createPolygon static method

List<Offset> createPolygon(
  1. int sides,
  2. double radius,
  3. Offset center, [
  4. double rotation = 0,
])

Creates a regular polygon with the given number of sides.

sides is the number of sides. radius is the radius of the polygon. center is the center of the polygon. rotation is the rotation angle in radians. Defaults to 0.

Implementation

static List<Offset> createPolygon(
  int sides,
  double radius,
  Offset center, [
  double rotation = 0,
]) {
  final points = <Offset>[];
  final angleStep = 2 * math.pi / sides;

  for (int i = 0; i < sides; i++) {
    final angle = i * angleStep + rotation;
    final x = center.dx + radius * math.cos(angle);
    final y = center.dy + radius * math.sin(angle);
    points.add(Offset(x, y));
  }

  return points;
}