Torus
function Canvas() { const geo = torus({ radius: 0.5, tube: 0.25, radialSegments: 8, tubularSegments: 32 }) const mat = rotate3dX(iMouse.y.negate()).mul(rotate3dY(iMouse.x)) const gl = useGL({ isWebGL: true, isDepth: true, count: geo.count, vertex: vec4(mat.mul(geo.vertex), 1), fragment: vec4(varying(geo.normal), 1), }) return <canvas ref={gl.ref} /> }
Torus Props
| radius | Major radius from torus center to tube center. Default is 1. |
|---|---|
| tube | Minor radius of the tube cross-section. Default is 0.4. |
| radialSegments | Number of segments around the tube circumference. Default is 12. |
| tubularSegments | Number of segments along the torus circumference. Default is 48. |
| arc | Central angle sweep in radians. Default is Math.PI*2. |
Parametric Surface Definition
The torus represents a surface of revolution generated by rotating a circle around a coaxial axis. The mathematical definition employs two angular parameters forming a coordinate system on the surface.
Where parameterizes the major circumference and parameterizes the minor circumference. The major radius controls the distance from the central axis to the tube center, while the minor radius determines the tube thickness.
Surface Normal Calculation
The normal vectors are computed by taking the cross product of the partial derivatives with respect to both parameters. For a torus, the normal at any point points radially outward from the nearest point on the central axis.
The resulting normal vector simplifies to:
Topological Properties
The torus exhibits genus-1 topology, containing exactly one handle. This fundamental property distinguishes it from spherical surfaces (genus-0) and creates non-trivial parametric relationships across the surface.
The ratio determines the torus type. When , a standard torus forms. As approaches , the inner hole shrinks. When , the surface develops a self-intersection, creating a spindle torus configuration.