Skip to Main Content Skip to Search
Product Documentation

Transformations

Affine linear transformations x -> A*x + b 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:

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))

MuPAD graphics

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)):

MuPAD graphicsimage

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 .

We generate a sphere s of radius r with center c = (c[x], c[y], c[z]). 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 Symbol::theta 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 Symbol::phi. We end up with the tangent plane at the point x = c[x] + cos(Symbol::phi)*sin(Symbol::theta), y = c[y] + sin(Symbol::phi)*sin(Symbol::theta), z = c[z] + cos(Symbol::theta). 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]):

MuPAD graphicsimage

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS