 # [Maya] How to perform this "calculation" with the least amount of nodes?

Hi,

I’m trying to perform this calculation:

``````diff_X = objA.tx - objB.tx
diff_Y = objA.ty - objB.ty
diff_Z = objA.tz - objB.tz

result =  sqrt (  (diff_X*diff_X) + (diff_Y*diff_Y) + (diff_Z*diff_Z)
``````

I was able to recreate it in the node editor but its a bit verbose and certainly susceptible to input error
Is there a way to optimize this?

P.S. You can ignore the matrix nodes. I was just trying to get the world positions.

Looks like you’re trying to find the distance between two nodes.
Luckily, there’s a `distanceBetween` node that encapsulates that whole equation into one node!

Even better, it has 2 matrix inputs that multiply the 2 point inputs… So if you don’t plug in any points to the point inputs, you can get the distance between two matrices without using decomposeMatrix nodes!

3 Likes

@tfox_TD

What sorcery is this! It works as expected and the result is the same number as computed in nodes above.