I am drawing a line connecting two points P1,P2. This line makes an angle of ‘x’ with x axis,again I need to draw a line from P2 to someother point,and this line needs to make an same angle’x’ with the perviously drawn line.(Basically i got AN angle,draw a line making a given angle with x axis, and now for the second line,the first line should act as x axis)

Basically all the lines will be in a unit square.so from P2 to P3, where the P3 will be in one of the boundary wall of the square.And this new line P2-P3 has to form an angle with P1-P2(this angle is same as line P1-P2 made with x axis.

(Actually This is simulation of a ray inside an unit square, As soon as it hits the surface of the square it is getting reflected assuming that the surface of the square is 100% reflective)

Well i am not sure I got it right here.
From what I understood you are in a square (2D) and want to reflect the light on on the surface of the square but on the borders.

Well that’s easily done at one condition : don’t think about angles, think symetry.

For example let us imagine a square going from 0,0 to 1,1. lets say our ray hit the segment (0<y<1;x=1) in y = 0.3 , what we really need to make a perfect (almost) reflection is where does the line of that ray hit the x=0 line.

in our exemple lets say it hits the y=0 line in x=-0.5. We then have a line going from (-0.5,0) to (1,0.3). We want a reflexion we take the symetry of axe y=0.3. Therefore a point on the line will be (-0.5,0.6). From here it is not hard to find a point somewhere else in the line and actualy draw the ray.

Hi,
i think there are many possibilities :
for example : let’s have a line it is a point (x,y) and a vector (u,v) for the direction. it’s symetric rspect to the point from x axis is the same as a line with a point (x,y) with direction (u,-v) for the y axis it is (-u,v). So reflection of axe x,y are very easy to compute.
for example you have a line in the unit square passing through P1 x=0.1,y=0.0 and going to P2 x=0.9 y=1.0 the point here of reflection is P2 the direction is given by :
D(xp1-xp2 = -0.8,yp1-yp2 = -1.0) so the reflection is a line passing through P2 and hitting the x axis having the direction D1(-.8,-(-1.0)). the equation is so :
x = xp2 + t(-.8)
y = yp2 + t(1.0)
you want to find the point of intersection with the right side of the unit square you want to have x = 1.0
so t = 1/-.8(1.0-.9)=-.1/.8=1/8 and then y = 1.0-1/8=0.875. P3 is then (0.875,1.0) whic is the correct answer.
You of course will have to make all the intersection tests and bounding test to find of what side the ray is actually reflecting but that’s easy
the_shadow

Jeez - you guys are all confusing yourselves.
The answer is a simple maths one…
Angles work around 360 degrees OK?
If the axis is vertical to start with, we shall make this 0 (zero) degrees.
You then draw a line using the angle X.
To make X your new axis - just add X to 0 and so on.
Example if X is 15 degrees
P1 Xaxis= 0 deg -> P2 Xangle=15 deg
P2 Xaxis=15 deg -> P3 Xangle=30 deg
P3 Xaxis=30 deg -> P4 Xangle=45 deg
ETC ETC
One thing to check for is when the angle
is greater than 360 you have to use a MOD function for this so that odd values come out at the right angle again.
Try this out in a Logo program to visualise what you are drawing, as what you are asking to draw is very Logoesque.