getRotatedRectPoints function

List<Offset> getRotatedRectPoints(
  1. double cx,
  2. double cy,
  3. double width,
  4. double height,
  5. double rotation,
)

Calculates the 4 corner points of a rotated rectangle.

Matches OpenCV's cv.boxPoints() behavior for drawing rotated bounding boxes. Parameters:

  • cx, cy: Center coordinates of the rectangle
  • width, height: Dimensions of the rectangle
  • rotation: Rotation angle in radians

Returns a list of 4 Offset points representing the corners of the rotated rectangle.

Implementation

List<Offset> getRotatedRectPoints(
  double cx,
  double cy,
  double width,
  double height,
  double rotation,
) {
  final b = cos(rotation) * 0.5;
  final a = sin(rotation) * 0.5;

  return [
    Offset(cx - a * height - b * width, cy + b * height - a * width),
    Offset(cx + a * height - b * width, cy - b * height - a * width),
    Offset(cx + a * height + b * width, cy - b * height + a * width),
    Offset(cx - a * height + b * width, cy + b * height + a * width),
  ];
}