Search:

In the properties of a 2D view element, when you hover over the word ‘Transform’ the tooltip shows the kinds of input that the view property accepts. The listing states: AffineTransform, int, double, double[], double[][], Object.

Int and Double shortcuts
The inputs ‘int’ and ‘double’ provide the shortest way to specify a rotation. (Of course, the input can be either a simple number, or a variable that has been declared on the variables panel.)
EJS takes an int to specify degrees, and a double to specify an angle in radians.

### Dialog box

The image to the right shows the dialog box that accompanies the cell ‘Transform’. This dialog box will generate strings that specify various transformations.

For example: enter the number “45” in the cell next to the button “Rotation”, and press the button. The line on the bottom will then read: ro:45d  That is entirely a string. To create the specified transform EJS processes that string.

A subsequent transformation can be added by adding another number and pressing the adjacent button. For example 1 and 1 the cells next to “Translation” and pressing the button. The line on the bottom will then read ro:45d & tr:1,1

A transformation for a 2D element is an object of the AffineTransform Java class. You can find some nice references if you google for AffineTransform, such as http://www.glyphic.com/transform/.

• If you link a double[] array (with at least 6 numbers in it) to the property transformation EJS set the transformation to `new AffineTransform(array)`. See the Javadoc page for AffineTransform to learn what this means.

• If you link a double[][] array to the property transformation EJS set the transformation to:
• if (array[0].length==2): `new AffineTransform(array[0][0],array[1][0],array[0][1],array[1][1],0,0));`
• if (array[0].length≥3): `new AffineTransform(array[0][0],array[1][0],array[0][1],array[1][1],array[0][2],array[1][2]));`
See the Javadoc page for AffineTransform to learn what this means.

• Finally, if you link an object of the `org.opensourcephysics.numerics.Matrix2DTransformation` class, EJS will use the AffineTransform returned by its `getTotalTransform()` for the element. The `Matrix2DTransformation` includes the constructors:
• `public static Matrix2DTransformation rotation(double theta)`: Creates a 2D transformation representing a rotation about the origin by the given angle.
• `public static Matrix2DTransformation rotation(double theta, double anchorx, double anchory)` : Creates a 2D transformation representing a rotation about the origin by the given angle around the given axis.
• `public static Matrix2DTransformation createAlignmentTransformation(double[] v1, double v2[])` : Instantiates a rotation that aligns the first vector with the second vector.
You can also multiply (compose) several objects of the `Matrix2DTransformation` class.