C4Dforbeginners

Crank Joint Node

Open the Xpresso Editor window. It so happens that the X-coordinates of a point (the "Generator") making one complete orbit around another point (like the Earth orbiting the Sun) provide exactly the correct type of sequence of numbers, provided that the point of orbiting is at X-0. The size of the numbers depends on the distance between the generator and the point of orbiting. The Crank Joint is such a point. By type is meant that as it rotates, its X-coordinates starts at zero, then increase, then reduce. Also, the changes in the values of the coordinates slow down, then speed up, exactly as we want. We have been clever here and used the Crank itself as that generating geometry. Also, the length of the crank is correct to ensure that the size of the numbers generated is suitable for piston movement. Run the animation from the beginning, step-by-step, and note the changing values at the Output Port of the Crank Joint Node shown by the Result 1 Node. (Note that Result Nodes do not show their correct data while the animation is running.)

However, that sequence of numbers starts at zero, and goes positive and negative. If used to drive the Piston, the Piston would move on each side of the Crankshaft, at the Viewport origin, and the Conrod would follow it by pointing at the origin. But that is easily solved by simply adding a positive number (550 in this case) as revealed by selecting the Math:Add Node and opening the Attribute Manager : Parameter button, and its effect is shown by the Result 2 Node. At the Output Port of the Math:Add Node we now have a Suitable Sequence of Numbers for the X-coordinates of the Piston. We now need to tell the Piston what is going on.

Piston Node

This was created by simply dragging the name of the Piston from the Object Manager on to the Xpresso Editor Window. A Global Position.X Input Port was created by Clicking on the blue box of the node and choosing Coordinates > Global Position > Global Position.X Any value arriving at this Input Port will make the Piston move to the X-coordinate equal to that value.

Finally, we need to make the Piston move in a straight line along the X-axis. To see why we need to do something here, delete the Link at the Piston Node's Global Position.Y Input Node (click on the Link) and run the animation. See? The Piston goes up and down. (I don't know why it does that, nor why it stops going left and right. Anyone got the answer?) Re-creating that Link (drag between the two Ports) forces the Piston's Y-coordinate to stay at zero, because of the value delivered by the Constant Node.

Its a Cheat!

Actually, the movement of the Piston is not exactly correct because the Crank Joint, acting as the generator of the Piston's X-coordinates, does not take account of the angle between the Crank and the horizontal. However, this difference is very small and who would notice, in a practical world? Also, in a real Crank, Conrod and Piston system, the Piston would be driven by the Piston end of the Conrod, directly and mechanically, rather than through a separate generator. Simulating that could be done elegantly using IK Bones, but I have never found a way to automatically force the piston end of the Bone Chain to be on the X-axis. (Anyone know how to do that?)

Movie

Make a movie of the Scene to see the full effect.