How to calculate the mirror point along a line?

前端 未结 8 1597
灰色年华
灰色年华 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

    Suppose the equation of the line is ax + by + c = 0. Now imagine a line perpendicular to it, which can be represented by -bx + ay + d = 0 (product of slopes of two perpendicular lines is -1). Now the problem is to find d. Put the co-ordinate of the point on the second line, and you'll get the value of d easily.

    The second part is, to find a point on the second line which is equidistant as the first point from the first line. For that, you can find the intersection of the two lines. Calculate the differences in x and y of the given point and the intersection point. Now add those to the x and y value of the intersecting point. That gives the point you need (you may need to negate the differences - that's up to the order of subtraction you use).

提交回复
热议问题