Skip to content

@technobuddha > library > Geometry > Polygon

Function: rotate()

Rotates a point or a polygon around a given origin by a specified angle.

Call Signature

ts
function rotate(
   point: Cartesian, 
   angle: number, 
   options?: UnitOptions & OriginOptions): Cartesian;

Defined in: rotate.ts:31

Rotates a point around a given origin by a specified angle.

Parameters

ParameterTypeDescription
pointCartesianThe point or array of points to rotate.
anglenumberThe angle to rotate the point(s) by. Positive values rotate counterclockwise.
options?UnitOptions & OriginOptionssee UnitOptions & OriginOptions

Returns

Cartesian

The rotated point.

Example

typescript
rotate({ x: 1, y: 0 }, Math.PI / 2); // { x: 0, y: 1 }

Call Signature

ts
function rotate(
   polygon: Polygon, 
   angle: number, 
   options?: UnitOptions & OriginOptions): Polygon;

Defined in: src/rotate.ts:52

Rotates a polygon around a given origin by a specified angle.

Parameters

ParameterTypeDescription
polygonPolygonThe polygon to rotate.
anglenumberThe angle to rotate the point(s) by. Positive values rotate counterclockwise.
options?UnitOptions & OriginOptionssee UnitOptions & OriginOptions

Returns

Polygon

The rotated polygon.

Example

typescript
rotate(
  [{ x: 1, y: 0 }, { x: 0, y: 1 }],
  Math.PI / 2,
  { x: 0, y: 0 }
);
// [{ x: 0, y: 1 }, { x: -1, y: 0 }]