Translation of 2D objects

MuPAD® notebooks will be removed in a future release. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.


plot::Translate2d([dx, dy], obj1, <obj2, …>, <a = amin .. amax>, options)


plot::Translate2d([dx, dy], object) shifts a 2D object by dx units along the x-axis and dy units along the y-axis.

plot::Translate2d can translate several graphical objects simultaneously. Plotting the translate object renders all graphical objects inside.

Transformation objects can be used inside translation objects. If they are animated, the animations run simultaneously.

Animated translate objects are rather “cheap” concerning computing and storing costs. For more complex graphical objects, it is more efficient to use an animated translate object than to redefine the object for each frame.

The function op allows to extract the graphical objects inside a translate object.


AttributePurposeDefault Value
AffectViewingBoxinfluence of objects on the ViewingBox of a sceneTRUE
Framesthe number of frames in an animation50
Namethe name of a plot object (for browser and legend) 
ParameterEndend value of the animation parameter 
ParameterNamename of the animation parameter 
ParameterBegininitial value of the animation parameter 
ParameterRangerange of the animation parameter 
Shiftshift vector[0, 0]
ShiftXshift vector0
ShiftYshift vector0
TimeEndend time of the animation10.0
TimeBeginstart time of the animation0.0
TimeRangethe real time span of an animation0.0 .. 10.0


Example 1

Use an animated translation object to shift a vector to the tip of another vector:

A1 := plot::Arrow2d([0, 0], [2, 1], Color = RGB::Red):
A2 := plot::Arrow2d([0, 0], [2, 3], Color = RGB::Green):
plot(A1, plot::Translate2d([2*a, a], A2, a = 0..1,
                           TimeRange = 0..4),
     plot::Arrow2d([0, 0], [4, 4], Color = RGB::Blue,
                   VisibleFromTo = 4..6),
     Header = "how to add 2 vectors"):

delete A1, A2:

Example 2

Note that plot::Translate2d does not actually change the objects translated, so you can use the same object in different places in the same plot. For example, use the following approach to construct the Sierpinski carpet, a flat version of the Menger sponge.

The Sierpinski carpet is a fractal with the general shape of a square and the property that the following operation maps it onto itself: Take eight copies, scale them by , and arrange them in a square with the middle left unfilled. Now, this can be directly written in MuPAD® code:

Carpet := proc(iter)
  local square;
  if iter <= 1 then
    return(plot::Polygon2d([[0,0], [0,1], [1,1], [1,0]],
                           Closed, Filled, FillPattern = Solid,
                           FillColor = [0.2234, 0.4563, 0.4568],
                           LinesVisible, LineColor = RGB::White,
                           Scaling = Constrained, Axes = None));
    square := plot::Scale2d([1/3, 1/3], Carpet(iter-1));
                 plot::Translate2d([  0,   0], square),
                 plot::Translate2d([  0, 1/3], square),
                 plot::Translate2d([  0, 2/3], square),
                 plot::Translate2d([1/3,   0], square),
               //   plot::Translate2d([1/3, 1/3], square),
                 plot::Translate2d([1/3, 2/3], square),
                 plot::Translate2d([2/3,   0], square),
                 plot::Translate2d([2/3, 1/3], square),
                 plot::Translate2d([2/3, 2/3], square)));


dx, dy

The components of the shift vector: numerical real values or arithmetical expressions of the animation parameter a.

dx, dy are equivalent to the attribute Shift.

obj1, obj2, …

Arbitrary plot objects of the appropriate dimension


Animation parameter, specified as a = amin..amax, where amin is the initial parameter value, and amax is the final parameter value.