Can I Limit An Object's Transformation To A Shape?

Hi!

I was wondering(worrying,rather 'cos i have to do it and i don't seem to find a way..!) if we cud limit the transformations(mainly translate) of an object to a shape? For eg., i have a pair of,say...cubes.And i want one cube to revolve around the other at a constant distance......so if somehow, i could keep the relative distance between them constant,the outer cube would form a circle around the inner cube......
THE MAIN OBJECTIVE here is to constrain the translate of an object to a shape,in the above case, a circle.But,what if.....i wished to constrain the translation to a triangle,....or a sphere,...or say,....an ellipse?How could i do that?
Every shape in 3D can be defined by an equation......(that of a sphere being, x^2+y^2+z^2 = r^2 ).But even if i do have an equation,how would i get maya to solve it.How could i constrain the movements of the above described cube to a sphere of radius 5,for eg.,around the other cube?

I found it a rather interesting problem........what do you think?
I'm not too well versed with MEL....so if there's a predefined function that does it,......i would be extremely happy to know about it!!!!

You might try using rotations, seeing as how an orbit is a natural rotation of an object.

You can get away with this without using MEL.

Objects: Sphere, Cube
Move the cube 2 units +Y. Move the rotation pivot to the center of the sphere (World Space origin if you have not moved the sphere yet). Parent the Cube under the Sphere. Lock the translates on the cube so you don't accidently move it and just use rotation.

Again, not a MEL solution but the easiest way to do this is to use a Geometry Constraint.

Hi!

If i use the geometry constraint,then the object moves "on" the shape only.....! i want the object to be able to move freely inside and on the shape but never go outside it.
So,i guess if we could somehow put some expressions in the limit transformation,maybe we could do this.....
Another question was left unanswered... : can maya "solve" an equation?

Yes maya can solve an equation, but you need to know how far in either direction of the object you want to limit the movement of the secondary object

You can solve an equation with MEL as easily as you can with any other programming/scripting language - have a look for a book on Computational Methods or Numerical Recipes.

If you want to constrain your object to the interior of a simple shape (sphere, cube, etc) then one possible solution is to use a target object and an expression:
Create two poly cubes and a locator and create this expression...
[codebox]float $radius = 12;
vector $centre = <>;
vector $target = <>;
vector $dir = ( $target - $centre);
vector $pos;

if( mag($dir) > $radius )
$pos = $centre + $radius * unit($dir);
else
$pos = $target;

pCube2.tx = $pos.x;
pCube2.ty = $pos.y;
pCube2.tz = $pos.z;[/codebox]

The locator acts as a target and its position vector relative to the first cube is used to determine the second cube's final position. This is for a 'sphere' constraint, obviously, but a 'cube' version would be very similar - just test and limit the x,y & z coords separately.

Hope this helps,

Well, yes you can but. Mel is not a language designed for dg time evaluation. Anyway a arbitrary shape is actually quite tricky. Secondly the limits don't update like people expect, but you can do this with expressions. And expressions are NOT MEL (they can contain mel but thats another thing entirely just because cars contain engines doesnt make them engines).

Hi!

Thanks a ton!
Lemme reasearch on this a bit,....then i'll post further comments/queries