Home :: Login :: Forgot Password :: Search :: FAQ
Support our host

News

Software

Reference

Community

Parts Library

About Us

Reference > Tutorials
Published By OrionP on Sunday, February 22, 2004 - 05:53 PM

Printer-friendly page



Introduction:

This Tutorial is about the advanced movement of pistons and other vector animations. Animations of steering assemblies, motors, and other mechanical elements will make every model to an eye-catcher. It will start with a crash-course in trigonometry and ends with a simple example and step-by-step instructions.

At the end we will be able to make an animated model seen in this animation:


The reqirements:

  • You should have read and understood the last animation tutorials, since some parts won't be described in as much depth in this tutorial (e.g the use of ini's or l3p).
  • simple.zip

Basics in Trigonometry:

If you are like many, you have forgotten the trigonometry you learned in high school. But trigonometry is essential for animations like pistons, cranes, etc. Don't be afraid, this math isn't as "hard" as you think. The only thing we need is a circle and an arrow.

The arrow can be rotated around a circle like the hand of a clock. Every position can be described by the angle alpha. The arrow (also called "vector") always has the same length, in our case "1". The only things that change with the angle are the "shadows" of this arrow - cos(alpha) and sin(alpha). Cos(alpha) is the shadow on the x-coordiante and the Sin(alpha) the one on the y-coordinate. Lets take a look at the lengths of these "shadows". The values are in a range between 0 and 1. Just rotate the vector and you will understand. Now its time to take a closer at the angle. The angle can be measured in two formats: degrees and radians. Degrees are the most common way. 360° are one full circle. Radians are only used in science and engineering; this is the reason why they are not commonly known. 2*PI Radians are one full circle.
Now its time to grab a calculator (even that one in Windows has sin/cos/tan !) and try it by yourself. Verify the angle system currently chosen (degrees is usually set by default) and try different angles.

This table will show you the most important values/angles:

alpha 0° or 0 90° or PI/2 180° or PI 270° or 3/2*PI 360° or 2*PI
Sin(alpha) 0 1 0 -1 0
Cos(alpha) 1 0 -1 0 1

There are some formulas you should keep in mind, because you use them to calculate X-Y coordinates.
The two shorter sides of a right-angled triangular are called "legs" and the third, the longest "hypotenuse". When the "opposite" or the "adjacent" leg is required, the one "opposite" and "adjacent" to angle alpha is meant.

sin(alpha) = [opposite leg]/[Hypothenuse]
cos(alpha) = [adjacent leg]/[Hypothenuse]
tan(alpha) = sin(alpha)/cos(alpha) = [oppsite leg]/[adjacent leg]

If this breif discussion trigonometry was to short for you, feel free to google for some better and more colorful examples. :)


The Tutorial:

1) The Model

First we have to create a simple MLCAD file that look like this one:

This file can contain more parts, but this is only a demonstration. The simpler, the better.
Save the file and create a POV-Ray file with l3p.

2) What a converted POV file contains (In the same order):

  • Global values (quality, studs, ambient...)
  • Definition of sub/primitive parts (unions of basic shapes)
  • Definition of the parts (unions of basic shapes and primitves/subparts)
  • Definition of the model(s) (unions of parts)
  • Scene objects (floor, camera, lights...)

We have a file with only 2 parts, but still has 1300 lines. This makes it necessary to know where to define values and what need to be rotated/translated. Usually only the parts in the model-definition are rotated/translated. This means after the line:

#declare [modelfilename]_dot_ldr = union {....

3) What we want to animate:

The gear should rotate and the steering link act like a piston which is moved by the gear.

4) The rotation of the gear:

First we have to define a value that calculates the angle from the clock. In this case the clock starts with 0 and ends with 1. So all that is needed is to add the following line under #declare: DIF =.....:

#declare angle_gear = 360 * clock;

Now we need to tell the gear that it has to rotate. This is done in the model definition. We change the following block

object {
_3648_dot_dat
matrix <1-SW/65.96,0,0,0,1-SW/65.96,0,0,0,1-SW/20,0,0,0>
matrix <0.707107,-0.707107,0,0.707107,0.707107,0,0,0,1,-10,-16,30>
#if (version >= 3.1) material #else texture #end { Color14 }
}

to:

object {
_3648_dot_dat
matrix <1-SW/65.96,0,0,0,1-SW/65.96,0,0,0,1-SW/20,0,0,0>
matrix <0.707107,-0.707107,0,0.707107,0.707107,0,0,0,1,-10,-16,30>
translate <10,16,-30>
rotate <0,0,angle_gear>
translate <-10,-16,30>
#if (version >= 3.1) material #else texture #end { Color14 }
}

What did we do?
A rotation is always done around the zero-point (x=0, y=0, z=0). so we have to bring the (rotation) center of the part to the center of the scene. We do that by moving the gear with the translate command. Where do you get the coordinates? Just take a look to the second matrix, all three values are there. The rotation command tells the gear to spin around the z-axis and the second translate command moves it back into place.

Note: The Rotation Animation Tutorial uses a different technique for translating/rotating. The advantage ot the system used here is that you have a chance to control the old position values. The disadvantage is that it has one translate command more. Both work fine, so use whatever method you wish. :)

5) Time to animate!

Set the ini file found in simple.zip as the ini which is used for rendering.

Now run the file and have a look at the results. The gear should now turn

6) The translation of the steering link

The Steering link has two main movements: translation and rotation. First we will translate it by the clock.

This is the step where we will have to use the formulas from the trigonometry basics above.
Add the following two value-declarations:

#declare piston_x = -14 * cos(radians(angle_gear));
#declare piston_y = -14 * sin(radians(angle_gear));

the piston should start on the left and the radius will be 14 so we need a x-offset of -14 and a y-offset of 0 when the clock is 0. cos(0) = 1 and sin (0) = 0, so it is clear that we have to use cosine for the x-offset and sine for the y-offset. At a clock of 0 we will have piston_x = -14 * 1 and piston_y = -14*0 . The gear rotates clockwise, so at 90° we will be at the top. The higher we get, the lower the y-value will be. This is the reason why the piston_y value has a "-" as well (sin(90°) = 1). Pov-ray requires a angle value in radians, so we have to convert our angle (in degrees) to radians using radians(angle_gear).

Next we have to translate the part definition like we did for the gear:

object {
_2739_dot_dat
matrix <1-SW/20,0,0,0,1-SW/12,0,0,0,1-SW/120,0,0,SW/2.4>
matrix <0,-1,0,0,0,1,-1,0,0,-24,-16,14>
#if (version >= 3.1) material #else texture #end { Color4 }
}

to:

object {
_2739_dot_dat
matrix <1-SW/20,0,0,0,1-SW/12,0,0,0,1-SW/120,0,0,SW/2.4>
matrix <0,-1,0,0,0,1,-1,0,0,-24,-16,14>
translate <14+piston_x,piston_y,0>
#if (version >= 3.1) material #else texture #end { Color4 }
}

Why is there an additional 14 in the translate-comand?
We calculated the movement from the center of the gear. Our link isn't in the the center, so we have to move it to the right by the radius.

If you have finished this step, see if it works when you run your animation. The piston hole should move with one hole of the gear.

7) The rotation of the piston

Now we will have to add a new value, the angle of the piston.

#declare angle_piston = degrees(asin(piston_y/100));

Huh. Looks confusing doesn't it?
The explanation is simple. The only value that changes the angle of the piston is the piston_y value (up-down motion). 100 is the distance between the centers if the holes of the link. Here is a picture to make it easier to understand:

What do we know? piston_y and the length of the piston (brown)
What do we need? beta - which is equal to angle_piston

The length of our piston is the Hypotenuse and piston_y is the adjacent leg. So lets fill these information into our formular:

sin(alpha) = [opposite leg]/[Hypothenuse]
sin(angle_piston) = piston_y/100
We need to solve for angle_piston, so a little bit of algebra later:
piston_angle = asin(piston_y/100)
But we need the value in degrees, and in Pov-ray asin returns a value in radians. The solution:
piston_angle = degrees(asin(piston_y/100))

degrees(value) transforms a radian value into one in degrees

we now have our value, so let's use it!

object {
_2739_dot_dat
matrix <1-SW/20,0,0,0,1-SW/12,0,0,0,1-SW/120,0,0,SW/2.4>
matrix <0,-1,0,0,0,1,-1,0,0,-24,-16,14>
translate <14+piston_x,piston_y,0>
#if (version >= 3.1) material #else texture #end { Color4 }
}

will be changed to:

object {
_2739_dot_dat
matrix <1-SW/20,0,0,0,1-SW/12,0,0,0,1-SW/120,0,0,SW/2.4>
matrix <0,-1,0,0,0,1,-1,0,0,-24,-16,14>
translate <24,16,0>
rotate <0,0,angle_piston>
translate <-10+piston_x,-16+piston_y,0>
#if (version >= 3.1) material #else texture #end { Color4 }
}

In our example the center of the piston is on one of the end holes (if you didn't use the example model, check where your part center is!!!). That means, that we just have to move the part center to the scene origin. (we did't move it in the z-direction, because we want to spin around the z-axis) From there we rotate our steering link with the rotate command. Where should we move it afterwards? We know that the offsets are calculated from the center of the gear, so let's move it there.

8) Everything has an end!

Run the POV file and see what you've got. If you combine the knowledge from this and the previous tutorials, you will be able to create amazing animations, like steerings and suspensions. Also, don't forget to share with the rest of us!! :D

By Martin Humel (martin [DoT] humel {aT} chello (dOt) at) (http://members.chello.at/martin.humel/
Edited by Orion Pobursky




Recipient 2007
Kevin Clague

Want to learn more about LDraw? Check out the following books:




Current Contest Winners

Model of the Month


Scene of the Month



Vote for Next Month's Winner

Submit Your Creation for Next Month's Contest

What's new in lugnet.cad?

Re: Blender to LDraw exporter (Blend2Dat v0.2)
by Stefan Garcia - 26 hours ago

Re: Blender to LDraw exporter (Blend2Dat v0.2)
by Philippe Hurbain - 33 hours ago

Re: Blender to LDraw exporter (Blend2Dat v0.2)
by Stefan Garcia - 2 days ago

58231.DAT Slope 33 3 x 6 is wrong type
by Lutz Uhlmann - 3 days ago


There are 44 unlogged users and 0 registered users online.

You can log-in or register for a user account here.





 


 Log in Problems?
 New User? Sign Up!

©2003-2008 LDraw.org, see Legal Info for details.
LDraw™ is a trademark owned and licensed by the Estate of James Jessiman
This website is powered by Peeron.com.

LEGO® is a registered trademark of the LEGO Group, which does not sponsor, endorse, or authorize this site. Visit the official Lego website at http://www.lego.com.
LDraw is a completely unofficial, community run free CAD system which represents official parts produced by the LEGO company.