View more

View more

View more

Image of the Day Submit

IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Projection from point to line

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

#1vicer1234  Members

Posted 15 December 2012 - 01:05 PM

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);

#2Álvaro  Members

Posted 15 December 2012 - 01:20 PM

Assuming Line.direction has length 1, the answer is Line.pos + Line.direction * dot_product(direction, Point - Line.pos).

#3vicer1234  Members

Posted 15 December 2012 - 01:40 PM

Assuming Line.direction has length 1, the answer is Line.pos + Line.direction * dot_product(direction, Point - Line.pos).

Is it Line.pos + Line.direction * dot_product(Line.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

#4Álvaro  Members

Posted 15 December 2012 - 02:04 PM

Assuming Line.direction has length 1, the answer is Line.pos + Line.direction * dot_product(direction, Point - Line.pos).

Is it Line.pos + Line.direction * dot_product(Line.direction, Point - Line.pos)

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

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

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).

2) Find angle between a line and a plane

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.

... 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

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?

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.