Transform literals - Sketch
Description: Sketch

Previous: Point and vector literals, Up: Literals

##### 3.1.3.3 Transform literals

Most transform literals are formed by constructors. These are summarized in the following table.

Constructor | Param types | Description
--- | --- | ---
`rotate(A,P,X)` | scalar,point,vector | Rotate `A` degrees about point `P` with axis `X` according to the right hand rule. See Right hand rule. `P` and `X` are both optional and default to the origin and the z-axis respectively.
`translate(X)` | vector | Translate by `X`.
`scale(S)` | scalar | Scale uniformly by factor `S`.
`scale(V)` | vector | Scale along each axis by components of `V`.
`project()` | — | Same as `scale([1,1,0])`.
`project(S)` | scalar | Perspective projection with view center at origin and projection plane z=-`S`.
`perspective(S)` | scalar | Perspective transform identical to `project(S)` except that the z-coordinate of the transformed result is pseudodepth, usable by the hidden surface algorithm.
`view(E,D,U)` | point,vector,vector | View transform similar to that of `OpenGL`'s. The eye point `E` is translated to the origin while a rotation is also applied that makes the view direction vector `D` and the view “up” vector `U` point in the negative z- and the y-directions respectively. If `U` is omitted, it defaults to [0,1,0]. When `U` is omitted, `D` may be also; it defaults to `(0,0,0)-(E)`, a vector pointing from the eye toward the origin.
`view(E,L,U)` | point,point,vector | An alternate form of `view(E,D,U)` above where the view direction parameter `D` is replaced with a “look at” point `L`, i.e., a point where the viewer is focusing her attention. This form of view is equivalent to `view(E, (L)-(E), U)`, where `(L)-(E)` is a direction vector. `U` is optional and defaults to [0,1,0].
`[[a_11,a_12,a_13,a_14]` `[a_21,a_22,a_23,a_24]` `[a_31,a_32,a_33,a_34]` `[a_41,a_42,a_43,a_44]]` | 16 scalars | Direct transform matrix definition. Each of the a_ij is a scalar expression. See text for details.

The `project` constructor is not generally useful because it defeats hidden surface removal by collapsing the scene onto a single plane. It is a special purpose transform for drawing pictures of scenes where three-dimensional objects are being projected onto planes. See, for example, Overview.

The direct transform constructor allows direct entry of a 4x4 transformation matrix. Most 3d graphics systems, including `sketch`, use 4-dimensional homogeneous coordinates internally. These are transformed by multiplication with 4x4 matrices. The built-in constructors (`rotate`, `scale`, etc.) are all translated internally to such 4x4 matrices. For more information on homogeneous coordinate transformations, see any good computer graphics textbook. The direct transform feature of `sketch` allows you to enter a matrix of your own choice. There are not many cases where this is useful, but if you do need it, you need it badly!