rotate method

Point rotate(
  1. Angle angle
)

Rotates the point around the origin (0, 0) by a given angle (in radians).

The rotation is performed counterclockwise.

Example:

var point = Point(1, 0);
Angle angle = Angle.radians(math.pi / 2)
var rotated = point.rotate(angle);
print(rotated); // Output: Point(0, 1)

Returns a new Point instance representing the rotated point.

Implementation

Point rotate(Angle angle) {
  var cosAngle = cos(angle.rad);
  var sinAngle = sin(angle.rad);
  var xRotated = x * cosAngle - y * sinAngle;
  var yRotated = x * sinAngle + y * cosAngle;
  return Point(xRotated, yRotated, z);
}