Project point on a line


#1

Please help solving this geometric problem.

Given a Dynamo point project it on a Dynamo line. Obtain projected point.

There is a lot of nodes dealing with projecting point on a surface, but not dealing with projecting point on a line.

Theres a built in node that reports the distance to geometry, so I used it to obtain the shortest distance, then made a sphere and intersected it with the line. Alas, the rounding makes this method non-reliable, one of my intersection points turned up as a line with a length of 0,005 millimeter.

Please help.


#2

Michail,

Can you demonstrate your exact problem? Sample files, steps taken, images are all accepted and even welcome. Please have a look at this post: POST It might be from a different forum, but I have been stressing to everyone that they need to ask better questions.

Thank you,


#3

You want to obtain the point on a line that is closest to some other point?

I think all you need is Geometry.ClosestPoint


#4

Thanks for the replies guys. I am sorry, I thought my explanation was complete.

Anyway, I didn’t know that Dynamo has extensive vector manipulation node library. Now I know and I solved the problem by using vector calculation of a point projection on a line:

<a href="http://gamedev.stackexchange.com/questions/72528/how-can-i-project-a-3d-point-onto-a-3d-line"><span class="pln" style="color: #000000">A </span><span class="pun" style="color: #000000">+</span><span class="pln" style="color: #000000"> dot</span><span class="pun" style="color: #000000">(</span><span class="pln" style="color: #000000">AP</span><span class="pun" style="color: #000000">,</span><span class="pln" style="color: #000000">AB</span><span class="pun" style="color: #000000">)</span><span class="pun" style="color: #000000">/</span><span class="pln" style="color: #000000"> dot</span><span class="pun" style="color: #000000">(</span><span class="pln" style="color: #000000">AB</span><span class="pun" style="color: #000000">,</span><span class="pln" style="color: #000000">AB</span><span class="pun" style="color: #000000">)</span><span class="pun" style="color: #000000">*</span></a><span class="pln" style="color: #000000"><a href="http://gamedev.stackexchange.com/questions/72528/how-can-i-project-a-3d-point-onto-a-3d-line"> AB = P'

</a><img src="http://dynamobim.org/wp-content/uploads/forum-assets/mgodamgaard-ri-dk/01/18/PointProjectionOnLine.png" alt="PointProjectionOnLine" width="1451" height="577" />


</span>

#5

Michail,

Hahaha, it always amazes me how every person learns differently. I love the mathematical approach. Well done!


#6

The same in crude python:


#7

The same using list comprehension:


#8

Where is the line?.. If you want to project a point onto a line use Vikram’s solution, if you want to project a vector onto a vector then your solution is fine.


#9

Yes, it is actually a solution to project a point onto a line between two other points. So if you have a line to begin with, you have to extract two points from it. End and start points work fine. :slight_smile:


#10

Hahaha, sorry. I think you only had a bunch op points… no lines. So it’s even easier… Geometry.ClosestPointTo works fine, and here other solution. http://i64.tinypic.com/sm94jk.png


#11

Thanks for those, will try them out