Perpendicular on a line segment from a given point

后端 未结 9 1552
小鲜肉
小鲜肉 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 12:20

    A point on line AB can be parametrized by:

    M(x)=A+x*(B-A), for x real.

    You want D=M(x) such that DC and AB are orthogonal:

    dot(B-A,C-M(x))=0.

    That is: dot(B-A,C-A-x*(B-A))=0, or dot(B-A,C-A)=x*dot(B-A,B-A), giving:

    x=dot(B-A,C-A)/dot(B-A,B-A) which is defined unless A=B.

提交回复
热议问题