Geometria
A collection of definitions and algorithms for working with 2- and 3- dimensional geometries in Swift.
(README.md is still in construction.)
Type definitions
N-dimensional | |||
---|---|---|---|
Primitive | Illustration | Geometria type | Remarks |
Axis-aligned bounding-box | AABB.swift | Defined as two point vectors describing the minimal and maximal coordinates contained within the AABB. | |
Ray (unit vector direction) | DirectionalRay.swift | Defined as a starting point vector and a unit vector describing the direction of the ray. Conceptually it extends to infinity in only one of its two ends (pointed to by its direction unit vector). | |
N-dimensional Ellipsoid | Ellipsoid.swift | Defined as a center point vector and an axis vector. | |
Hyperplane | Hyperplane.swift | Defined as a point vector on the plane and a unit vector orthogonal to the hyperplane’s surface. Defines a split between two half-spaces of the space it is contained within. Is considered a convex, volumetric space that can be intersected against lines and contain points. | |
Line | Line.swift | Defined as a pair of point vectors on the line. Conceptually it extends to infinity at both ends. | |
Line segment | LineSegment.swift | Defined as start and end point vectors on the line. Conceptually it is contained only within the limits of start <-> end. | |
N-dimensional capsule | NCapsule.swift |
Defined as a line segment containing two point vectors describing the span of the capsule’s body, and a scalar
radius that defines the maximal distance to the line segment points must be to be considered as contained within the capsule.
Specializes as a Stadium in 2D and Capsule in 3D. |
|
Hyperrectangle | NRectangle.swift | Defined as an origin (top-left in two dimensions) point vector and an N-dimensional size vector. | |
N-sphere | NSphere.swift | Defined as a center point vector and a scalar radius. | |
N-dimensional cube (Hypercube) | NSquare.swift |
Generalized for any dimension.
Defined as an origin point (top-left in two dimensions) and a scalar value that describes the span of the cube, in each dimension. Forms a square in 2D, and a cube in 3D. |
|
Plane | PointNormalPlane.swift | Defined as a point vector on the plane and a unit vector orthogonal to the plane’s surface. | |
Ray (two-point) | Ray.swift | Defined as a pair of points start and b describing the two points the ray crosses before projecting to infinity. Similar in definition to a line and line segment, but extends in one direction to infinity. | |
Triangle | Triangle.swift | Defined as a set of three point vectors. |
GeometriaClipping
An extra library dependency exported called GeometriaClipping
can be used to generate boolean geometry from input geometries composed of line and circular arc simplexes.
The operations supported are the following:
2-dimensional | ||
---|---|---|
Operation | Illustration | GeometriaClipping type |
Union | Union2Parametric.swift | |
Intersection | Intersection2Parametric.swift | |
Subtraction | Subtraction2Parametric.swift | |
Exclusive disjunction or Symmetric Difference | ExclusiveDisjunction2Parametric.swift |