Reflection or vector rotation problem...

Hi all, im new to c++.
My task is to make function that will rotate radius vector of incident photon when he interact with surface. Its total reflection problem, no transmision (so no refraction, just reflection).
Inputs are components "Ex" and "Ey" or radius vector "r". And outputs are new radius vector "r' " with new components "Ex' " and "Ey' ". Acctually its problem of rotating vector "r" around vector "n". Vector "n" is surface normal vector, since its surface along X axis (its horisontal) its components are (0,1).
I drow little picture of this problem. So inputs are components Ex and Ey of radius vector of photons, next surface normal vector n(0,1), and result should be components Ex' and Ey' of radius vector after reflection. in this case components along X axis will remain same, but Ey components will change.
Here is little picture of this problem:
https://root.cern.ch/phpBB3/download/file.php?id=12352&t=1
Last edited on
So far i had understand, there needs only a negation of the 'y' part of your vector?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
namspace starke {

class Vector
{
private:
   double m_x;
   double m_y;

public:
   Vector( double x, double y)
   : m_x(x), m_y(y) {}
   double x() const { return m_x; }
   double y() const { return m_y; }
   void set( const Vector& v ) { m_x = v.x(); m_y = v.y(); }
   void setX( const double x) { m_x = x; }
   void setY( const double  y) { m_y = y; }
};

// changes the y value of its input vector
Vector& reflect_to_x_axis( Vector& v)
{
	v.setY( - v.y() );
	return v;
}

} // end of namespace starke 

*edited
Last edited on
Mr diddeldidum,
thank You for your response, but this look really complicated, at least for my knowledge of programming.
I can't understand what is happening here, except last line v.x = -v.x()...
althought last line is what I need...
There I made a mistake, sorry. I have this corrected now.
The '-' in line 22 just negates its value. Its like * -1

If you want return a new vector you could take this function:

1
2
3
4
Vector reflect_to_x_axis( const Vector& v)
{
    return Vector( v.x(), - v.y() );
}


The namespace directive you could omit. With the namespace, you must precede your Vector with 'starke::'
1
2
3
4
5
// example for creating a new Vector:
starke::Vector v = starke::Vector( 3.14, 2.52 );

// example for using the reflection function:
starke::Vector v_2 = starke::reflect_to_x_axis( v );

Or you write at top:
using namespace starke;

*edited
Last edited on
closed account (48T7M4Gy)
If the incident ray has components Ex and Ey and the reflected ray has components Ex' and Ey',
then,
Ex' = Ex and Ey' = - Ey which is described in the class Vector method return value (line 3 above).
Thank You kemory,

acctualy my problem is reflection on 4 sides of parallelepiped or square.
I need some "universal formulae" not only for parallelepiped whose two sides is parallel to X axis, and 2 sides parallel to Y axis, but also for parallelepiped that is leaning by some angle to X axis.
closed account (48T7M4Gy)
I'm glad it helped Starke, all the posts point to the same, believe it or not.

The point you raise about universality is not perfectly clear because the
incident -> reflected ray vector transformation is universal in itself and applies at every interface or reflective surface in the 2D world.

Do you mean a parallelogram (2D) or a parallelepiped (3D object)? Whatever it is the same physics principle applies but you may need to take into account the Ez vector component if it's a 3D object/mirror.

Assuming for simplicity that it is the 2D case you have 2 options:
a) draw a picture similar to the diagram you posted and work it out from there as a single formula.

b) use the transform you have for the single case and model the parallelogram in a program and let the computer work it out.

There are a couple of cases depending on the relative direction the incident ray is travelling. (Maybe someone has a formula if you google it.)

PS Afterthought: You need to correct for any rotation of the reflecting surface in about the Z-axis (ie in the XY plane) - this is where local and global coordinates come into play :)
Last edited on
Topic archived. No new replies allowed.