C²=A²+B² - Locomotive Pistons TUT

A frequent question on the C4D boards around the world is: "How do I animate a Locomotive Piston?"

loco

At first glance it seems to be some sort of target thing, but unfortunately it is more complex.
We need some math here.
Remember the Pythagorean theorem? AAAAARGH!

Follow up:

Please do not read the following 8 lines, they will make you feel nauseous and suddenly remember the face and posture of your math teacher
The theorem is as follows:
In any right triangle, the area of the square whose side is the hypotenuse (the side of the triangle opposite the right angle) is equal to the sum of the areas of the squares of the other two sides.
Where C is the length of the hypotenuse and A and B are the lengths of the other two sides, the theorem can be expressed as the following equation:
C²=A²+B²
or in other words:
C=Sqrt(A²+B²)

pytha

Grr I hate that. The guy was huge and had a big nose with craters.

Ok never mind that.
Lets get to work here.
Start by making your model of the wheel and the arm and the piston.
Put the wheel in a null positioned at the center of the wheel. Make a null containing the arm at the location it has to rotate on.
Make another null called Target containing the moving part of the piston. And a last null containing the fixed part of the piston.

What we will do is to determine is the position of the "target" null. And yes we need the math thing above, sorry.
What we know already is the length of the arm (C) and we know the hight of A but we don't know B.

pytha

pytha

A is the hight (Y) between the centre of the wheel and the rotation point.
C is the length of the arm
B is given after the calculation in the X direction.

But it is harder than that because the rotation point rotates around.
And that means A changes all the time and D has to be added.

pytha

So lets determine A first.
You need to subtract the wheel global position from the arm global position. Then convert vectors2reals. The Y is the length of A. Feed this to a FloatFunc set to Pow2.
Then feed the length of the arm (C) to another FloatFunc set to Pow2.
Subtract them C-A (that is not clear in the screenshot sorry)
And make another FloatFunc set to Sqrt (square root)
Now the last step is to add D, we got D out of the vectors2reals. Add the X of vectors2reals to the result of the previous calculation and the result is the exact position of the target.

pytha5

Now add a target tag to the Arm null and point it to the target null.
To avoid problems I have added an upvector, that is another null placed right above the setup. This avoids the Gimbal effect (flipping of arm)

I hope you understood the setup and can reproduce it.

6 comments

Comment from: Nathaniel [Visitor] : 2006-03-12 @ 22:31
I was able to recreate the animation you have above only one very simple Xpresso (target z = piston z) and nulls/targets... the only issue with mine is that at high speeds it tends to blow apart but at low to moderate speeds it works very well... is this blowing apart problem what you were trying to solve? what was the problem with using targets?
Comment from: base80 [Member] Email : 2006-03-12 @ 23:01
If an expression shows aberrations at high speed, resolve it by setting the number of frames at a much higher rate so that the calculation is done more often. You can still render a 30fps.
The target tag does not work for this thing because you don't know where to target to. It will not be exactly on spot I assure you.

Apart from that there IS a serious issue with this expression, the model can not be rotated as a whole, because I used global positions it will not work everywhere.
I am working on a similar setup where I use trigonometry sine and cosine, but it isn't finished yet
Comment from: bobtronic [Visitor] : 2006-03-13 @ 09:59
hi base80,

I had a try with your scene and developed my own solution, It's pure trigonometrical. You can find it here:
http://www.bobtronic.de/files/misc/loco/loco.zip

and here a little test:
http://www.bobtronic.de/files/misc/loco/loco.mov

thanks for the challenge :)

cheers,
Bob
Comment from: base80 [Member] Email : 2006-03-13 @ 13:53
Hi Bob
Thanks for the file
I have something very similar, trigo and a target.
I am preparing a tutorial but unfortunately it is longer than my usual tutorials and that is a shame.
Your file is the only "right" way to do it thanks for sharing.
Comment from: Steve B [Visitor] : 2007-03-08 @ 21:21
Your math teacher, his nickname wasn't Rudolph was it? Only it sounds like a teacher i used to have, but back then he taught geography as well.
By the way, nice tut's, I am a complete novice, but learning quick with your help. Would be nice to see the MoGraph tut's up though, would really help out. Keep up the good work!!
Comment from: Richard Perrine [Visitor] : 2008-08-10 @ 20:48
Any chance someone can give me an idea as to how to expand this to include more than one wheel?

Thanks!

Richard

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.
PoorExcellent
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)
This is a captcha-picture. It is used to prevent mass-access by robots.
Please enter the characters from the image above. (case insensitive)