scale

Scales a polyshape by a factor, about a center point.

Category: Mathematics > Computational Geometry

Syntax

pshape = scale(pshape, s)

Multiplies all coordinates by the scalar s.

pshape = scale(pshape, [sx sy])

Uses different factors along x and y.

pshape = scale(pshape, [sx sy], center)

Scales about the point center = [x y] instead of the origin.

Description

The point center stays where it is and every other vertex moves along the line from the center by the factor given. With a factor of 2 a shape doubles in width and height, and its area grows four times. A negative factor mirrors the shape.

The name scale is also used by other toolboxes for unrelated normalizing operations; with a polyshape it is geometric scaling.

Input arguments

pshape
A polyshape object.
s
Scale factor: a scalar, or a two-element vector [sx sy].
center
Fixed point of the scaling.

Output arguments

pshape
The scaled polyshape. Area changes by sx*sy.

Example

Stretch a rectangle in x only

P = polyshape([0 2 2 0], [0 0 1 1]);
S = scale(P, [3 1], [0 0]);
S.Vertices
are = [area(P) area(S)]
Output
ans = 4×2

     0     0
     0     1
     6     1
     6     0
are = 1×2

     2     6

Notes

In MatLivre, use the vector form [sx sy] when you also pass a center; the scalar form with a center is not handled correctly.

See also

rotate translate polyshape area