triSDF: Two-Dimensional Triangle Distance Field
Planar Triangular Geometry
The triSDF
function computes the signed distance from any 2D point to an equilateral triangle. This primitive provides the foundation for triangular patterns, tessellations, and geometric compositions in 2D space.
Mathematical Foundation
The triangular SDF uses geometric constraints based on the equilateral triangle properties:
where the coefficient represents the geometric relationship for an equilateral triangle's sides.
The coordinate transformation centers the triangle and scales it:
Function Variants
Function | Parameters | Description |
---|---|---|
triSDF | st | Triangle centered at (0.5, 0.5) |
triSDFCenter | st , center | Triangle at custom position |
Function Signature
Parameter | Type | Description |
---|---|---|
st | vec2 | Sample point in 2D space |
center | vec2 | Triangle center position (triSDFCenter only) |
Implementation Demonstrations
ライブエディター
const fragment = () => { const pos = uv.mul(2).sub(1) const dist = triSDF(uv).step(0.5) return vec4(vec3(dist), 1) }