rotate

Rotates a polyshape by an angle in degrees about a center point.

Category: Mathematics > Computational Geometry

Syntax

pshape = rotate(pshape, angle, center)

Rotates counterclockwise by angle degrees about the point center = [x y].

Description

Each vertex (x, y) is mapped to its rotation about center. Because the angle is in degrees, rotate(P, 90, c) turns a shape a quarter turn. The vertices that come back may be listed starting from a different corner than the input.

For graphics objects, a function of the same name, rotate(h, direction, alpha), rotates plotted objects about an axis in 3-D; it is a separate function.

Input arguments

pshape
A polyshape object.
angle
Rotation angle in degrees. Positive values turn counterclockwise.
center
Two-element vector with the center of rotation.

Output arguments

pshape
The rotated polyshape. Areas and perimeters are preserved.

Example

Quarter turn about the square's center

Q = polyshape([0 1 1 0], [0 0 1 1]);
R = rotate(Q, 90, [0.5 0.5]);
R.Vertices
area(R)
Output
ans = 4×2

     1     0
     0     0
     0     1
     1     1
ans = 1

Notes

Pass the center explicitly. When it is omitted MatLivre rotates about the origin.

See also

scale translate polyshape centroid