Algorithm for reflecting a point across a line

前端 未结 9 1947
感动是毒
感动是毒 2020-12-03 03:02

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

9条回答
  •  -上瘾入骨i
    2020-12-03 03:36

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

    #include
    #include
    #include
    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 = "<
                                                            
提交回复
热议问题