• Advertisement
Sign in to follow this  

point - line projection

This topic is 4721 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, How can i project a point to a line? Like here below. I project p and q perpendicular on the line. What are the new coordinates of p and q after the projection? +p0 | |------------.p | | +p1 . .------------.q . .

Share this post


Link to post
Share on other sites
Advertisement
I'm at work, so here's a super-quick reply.

Vector3 ProjectPointToLine(const Vector3& p, const Vector3& p1, const Vector3& p2)
{
Vector3 dir = p2 - p1;
Vector3 diff = p - p1;
float t = diff.Dot(dir) / dir.Dot(dir);
return p1 + t * dir;
}

No time to proof, so I may or may not have gotten that right :-)

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Hello,

Thx. Does this works for 3d also?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement