Skip to content Skip to sidebar Skip to footer

Cannot Get The Coord Of A Projected Point On An Axis

I'm trying to do a function who take a point position and an axis (a line) and return the projection of the point on the axis. Point are simply represented by {x, y} coords Axis a

Solution 1:

Represent line (your axis) in parametric form as base point A and unit direction vector d = (dx, dy). It is universal representation suitable for all slopes. If you have slope angle fi relative to OX axis, then dx=cos(fi), dy=sin(fi)

L = P0 + d * t

Then projection of point C onto line is (using scalar product)

AC = C - A
P = A + d * (d.dot.AC)

enter image description here

In coordinates

dotvalue = dx * (C.x - A.x) + dy * (C.y - A.y)
P.x = A.x + d.x * dotvalue
P.y = A.y + d.y * dotvalue

Post a Comment for "Cannot Get The Coord Of A Projected Point On An Axis"