Maya for 3D Printing - Rapid Prototyping
In this course we're going to look at something a little different, creating technically accurate 3D printed parts.
# 1 08-07-2003 , 03:06 PM
septentrio's Avatar
Subscriber
Join Date: Nov 2002
Location: Dunkerque, Flanders, France
Posts: 201

A rolling Wheel (or any cylindrical object)

Hello,

I've no experience in writing expressions but i want to make a wheel roll as i move a locator attached to it (the wheel parented to the locator and the locator's x translation drives the wheel's rotation.)

the translation is on the X axis.

For a wheel which has 0.5 unit for radius :

perimeter=2*3.1416*0.5=3.1416 units
So, 3.1416 is the distance to accomplish one round, 360°


Now, normally if the locator moves 1 unit on the x axis, the wheel should turn 360*1/3.1416=115°.

Am i right to do that ?


Today man, tomorrow bird...i already have the plumage
# 2 10-07-2003 , 05:00 PM
Blinn's Avatar
Registered User
Join Date: Sep 2002
Location: Nova Scotia
Posts: 290
yep i think your spot on
every 3.14 units it will completley rotate once.


________

- Jacob
# 3 10-07-2003 , 07:04 PM
mark_wilkins's Avatar
Registered User
Join Date: Jan 2003
Posts: 161
Where this gets tricky is if the object's not rolling in a straight line, in which case you have to have some way of figuring out the distance along its path that it's rolled.

Using a curve as a motion path and constraining the object to orient itself along the curve can put you in a position to do this properly -- use the distance along the curve to drive rotation.

-- Mark


Mark R. Wilkins
author of MEL Scripting for Maya Animators
www.melscripting.com
# 4 11-07-2003 , 08:03 AM
septentrio's Avatar
Subscriber
Join Date: Nov 2002
Location: Dunkerque, Flanders, France
Posts: 201
Ok, here's the solution :

I made a cylinder (named wheel) parented to a locator which is driving (named driver) the cylinder.

The rotation is based upon the locator's translation D over the x and z axis

1 constant : C, which is the cylinder's circumference.
D : variable


wheel.rotateX=360*D / C
C=2*3.1416*$radius;

What is D? How do we calculate D ?
D is the distance between the locator's (x,z) position and its former (x,z) position.

So i set global variables ($formerX and $formerZ) which stores the locator's former position...

D=sqrt((driver.translateX-$formerX)^2+(driver.translateZ-$formerZ)^2);


So, to sum up :

wheel.rotateX=360*(sqrt((driver.translateX-$formerX)^2+(driver.translateZ-$formerZ)^2))
/ (2*3.1416*$radius);


this works well if you move positive, so that's why i have to test the wheel's position with an if statement

ex : if (wheel.translateX < 0){$direction = -1}

and then ...

wheel.rotateX=$direction*360*(sqrt((driver.transla teX-$formerX)^2+(driver.translateZ-$formerZ)^2))
/ (2*3.1416*$radius);


Once done, i update $formerX and $formerZ with the current values of the locator :

$formerX = driver.translateX;
$formerZ = driver.translateZ;


Apply this expression to your wheel, move the locator and there it is !


Today man, tomorrow bird...i already have the plumage
# 5 11-07-2003 , 10:38 AM
kbrown's Avatar
Moderator
Join Date: Sep 2002
Location: London, UK
Posts: 3,198
Deleted the duplicate post as requested...


Kari
- My Website
- My IMDB

Do a lot, Fail a lot and Learn a lot!
# 6 13-07-2003 , 04:31 AM
mark_wilkins's Avatar
Registered User
Join Date: Jan 2003
Posts: 161
That works, unless you want to render individual frames separately, as you would on a render farm. In that case, you're stuck with playing the entire scene from start to the frame in question to get to the right place.

That's one big reason I suggested using the parameter along a motion path rather than calculating differences in distance as you have, because that approach does not require playing the scene through from the beginning to give the correct result.

However, for your application it may not matter.

-- Mark


Mark R. Wilkins
author of MEL Scripting for Maya Animators
www.melscripting.com
Posting Rules Forum Rules
You may not post new threads | You may not post replies | You may not post attachments | You may not edit your posts | BB code is On | Smilies are On | [IMG] code is On | HTML code is Off

Similar Threads