PDA

View Full Version : A rolling Wheel (or any cylindrical object)


septentrio
08-07-2003, 03:06 PM
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 ?

Blinn
10-07-2003, 05:00 PM
yep i think your spot on
every 3.14 units it will completley rotate once.

mark_wilkins
10-07-2003, 07:04 PM
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

septentrio
11-07-2003, 08:03 AM
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 !

kbrown
11-07-2003, 10:38 AM
Deleted the duplicate post as requested...

mark_wilkins
13-07-2003, 04:31 AM
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