rotatePointInBox function

List<double> rotatePointInBox(
  1. double x,
  2. double y,
  3. double angle,
  4. double width,
  5. double height,
)

Implementation

List<double> rotatePointInBox(
  double x,
  double y,
  double angle,
  double width,
  double height,
) {
  double angleValue = degreesToRadians(angle);
  double centerX = width / 2.0;
  double centerY = height / 2.0;
  double dx = x - centerX;
  double dy = y - centerY;
  double dist = sqrt(dx * dx + dy * dy);
  double a = atan2(dy, dx) + angleValue;
  double dx2 = cos(a) * dist;
  double dy2 = sin(a) * dist;

  return [dx2 + centerX, dy2 + centerY];
}