C4Dforbeginners

Maths Method

Hello. Hello. Are you still there? Good. A pendulum swings in accordance with a type of motion called Simple Harmonic Motion, provided the swings are small. The simplest example of this is a spring hanging down with a weight on its end. If the weight is pulled down from its rest position and released, it will move up, and its speed will increase as it approaches the rest position. It therefore accelerates, upwards. It will continue to move up, passing through the rest position, decelerating until it reaches as far above the rest position as it was below it when it started. However, what we are interested in this Walkthrough is some way of relating how its distance varies with time, because distance is what Xpresso is good at. Now for just a little trigonometry. But first, remember that the rotating arm that you see in the Viewport has nothing to do with this method of generating the required sequence of numbers.

Cos

The Cosine (Cos) of an angle is a number associated with that angle, as follows. Look at the diagram here. In the triangle, consider one of its angles C. If the length of side A is divided by the length of side H you get a number which is less than 1 (because the length of side H is greater then the length of side A). The angle C in the diagram is 45 degrees, so its Cosine is 0.707 The Cos of 22 degrees is 0.927 Every angle has a different Cosine, and the size of the triangle has no effect - an angle is an angle. The bigger the angle the smaller the Cosine. The Cos of 0 degrees is 1 (You can verify that by imagining the angle C being zero, in which case H will be the same length as A). The Cosine of 90 degrees is 0 (because A is zero).

Furthermore, imagine writing out all the Cosines for all angles between 0 through 90 degrees, 180, 270 and back to 0 degrees. At the start, at 0 degrees, they would have a high value (1), decrease slowly at first but more quickly until 90 degrees is reached when the numbers reach 0. Then the numbers would start increasing again but become negative (because A is pointing in the opposite direction - left), increasing quickly at first then slowing down until they reach, at 180 degrees, the same high value at which they started but negative (-1). Then, as the angle increases towards 270 and then back to zero the whole sequence of numbers is repeated but in reverse order.

We are Getting There

Remember this sequence? Its description is effectively identical in wording to that described above under the heading "The Numbers". So a sequence of Cosines produced by a set of gradually increasing angles is another way of generating the required type of sequence of angles for the pendulum. (Their size will be adjusted later.) That's what the Xpresso Expression does.

The Xpresso Expression (Maths Version)

Open the Xpresso Editor window again but his time concentrate on the bottom set of Nodes and follow the directions in the window to deactivate the top set and activate the bottom set. Run the animation and note that the pendulum moves in exactly the same way as with the top set of Nodes. (Remember to ignore the rotating arm.)

Trigonometric (Cos) Node

If a number arrives at its Input Node, the value of that number is treated as an angle and its Cosine is produced at its Output Port. So we have our node to produce Cosines. All we need to do is to deliver to its Input Port a sequence of numbers representing the gradually increasing size of the generating angle C. So lets look at the Time Node.

Time Node

Conveniently, the Frame Output Port of this node produces a sequence of gradually increasing numbers while the animation runs. These numbers will represent in our model the angle C as it increases. Because the total number of frames in this animation is less than 360 (the number of degrees in a full circle) you might think that the sequence of numbers representing C does not go high enough. However, as explained in the next paragraph, the size of the numbers will be adjusted to produce Radians and that sequence of numbers will be the correct size to reflect C moving a full circle

First Math:Divide Node

The Trigonometric (Cos) Node is designed to accept at its Input, data which is not in degrees but Radians. Mathematicians prefer Radians. They are simply another way of measuring angles. 360 degrees = 6.28 Radians. Therefore, our changing angle C which is delivered to the Trigonometric (Cos) Node must be as a sequence of numbers starting at 0 and ending at 6.28 for a full left-right-left cycle of swings of the pendulum (representing C moving round a full 360 degrees which is the same as 6.28 Radians). Conveniently for us, as the numbers continue to increase above 6.28, the mathematics of Trigonometric ratios (including Cos) just cause the sequence of Cos numbers to repeat itself from the beginning. This is good because we want to make the pendulum swing for several cycles (as C goes round and round) so that we can get a clear impression of its movement. Therefore, the sequence of numbers being generated by the Time Node is divided by 2.707 as can be seen in the Math (Divide) Node's Attribute Manager : Parameter button. (2.707 is simply a convenient number to get an appropriate size in the sequence of numbers being delivered by the Time Node as the animation runs. If the number 2.707 was bigger, the effect would be that the sequence of numbers being delivered to the Trigonometric (Cos) Node would be smaller and the pendulum would move more slowly.

We now have a sequence of numbers being delivered to the Trigonometric (Cos) Node representing the angle C as it increases, starting at 0 and going up gradually to 6.28 Radians (360 degrees), and continuing up to generate the second swing cycle.

Trigonometric (Cos) Node (again)

As described above, this Node converts the sequence of numbers, as Radians, to their Cosines. Therefore, we now have the Suitable Sequence of Numbers mentioned under "We are Getting There". This is a graph of the values of Cosines for angles (in Radians) from 0 to 6.28. This, and other Trigonometrical curves, are fundamental in many branches of Physics, Chemistry, Engineering, Biology, Astrophysics, you name it.

Second Math:Divide Node

If we delivered this sequence of numbers to the Global Rotation.B Input port of the Rod Node, the pendulum would swing through a very wide angle. We could leave it at that, but most pendulums swing through a small angle, so this Math (Divide) Node reduces that angle to a more realistic one.

Movie

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

Epilogue

Was that hard work? Probably not if you were paying attention when you were at school. If it was, you could just use the nodes in the Xpresso Editor window and get on with your project, or use the generator alternative mentioned earlier which is probably more intuitive to understand.