Sign in to follow this  

Projection from point to line

This topic is 1858 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

Hi,
I want to find projection from a point 'P' on a line 'L'

if line is given as:

struct Line
{
vec3 pos;
vec3 direction;
}

and the point is vec3(a,b,c)


I am trying to form a function like:

vec3 ProjectionToLine( Line, Point);

Share this post


Link to post
Share on other sites
Assuming Line.direction has length 1, the answer is Line.pos + Line.direction * dot_product(direction, Point - Line.pos).

Share this post


Link to post
Share on other sites
[quote name='Álvaro' timestamp='1355599204' post='5011009']
Assuming Line.direction has length 1, the answer is Line.pos + Line.direction * dot_product(direction, Point - Line.pos).
[/quote]


thank you for replying

Is it Line.pos + Line.direction * dot_product([b]Line[/b].direction, Point - Line.pos)

I know what is dot product, cross product, knowledge of trigonometry etc but I find it confusing to
apply in problems ( in way of programming ie construction functions to calculate) like:

1) Given a point and a line to find out whether it is on the left or the right side of the line
2) Find angle between a line and a plane
... etc

Is there any tutorials or any weblinks where I can find these sort of problem for practise/learn.

Any guidance or suggestion is welcome

Share this post


Link to post
Share on other sites
[quote name='vicer1234' timestamp='1355600443' post='5011012']
[quote name='Álvaro' timestamp='1355599204' post='5011009']
Assuming Line.direction has length 1, the answer is Line.pos + Line.direction * dot_product(direction, Point - Line.pos).
[/quote]


thank you for replying

Is it Line.pos + Line.direction * dot_product([b]Line[/b].direction, Point - Line.pos)[/quote]

Yes, that's what I mean. Sorry about the typo.

[quote]I know what is dot product, cross product, knowledge of trigonometry etc but I find it confusing to
apply in problems ( in way of programming ie construction functions to calculate) like:

1) Given a point and a line to find out whether it is on the left or the right side of the line[/quote]
There are several ways to think about it. Imagine the plane is the x-y plane inside a 3D space and compute the z component of cross_product(Line.direction, Point - Line.pos).

[quote]2) Find angle between a line and a plane[/quote]
An angle is defined between two vectors, and then it's acos(dot_product(v,w)). To compute the angle between a line and a plane, project the line onto the plane and compute the angle between the original line and the projected line.

[quote]... etc

Is there any tutorials or any weblinks where I can find these sort of problem for practise/learn.

Any guidance or suggestion is welcome
[/quote]

I learned Linear Algebra in college. This is something that takes effort to push into your brain, but it's extremely useful, so you should definitely put the effort in. Perhaps Khan Academy has good material on this?

Share this post


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