# Documentation

## Transformations

 Note:   Use only in the MuPAD Notebook Interface. This functionality does not run in MATLAB.

Affine linear transformations with a vector b and a matrix A can be applied to graphical objects via transformation objects. There are special transformations such as translations, scaling, and rotations as well as general affine linear transformations:

• ```plot::Translate2d([b1, b2], Primitive1, Primitive2, ...)``` applies the translation by the vector b = ```[b1, b2]``` to all points of 2D primitives.

• ```plot::Translate3d([b1, b2, b3], Primitive1, ...)``` applies the translation by the vector b = ```[b1, b2, b3]``` to all points of 3D primitives.

• ```plot::Reflect2d([x1, y1], [x2, y2], Primitive1, ...)``` reflects all 2D primitives about the line through the points `[x1, y1]` and `[x2, y2]`.

• ```plot::Reflect3d([x, y, z], [nx, ny, nz], Primitive1, ...)``` reflects all 3D primitives about the plane through the point `[x, y, z]` with the normal ```[nx, ny, nz]```.

• ```plot::Rotate2d(angle, [c1, c2], Primitive1, ...)``` rotates all points of 2D primitives counter clockwise by the given angle about the pivot point `[c1, c2]`.

• ```plot::Rotate3d(angle, [c1, c2, c3], [d1, d2, d3], Primitive1, ...)``` rotates all points of 3D primitives by the given angle around the rotation axis specified by the pivot point `[c1, c2, c3]` and the direction ```[d1, d2, d3]```.

• `plot::Scale2d([s1, s2], Primitive1, ...)` applies the diagonal scaling matrix `diag`(`s1`, `s2`) to all points of 2D primitives.

• `plot::Scale3d([s1, s2, s3], Primitive1, ...)` applies the diagonal scaling matrix `diag`(`s1`, `s2`, `s3`) to all points of 3D primitives.

• ```plot::Transform2d([b1, b2], A, Primitive1, ...)``` applies the general affine linear transformation with a 2×2 matrix `A` and a vector b = ```[b1, b2]``` to all points of 2D primitives.

• ```plot::Transform3d([b1, b2, b3], A, Primitive1, ...)``` applies the general affine linear transformation with a 3×3 matrix `A` and a vector b = ```[b1, b2, b3]``` to all points of 3D primitives.

The ellipses `plot::Ellipse2d` provided by the `plot` library have axes parallel to the coordinate axes. We use a rotation to create an ellipse with a different orientation:

```center := [1, 2]: ellipse := plot::Ellipse2d(2, 1, center): plot(plot::Rotate2d(PI/4, center, ellipse))```

Transform objects can be animated. We build a group consisting of the ellipse and its symmetry axes. An animated rotation is applied to the group:

```g := plot::Group2d( ellipse, plot::Line2d(center, [center[1] + 2, center[2]]), plot::Line2d(center, [center[1] - 2, center[2]]), plot::Line2d(center, [center[1], center[2] + 1]), plot::Line2d(center, [center[1], center[2] - 1]) ): plot(plot::Rotate2d(a, center, a = 0..2*PI, g)):```

Objects inside an animated transformation can be animated, too. The animations run independently and may be synchronized via suitable values of the `TimeRange` as described in section Advanced Animations: The Synchronization Model.

We generate a sphere s of radius r with center c = (cx, cy, cz). We wish to visualize the tangent plane at various points of the surface. We start with the tangent plane of the north pole and rotate it around the y axes (i.e., along the line with zero longitude) by the polar angle θ for the first 3 seconds. Then it is rotated around the z-axis (i.e., along the line with constant latitude) by the azimuth angle ϕ. We end up with the tangent plane at the point x = cx + cos(ϕ) sin(θ), y = cy + sin(ϕ) sin(θ), z = cz + cos(θ). The two rotations are realized as a nested animation: By specifying disjoint time ranges, the second rotation (around the z-axis) starts when the first rotation (around the y-axis) is finished:

```r := 1: // the radius of the sphere R := 1.01: // increase the radius a little bit c := [0, 0, 0]: // the center of the sphere thet := PI/3: // spherical coordinates of phi := PI/4: // the final point p // the final point: p := plot::Point3d(c[1] + R*cos(phi)*sin(thet), c[2] + R*sin(phi)*sin(thet), c[3] + R*cos(thet), PointSize = 2*unit::mm, Color = RGB::Black): // the sphere: s := plot::Sphere(r, c, Color = RGB::Green): // the meridian at thet = 0 c1 := plot::Curve3d([c[1] + R*sin(t), c[2], c[3] + R*cos(t)], t = 0..thet, Color = RGB::Black): // the meridian at thet = 0 c2 := plot::Curve3d([c[1] + R*cos(t)*sin(thet), c[2] + R*sin(t)*sin(thet), c[3] + R*cos(thet)], t = 0..phi, Color = RGB::Black): // form a group consisting of the tangent plane and its normal: g := plot::Group3d( plot::Surface([c[1] + u, c[2] + v, c[3] + R], u = -1..1, v = -1..1, Mesh = [2, 2], Color = RGB::Red.[0.3]), plot::Arrow3d([c[1], c[2], c[3] + R], [c[1], c[2], c[3] + R + 0.7]) ): // rotate the group for 3 seconds along the meridian: g := plot::Rotate3d(a, c, [0, 1, 0], a = 0..thet, g, TimeRange = 0..3): // rotate the group for further 3 seconds along the azimuth: g := plot::Rotate3d(a, c, [0, 0, 1], a = 0..phi, g, TimeRange = 3..6): plot(s, g, c1, c2, p, CameraDirection = [2, 3, 4]):```