Calculating distances of linear curves in maya?[Python]

maya

#1

Hi!

Let’s say I have 2 cubes.
They can be placed anywhere in the scene.
When I run the script I want to create 2 more cubes inbetween these 2 cubes.

Here is a picture to demonstrate the idea. The red strokes is where the new cubes should be placed.
example

My idea was to create a linear curve between the two cubes and then get the distance of the curve and place cubes at 1/3rd and 2/3rd of the distance. Is it possible to calculate a curves distance and then somehow get the point in world space?

//Dabbo


#2

Sure although you don’t need to calculate a line, you could let a simple linear interpolation do the trick

firstCube pos = cube1pos + 0.33*(cube2Pos-Cube1Pos)
secondcube pos = cube1pos + 0.66*(cube2Pos-Cube1Pos)


#3

Oh. That looks a lot more simple than my idea. Thanks a bunch! :grin:


#4

Depending on what you’re doing, you could also achieve this with point constraints weighted 2:1 and 1:2 to the original cubes – that would let you adjust the positions live and get updates.


#5

I’m creating a rigging script and I wanted a second spine that is always a joint chain of 4 joints with the distances shown in the picture above.

Out of curiousity I would like to know how you would do it your way, if you don’t mind?


#6


I think it would be like this, but I have no idea if this is a good idea. It strikes me as probably not a good idea.
Each joint has point constraint weights to the 2 cubes like (4,1) (3,2) (2,3) (1,4).


#7

If you don’t want it to stay live, you can do a little script that creates a constraint with the proper weights and then deletes it immediately, leaving the joint in the right place…