View Full Version : trig in a piston and crankshaft simulation

 kingmango10 October 2006, 05:04 AMI started with a single crank, conRod, and Piston custom attrs on the crank: crankSpeed, conRodLength, crankRadius expression on the crank: crank.rotateX = time * crank.crankSpeed expression on the piston: piston1.translateY = sqrt( pow( crank1.conRodLength, 2 ) - pow( crank1.crankRadius * sind(crank1.rotateX), 2 ) ) - ( crank1.crankRadius * cosd(crank1.rotateX) ); expressions on the conRod: conRod1.translateY = crank1.crankRadius * -cosd(crank1.rotateX); conRod1.translateZ = crank1.crankRadius * -sind(crank1.rotateX); conRod1.rotateX = -atan2d( conRod1.translateZ, sqrt( pow( crank1.conRodLength, 2 ) - pow( conRod1.translateZ, 2 ) ) ); This works like a charm So I duped the assembly over in X twice so I have a row of pistons. I changed the phase of the duped cranks to 120 and 240 respectively by adding those values into the rX expressions. Then I added in 120 and 240 respectively in the rod and piston expressions where there were instances of crank#.rX. so the second conRod looks like this: conRod2.translateY = crank2.crankRadius * cosd(crank2.rotateX + 120); conRod2.translateZ = crank2.crankRadius * sind(crank2.rotateX + 120); conRod2.rotateX = -atan2d( conRod2.translateZ, sqrt( pow( crank2.conRodLength, 2 ) - pow( conRod2.translateZ, 2 ) ) ); but I wind up with a strange out of phase syncronization. http://smg.photobucket.com/albums/v87/KingMango/Problems/?action=view¤t=crankShaft-withexpressionsTriple.flv The first crank is in the center. I just duped a set to each side for sake of symmetry while I worked. so the cranks on the ends are slightly out of phase in their connections, but I can't see where I've erred...
Per-Anders
10 October 2006, 05:30 AM
The first problem is that you should be using radians rather than degrees.

kingmango
10 October 2006, 05:59 AM
ah will do

kingmango
10 October 2006, 06:30 AM
for some reason changing the duped pieces expressions to the following worked:

conRod2.translateY = crank2.crankRadius * cosd(crank2.rotateX + 180);
conRod2.translateZ = crank2.crankRadius * sind(crank2.rotateX + 180);
conRod2.rotateX = -atan2d( conRod2.translateZ,
sqrt( pow( crank2.conRodLength, 2 ) - pow( conRod2.translateZ, 2 ) ) );

CGTalk Moderation
10 October 2006, 06:30 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.

1