2010
06.05

This post surged from a question at a forum where somebody tried to use the ctr_dist() function — that returns distance between two object centers — in a Softimage script only to realise that actually it only exists for expressions, not scripting.

Here’s my take on said function for both Softimage and Maya…


First of all, we need to know the math behind it. Knowing global position vectors A and B, the formula for the distance (d) between them would be:

d = √  Ax-Bx2 + Ay-By2 + Az-Bz2  

In Python to do pow() we can use the “**” operator and for sqrt() simply do **0.5 instead of borrowing pow() and sqrt() functions from Python’s math library, by the way.

First let’s see how to do this with Python in Softimage:

Now let’s repurpose it for PyMEL in Maya, without using distance nodes:

By the way, note the awesomeness of Python for letting you assign multiple variables from an array using a single line. That’s pretty nice. 🙂

Hope somebody finds this useful! You can use it a measuring tool or for distance-dependent rigging logic.

If you do use it for rigging, please remember that if you want the distance to stay the same while a character is scaled, you must divide the distance by the scaling value.

4 comments so far

Add Your Comment
  1. Thanks Alan, it’s useful for me:)

  2. Yo tiraría por aquí… el SDK de softimage tiene cosillas interesantes para trabajar con vectores 🙂

    def ctr_dist( objA, objB ):
    v = objA.Kinematics.Global.Transform.Translation
    v.SubInPlace(objB.Kinematics.Global.Transform.Translation)
    return v.Length()

  3. Hey Alan! It’s Anthony from MODUS! I was googling for a way to calculate distances between two objects in Softimage and stumbled on your blog! hahah. Hope all is good at the new place!

  4. Thanks