You have a list of MVectors and you want to find which of them is closest 
to a target MVector? Unless your list of MVectors is sorted, you're going 
to have to compare them all, one at a time. In Python:
closestDist = float("inf")
for i, vec in enumerate(vectors):
    dist = (vec-targetVector).length()
    if dist < shortestDist:
         closestIndex = i
         shortestDist = dist
If you were doing it in C++ you'd probably roll your own distance-squared 
function, but in Python I think it's faster to call length (which is done 
in C++).
If your vectors are normalized, you can use the dot product instead of 
subtraction and length, and that will be faster.
If you have a lot of vectors to compare to your list, you can optimize by 
sorting the list into an octree first.


On Wednesday, 22 March 2017 05:20:09 UTC+11, justin hidair wrote:
>
> How would you find the closest MVector to another MVector (argument) ? Is 
> there a way to do it exclusively using the API ? the only thing I could see 
> is MVector.isEquivalent() 
> but that's not what I want , even with the tolerance setting, that's just 
> inaccurate .. 
> I heard about sciPy and numPy without investigating too much...
>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/b8737823-51c8-4476-a415-a0589c1bedb8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to