Script in python, for mathematics I have used pymobu, in my opinion interesting and useful project for scripting in the MoBu.

To use the mathematical part, you must connect the module datatypes, and then make a call insertMathClasses.

unfortunately there’s no documentation according to the list of supported math, but you can easily understand source glancing datatypes file.

Now, regarding the algorithm. The following function allows you to project a point on the line:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from pyfbsdk import *
from datatypes import *

insertMathClasses()

def ClosestPointOnLine(A, B, P):
a_to_p = P-A
a_to_b = B-A

atb2 = abs(a_to_b)
atp2 = abs(a_to_p)

a1 = a_to_p.Normalize()
a2 = a_to_b.Normalize()

atp_dot_atb = a1.Dot(a2)

t2 = atp_dot_atb * atp2 / atb2;

a_to_b = B-A
res = FBVector3d( A.X + a_to_b.X * t2, A.Y + a_to_b.Y * t2, A.Z + a_to_b.Z * t2 )
return res
Python: Closest point on line
Tagged on:             

2 thoughts on “Python: Closest point on line

  • Wednesday February 9th, 2011 at 08:24 AM
    Permalink

    Hey, this is Scott Englert, the author of pymobu. I came across your post and wanted to say thanks for downloading it and giving it a try.

    I know the documentation is lacking on some of the methods. When I have time to go back and continue development, I want to add more examples and descriptions.

    I think the matrix and vector maths is probably my favorite section of the project just because there is a clear lack of support and very fundamental to 3D.

    If you want to contribute to the project, just send me a message or if you have any comments, let me know. I haven’t too many responses so I haven’t move too much more forward with it lately.

    Thanks again and it’s good to know someone is using it out there!

    -Scott

  • Wednesday February 9th, 2011 at 10:24 PM
    Permalink

    Hello Scott,
    thank you for your pymobu, It’s really useful (math part for me is very helpfull)!
    I have added a link to you project in my links section.
    Also I’ll send you an e-mail about contribute.

    I wish you good luck!

Leave a Reply

Your email address will not be published. Required fields are marked *