How to calculate the mirror point along a line?

前端 未结 8 1662
灰色年华
灰色年华 2020-12-31 18:09

In 2D plane, I have a point and a line. How to get the mirror point along this line?

8条回答
  •  遥遥无期
    2020-12-31 18:48

    You can use a simple formula to find this. First you have to write the formula of the line using

    ax+by+c=0
    

    lets say your line is y=x. and the point you'r trying to mirror is (3,2). we all know it's gonna become (2,3) anyway write y=x in standard form, which will become like this :

    y-x=0
    

    now use this formula and insert the values of the point instead of the x and y.

        (ax+by+c)/a^2+b^2
        (a^2 means a square.)
    

    you will get a value, so let's name it K. in this instance where the point is (3,2) and the line is y-x=0, K would equal to:

    (-3+2)/(1+1)= -1/2
    

    now to calculate the new coordinates all you have to do is insert the values in this formula:

     x-2ak
     y-2bk
    

    where x and y are the original coordinates and a and b are the values used in the original formula of the line (y-x=0 a=-1, b=1, c=0) so the value we get is:

    3 - 2 x -1 x -1/2 = 3-1 = 2
    2 - 2 x +1 x -1/2 = 2+1 = 3
    

提交回复
热议问题