Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Geometric Types

Convex-λ provides first-class support for 3D geometry.

Vector

Represents a direction and magnitude in 3D space. Vectors are location-independent.

Constructor

Vector(x, y, z)

v = Vector(1.0, 0.0, 0.0)
up = Vector(0, 0, 1)
assert(up.z == 1, "Vector Z")

Properties

  • .x, .y, .z: Coordinates

Helpers

  • Normal(elevation, azimuth): Creates a unit vector from spherical coordinates.
    • elevation: 0 (Equator) to 90 (Pole).
    • azimuth: 0 to 360.
    • Note: If Mode("index") is active, elevation 0 is Pole, 90 is Equator.
// Standard Math Mode
n = Normal(90, 0) // Z axis (Pole)
assert(abs(n.z - 1) < 0.001, "Normal pole")

// Faceting Mode (after Gear())
Gear(96)
n_facet = Normal(0, 0) // Z axis (Pole)
assert(abs(n_facet.z - 1) < 0.001, "Facet Normal pole")

Point

Represents a specific location in 3D space.

Constructor

Point(x, y, z)

origin = Point(0, 0, 0)
p = Point(10, 5, -2)
assert(p.y == 5, "Point Y")

Properties

  • .x, .y, .z: Coordinates

Line

Represents an infinite line defined by an origin point and a direction vector.

Constructor

  1. Line(Point, Vector): Point and Direction.
  2. Line(Point, Point): Two points (direction is p2 - p1).
l1 = Line(Point(0,0,0), Vector(0,0,1)) // Z axis
l2 = Line(Point(0,0,0), Point(1,1,1))  // Diagonal

Usage

Lines are typically the result of intersections (Plane * Plane).

Plane

Represents an infinite plane. This is the primary "cutting" tool in faceting.

Constructor

  1. Plane(Normal, Distance): Normal vector and distance from origin.
  2. Plane(index, p1, p2): (Faceting mode only) Defines plane by gear index and two points.
// Plane facing X, at distance 5
p1 = Plane(Vector(1,0,0), 5)
assert(p1.distance == 5, "Plane Dist")

// Plane facing Z, passing through origin
p2 = Plane(Vector(0,0,1), 0)

Properties

  • .normal: The normal Vector.
  • .distance: The distance Number.

Symmetry Groups

Represents a geometric transformation or collection of transformations. Groups are applied using the pipe operator |>.

Constructor

  1. Rotate(axis, order): Creates a rotational symmetry group.
  2. Mirror(plane): Creates a reflection symmetry.
// 4-fold rotation around Z
rot = Rotate(Vector(0,0,1), 4)

// Mirror across XY plane
mir = Mirror(Plane(Vector(0,0,1), 0))

// Composition using *
group = rot * mir

Arrays of Geometry

Most operations work on arrays of geometry (broadcasting).

ring_pts = [Point(1,0,0), Point(0,1,0), Point(-1,0,0), Point(0,-1,0)]
assert(ring_pts.length == 4, "Array length")

Helpers

  • Hull(points_array): Creates the convex hull (array of planes) from a set of points.
pts = [Point(1,0,0), Point(-1,0,0), Point(0,1,0), Point(0,-1,0), Point(0,0,1), Point(0,0,-1)]
octahedron = Hull(pts)
assert(octahedron.length == 8, "Octahedron faces")