# point - line projection

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

## 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 on other sites
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 on other sites
Hello,

Thx. Does this works for 3d also?

1. 1
Rutin
43
2. 2
3. 3
4. 4
5. 5

• 10
• 27
• 20
• 9
• 20
• ### Forum Statistics

• Total Topics
633405
• Total Posts
3011680
• ### Who's Online (See full list)

There are no registered users currently online

×