Connect two Line Segments

前端 未结 7 2166
你的背包
你的背包 2021-01-02 12:07

Given two 2D line segments, A and B, how do I calculate the length of the shortest 2D line segment, C, which connects A and B?

7条回答
  •  一生所求
    2021-01-02 12:37

    Quick tip: if you want to compare distances based on points, it's not necessary to do the square roots.

    E.g. to see if P-to-Q is a smaller distance than Q-to-R, just check (pseudocode):

    square(P.x-Q.x) + square(P.y-Q.y) < square(Q.x-R.x) + square(Q.y-R.y)
    

提交回复
热议问题