projection of point on line in 3D
Solution 1
You want to project the vector (x,y,z) on the line with direction (a,b,c).
If (a,b,c) is a unit vector then the result is just (x,y,z).(a,b,c) (a,b,c) = (ax+by+cz)(a,b,c)
If it's not a unit vector make it one, divising it by its norm.
EDIT : a little bit of theory:
Let E be your vectorial space of dimension N:
let F be the line directed by vector a. The hyperplan orthogonal to F is :
Now let's chose a vector x in E, x can be writen as : where xF is the coordinate of x in the direction of F, an x orthogonal is the coordinate on the orthogonal hyperplan.
You want to find xF: (it's exactly the same formula as the one I wrote above)
You should have a close look at the wikipedia article on orthogonal projections and try to find more stuff on the web .
You can generalise that to any F, if it's not a line anymore but a plan then take F orthogonal and decompose x the same way...etc.
Solution 2
This topic is clearly old and I think the original poster meant vector not line. But for the purposes of Google:
A line, unlike a vector does not (necessarily) have its origin at (0,0,0). So cannot be described just by a direction, it also needs an origin. This is the zero point of the line; the line can extend beyond and before this point, but when you say you’re zero meters along the line this is where you mean.
So to get the projection of a point onto a line you first need to convert the point into the local co-ordinate frame, which you do by subtracting the origin from the point (e.g. if a fence post is the ‘line’ you go from GPS co-ordinates to ‘5 metres to the north and a meter above the bottom of the fence post‘). Now in this local co-ordinate frame the line is just a vector, so we can get the projection of the point using the normal dot product approach.
pointLocalFrame = point– origin
projection = dotProduct(lineDirection, pointLocalFrame)
NOTE: this assumes the line is infinite in length, if the projection is greater than the actual line length then there is no projection
NOTE: lineDirection must be normalised; i.e. its length must be 1
NB: dot product of two vectors (x1,y1,z1) and (x2,y2,z2) is x1*x2+y1*y2+z1*z2
AMH
Updated on June 04, 2022Comments
-
AMH almost 2 years
I have point with x,y,z
and line direction x,y,z
how to get the point projection on this line
I tried this code
http://www.zshare.net/download/93560594d8f74429/
for example when use the function intersection in the code I got the line direction is (1,0,0) and the point (2,3,3) will have projection (value in x , 0, 0 ) and this is wrong value
any suggestion Best regards
-
AMH over 12 yearsI need the point after projection, I updated my question, I mean the new point location on the line
-
Ricky Bobby over 12 years@AMH The new point location on the line (directed by unit vector a,b,c) will be : (ax+by+cz) . And the new point coordinate on the whole space will be (((ax+by+cz)*a , (ax+by+cz)*b , (ax+by+cz)*c). is it what you need ?
-
Ricky Bobby over 12 years@AMH note that if you define a line just by a direction I assume that it's passing through 0,0,0 (like in a vectorial space not an affine space
-
AMH over 12 years@jean I tried hard to fix the problem, and posted the code, then updated it depending on ricky suggestion but still face error, that what made me ask
-
Jean-François Corbett over 12 yearsIf you get an error, say what the error is in the question, post the relevant code (not necessarily the whole code) in the question, and say what line of the code gives the error. Nobody wants to download a zip file to do someone else's work.
-
AMH over 12 yearsI didn't post whole the code , if u opened my link u will noticed that I did a simple project to simulate the problem no more no less
-
AMH over 12 years@rickyBobby If u can help me in that
-
AMH over 12 yearsthe line direction is (1,0,0) so I projection of the point (2,3,3) will be (value in x , 0, 0 ) and this is wrong value
-
Ricky Bobby over 12 years@AMH why do you say it's the wrong value ? The orthogonal project on your x axis is the first coordinate of your point: (2,0,0). Otherwise we are not talking about orthogonal projections.
-
AMH over 12 yearsI need projection in all directions so I got the actual point projection, I mean the x,y, and z component
-
Ricky Bobby over 12 years@AMH, You want the projection on a line in all direction ? The line is in one direction so the projection is in one direction. (CF formula above. ). You should have a look at vectorial spaces OR affine geometry (depending on what the problem really is). I will try to have a look at your code when I have more time. In the mean time you should try to clarify your problem and get more knowledge on the subject. The orthogonal projection of (2,3,3) on the direction (1,0,0) IS the vector (2,0,0) by definition orthognal projection.
-
AMH over 12 yearswish you have time because I tried many times in this, also the point have x,y,z values
-
Christian Rau over 12 years@AMH (2,0,0) are the x,y and z components of the projected point, y and z are just 0, as you projected the point onto the x-axis. You should really refresh your analytic geometry/linear algebra knowledge, to at least ask the correct question, as you obviously seem not to speak of orthogonal projection on a line.
-
Mike 'Pomax' Kamermans almost 2 yearsI wish this answer had actual code, for programmers looking how to do this. It's bizarrely hard to just find "actual programming code" to perform what is essentially a simple trick. Everything sticks to showing the maths and letting the reader figure out the implementation from there.