sphere static method

void sphere(
  1. Vector3 center,
  2. double radius, {
  3. int segments = 16,
  4. Vector4? color,
})

Draws a wireframe sphere at center with radius.

Implementation

static void sphere(
  vm.Vector3 center,
  double radius, {
  int segments = 16,
  vm.Vector4? color,
}) {
  for (var i = 0; i < segments; i++) {
    final a1 = (i / segments) * 2 * math.pi;
    final a2 = ((i + 1) / segments) * 2 * math.pi;

    final c1 = math.cos(a1) * radius;
    final s1 = math.sin(a1) * radius;
    final c2 = math.cos(a2) * radius;
    final s2 = math.sin(a2) * radius;

    // XZ circle
    line(
      center + vm.Vector3(c1, 0, s1),
      center + vm.Vector3(c2, 0, s2),
      color: color,
    );
    // XY circle
    line(
      center + vm.Vector3(c1, s1, 0),
      center + vm.Vector3(c2, s2, 0),
      color: color,
    );
    // YZ circle
    line(
      center + vm.Vector3(0, s1, c1),
      center + vm.Vector3(0, s2, c2),
      color: color,
    );
  }
}