Rotate

Method: point.rotate(centre, angle)

Parameters:

  • centre — the centre of rotation as a Point

  • angle — the rotation angle in radians (positive = counter-clockwise)

Returns: Point


Description

Rotating a point \(P\) about a centre \(C\) by angle \(\theta\) is performed in three steps:

  1. Translate \(P\) so that \(C\) is at the origin: \(P' = P - C\)

  2. Apply the 2D rotation matrix:

\[\begin{split}R(\theta) = \begin{pmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{pmatrix}\end{split}\]
  1. Translate back: add \(C\) to the result.

Written out component-wise:

\[x' = C_x + (P_x - C_x)\cos\theta - (P_y - C_y)\sin\theta\]
\[y' = C_y + (P_x - C_x)\sin\theta + (P_y - C_y)\cos\theta\]

Sign convention

Following the standard mathematical convention, positive angles rotate counter-clockwise. To rotate clockwise, pass a negative angle.

A full revolution is \(2\pi\) radians (\(360°\)). Common conversions:

Degrees

Radians

90°

\(\pi / 2 \approx 1.571\)

180°

\(\pi \approx 3.14159\)

270°

\(3\pi / 2\)

360°

\(2\pi\)

Implementation

rotate(centre, angle) {
  const x = centre.x + (this.x - centre.x) * Math.cos(angle)
                     - (this.y - centre.y) * Math.sin(angle);
  const y = centre.y + (this.x - centre.x) * Math.sin(angle)
                     + (this.y - centre.y) * Math.cos(angle);
  return new Point(x, y, this.bulge, this.sequence);
}

Usage in Design

rotate underpins the Rotate command, where every point of each selected entity is rotated about the user-specified base point by the given angle.

It is also used internally when generating arc geometry — for example, rotating a point around an arc centre to step through arc vertices — and in the AngularDimension to position arrow-head endpoints around a shared intersection point.

See Also

Project | Development