sources.sphere

A UV sphere of triangles from rings latitude bands and segments longitude divisions, with smooth normals and persistent ids.

GeometricSince 0.15.0

Usage

TypeScript
Sources.sphere(params?: SourceSphereParams): Result<Geometry>

Parameters

  • params.radiusnumber

    Distance from the centre to every point. Default 0.5. In model.

  • params.ringsnumber

    Latitude bands; an integer. Default 12. Range [2, 1024] count.

  • params.segmentsnumber

    Longitude divisions; an integer. Pass 16 explicitly to rebuild a sphere made with 16 divisions: the default changes the point count and the ids. Default 32. Range [3, 1024] count.

  • params.scopestring

    The host’s node id; ids are minted under it. Default undefined (index ids, minter 0).

Returns

Ok with polygon geometry of 2 + (rings − 1) · segments points (the poles at +Y and −Y, then each ring from the top) and 2 · segments · (rings − 1) triangles (the top fan, two per band cell, the bottom fan); N (Float32 ×3) per point, the unit direction.

Errors

Guarantees

  • every point is at radius from the centre, and the volume is below 4/3 π radius³ and tends to it
  • closed, Euler characteristic 2
  • the same parameters give the same bytes (geometryContentHash), natively and in WASM
  • The same result on every machine.

Example

TypeScript
const r = Sources.sphere({ radius: 1, rings: 8, segments: 12 })
r.ok || r.diagnostics[0].code // → 86 points once loadGeometryKernel() has run

See also