Algorithm for reflecting a point across a line

Viewed 53837

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. Spent about an hour trying to figure it out with no luck!

See here for a visualization - http://www.analyzemath.com/Geometry/Reflection/Reflection.html

9 Answers

I have a simpler and an easy way to implement in c++

#include<graphics.h>
#include<iostream>
#include<conio.h>
using namespace std;

int main(){
cout<<"Enter the point";
float x,y;
int gm,gd=DETECT;
initgraph(&gd,&gm,"C:\\TC\\BGI");

cin>>x;
cin>>y;
putpixel(x,y,RED);
cout<<"Enter the line slop and intercept";
float a,c;
cin>>a;
cin>>c;
float x1,y1;
x1 = x-((2*a*x+2*c-y)/(1+a*a))*a;
y1=(2*a*x+2*c-y)/(1+a*a);
cout<<"x = "<<x1;
cout<<"y = "<<y1;

putpixel(x1,y1,BLUE);
getch();

}

Related