rotatePoint function

List<double> rotatePoint(
  1. double x,
  2. double y,
  3. double cx,
  4. double cy,
  5. double angle,
)

Rotate a point around a center.

Implementation

List<double> rotatePoint(
    double x, double y, double cx, double cy, double angle) {
  final s = sin(angle);
  final c = cos(angle);
  final px = x - cx;
  final py = y - cy;

  final nx = px * c - py * s;
  final ny = px * s + py * c;

  return [nx + cx, ny + cy];
}