Search code examples
mathgeometrycomputational-geometrytrigonometry

Find x and y coordinates where a perpendicular point crosses a straight line


This is a follow-up question to this question.

Taking the following image as an example:

enter image description here

What I know:

  • x and y coordinates of points D, E, and P.
  • Therefore, I also know slope and intercept of D-E line

What I want to know:

  • x and y coordinates of point Q. (This is the point which crosses the D-E line).

Solution

  • Notation P=[px,py], D=[dx,dy], E=[ex,ey], Q=[qx,qy]

    First:

    R=P-D=[px-dx, py-dy]=[rx,ry]
    
    K=E-D=[ex-dx, ey-dy]=[kx, ky]
    

    Then

    z=dot(R,K)/dot(K,K)=(rx*kx+ry*ky) / (kx*kx+ky*ky)
    

    Finally

    Q=D+z*K=[dx+z*kx, dy+z*ky]
    

    The R is vector which start on point D and ends on point K, the K is vector which start on point D and ends on point E. Using this we made scalar projection to calculate result Q. More info about concept here