| Unit of distance |
Since ThreeDimSim does not make assumptions about the unit of distance used in
your script, you have to assume the unit size. In the previous example, the box
was moved 5 units, you have to assume if this means 5 meters, 5 inches or 5
micrometers, or anything else. The only prerequisite is that all units used in
the script form a consistent set. For example, as velocity is expressed in
distance units per time units, the choice you make for the distance unit has to
be
reflected in the velocity unit. |
| Move |
As demonstrated in the previous paragraph, an object can be positioned by
using the method move. The move(x,y,z) method translates an object over the
specified vector [x,y,z]. The vector is given by the 3 arguments x,y,z. Many
methods have alternate forms. In this case, the move method also accepts one
argument containing the translation vector: move(p). You can define a vector by
enclosing its 3 elements by braces: {x, y, z}. Example:
// move the object 'a' 10 units in x-, 20 in y-
//and 30 in z- direction
a.move(10,20,30);
// define a vector p
var p = {10,20, 30};
// translate the object 'a' over vector 'p'
a.move(p);
// create the vector on the fly
a.move ( { 10,20,30} );
|
| Rotate |
The orientation of an object can be changed by the rotate method. Example:
// express angles in degrees
factory.useDegrees = true;
// rotate around y-axis with 90 degrees
a.rotate(0, 90, 0);
In this example object 'a' is rotated around the y-axis with 90 degrees. The factory
property useDegrees was set to true, meaning that after this property is set, all arguments concerning angles are expressed in
degrees. This setting will continue to hold until the 'useDegrees' property is changed. When useDegrees is set false, radians are expected.
Example:
// express angles in radians
factory.useDegrees = false;
// rotate around x-axis with .2 radians
a.rotate(.2,0,0);
Another way to change the orientation is the method rotateAround. This method
will rotate the object around another one, over a specified angle. To do so, it
uses the current position and orientation of the object to define the plane in
which the object will be rotated. Example:
// create a cylinder
var a = Cylinder(10,10,20);
// create a cube with size 10 at position [30,0,0]
var b = Box({10,10,10}, {30,0,0});
// rotate the box around the cylinder with 45 degrees
b.rotateAround(a, 45);
|