Given a point (x1, y1) and an equation for a line (y=mx+c), I need some pseudocode for determining the point (x2, y2) that is a reflection of the first point across the line
Reflection of point A(x,y) in the line y=mx+c.
Given point P(x,y) and a line L1 y=mx+c.
Then P(X,Y) is the reflected point on the line L1.
If we join point P to P’ to get L2 then gradient of L2=-1/m1 where m1 is gradient of L1.
L1 and L2 are perpendicular to each other.
therefore,
Get the point of intersection of L1 and L2 say m(a,b)
Since m(a,b) is the midpoint of PP’ i.e. L2, then
M= (A+A')/2
i.e. m(a,b)=(A(x,y)+ A^' (x^',y^' ))/2.
from this we can get coordinates of A^' (x^',y^' )
Example
Find the image of point P(4,3) under a reflection in the line y=x-5
M1=1
M2 will be -1
Equ. L2 with points, (4,3) , (x ,y) grad -1 is
y=-x+7
Point of intersection say, M(a ,b)
Note that, L1 =L2 ;
Then x-5=-x+7
This gives the point for M that is M( 6,1)
Then;
M(6,1)=(P(4,3)+P^' (x^',y^' ))/2
M(6,1)=[(4+x)/2 ,(3+y)/2]
This gives x = 8 and y = -1 hence,
P^' (x^',y^' )= P^' (8,-1)