# Projecting a line segment on a plane

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

## Recommended Posts

I need to project a line segment ( represented by two vectors, vStart and vEnd ) on a plane ( ax + by + cz + d = 0 ). I'm not very good at 3d math, and I didn't find anything useful on google. Cound you point me to an article or tutorial about this? Anyway, I already know the basics about vectors, planes, matrices etc. I just need this particular operation. Ok, here is my attempt: -find the plane-segment intersection point, call it P -find the intersection point of the vector going from vStart perpendicular towards the plane, parallel to the plane normal (How do I find this?), call this K -The projected segment is now K - P Is this the standard approach? I'm pretty sure there are other ways..

##### Share on other sites
simply do

Vector N = Vector(a, b, c); // normal of the plane

float sn = vStart.Dot(N) + d;
float en = vEnd.Dot(N) + d;
float n2 = N.Dot(N); // square length of normal

vStart -= (sn / n2) * N; // projection on plane
vEnd -= (en / n2) * N; // projection on plane

##### Share on other sites
Quote:
 Original post by oliiisimply do Vector N = Vector(a, b, c); // normal of the planefloat sn = vStart.Dot(N) + d;float en = vEnd.Dot(N) + d;float n2 = N.Dot(N); // square length of normalvStart -= (sn / n2) * N; // projection on planevEnd -= (en / n2) * N; // projection on plane

Thanks, this code works perfectly.
I understand what it does, it's rather simple, but.. why are you computing the square length of the plane normal? The normal has length 1 so it has no effect.

##### Share on other sites
Quote:
Original post by Arcibald Wearlot
Quote:
 Original post by oliiisimply do Vector N = Vector(a, b, c); // normal of the planefloat sn = vStart.Dot(N) + d;float en = vEnd.Dot(N) + d;float n2 = N.Dot(N); // square length of normalvStart -= (sn / n2) * N; // projection on planevEnd -= (en / n2) * N; // projection on plane

Thanks, this code works perfectly.
I understand what it does, it's rather simple, but.. why are you computing the square length of the plane normal? The normal has length 1 so it has no effect.

for case normal's length !=1

if normal's length is surely 1, then of course you can remove squared length, and use 1 instead.

##### Share on other sites
Just to be sure. Else you would have said "uhhh doesn't work!!!! panic!" [grin]

well, to be fair, I'm not sure if it would work then... [embarrass]

1. 1
Rutin
46
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 12
• 10
• 13
• ### Forum Statistics

• Total Topics
632988
• Total Posts
3009736
• ### Who's Online (See full list)

There are no registered users currently online

×