Perpendicular on a line segment from a given point

后端 未结 9 1544
小鲜肉
小鲜肉 2020-12-02 11:52

I want to calculate a point on a given line that is perpendicular from a given point.

I have a line segment AB and have a point C outside line segment. I want to ca

9条回答
  •  春和景丽
    2020-12-02 11:57

    Since you're not stating which language you're using, I'll give you a generic answer:

    Just have a loop passing through all the points in your AB segment, "draw a segment" to C from them, get the distance from C to D and from A to D, and apply pithagoras theorem. If AD^2 + CD^2 = AC^2, then you've found your point.

    Also, you can optimize your code by starting the loop by the shortest side (considering AD and BD sides), since you'll find that point earlier.

提交回复
热议问题