The Sphere class creates 3D spherical shapes with customizable radius and segment resolution. Spheres are generated using UV parameterization with configurable width and height segments for controlling geometry smoothness.
Spheres are generated using parametric equations with UV coordinates:Rust Implementation:/workspace/source/main/opengeometry/src/primitives/sphere.rs:76-106
for iy in 0..=height { let v = iy as f64 / height as f64; let theta = v * std::f64::consts::PI; let sin_theta = theta.sin(); let cos_theta = theta.cos(); for ix in 0..=width { let u = ix as f64 / width as f64; let phi = u * std::f64::consts::PI * 2.0; let sin_phi = phi.sin(); let cos_phi = phi.cos(); let x = self.center.x + self.radius * sin_theta * cos_phi; let y = self.center.y + self.radius * cos_theta; let z = self.center.z + self.radius * sin_theta * sin_phi; }}
Unlike other shapes, sphere outlines are generated from the B-Rep edge data to properly represent the geometry:Source:/workspace/source/main/opengeometry/src/shapes/sphere.ts:150-176
The sphere is composed of triangular faces, with special handling for the poles to avoid degenerate triangles:Source:/workspace/source/main/opengeometry/src/primitives/sphere.rs:111-136
Segment Optimization: Use widthSegments: 24 and heightSegments: 16 for general purposes. Increase for close-ups (32/24 or 48/32), decrease for distant objects (12/8) to improve performance.
Minimum Segments: The Rust implementation enforces minimum values: widthSegments >= 3 and heightSegments >= 2. Lower values will be automatically clamped.
Aspect Ratio: For most realistic spheres, maintain a widthSegments:heightSegments ratio of approximately 3:2 (e.g., 24:16, 30:20, 48:32).