tiny.geometry.Triangle
Defined in tiny.geometry.
A triangle with counter-clockwise winding around its normal.
API (9)
Actions
Public operations.
areaNormal: The unnormalized normal, twice the area in length.boundscentroidisDegenerate: Whether the corners are collinear, or so close to it that the area normal is rounding noise.normal: The unit normal, or null for a degenerate triangle.vertex
Fields and members
Public fields and members.
Source
Source: lib/geometry/src/primitive.zig:146
zig
/// A triangle with counter-clockwise winding around its normal.pub const Triangle = extern struct { a: Vec3, b: Vec3, c: Vec3, /// The unnormalized normal, twice the area in length. pub fn areaNormal(triangle: Triangle) Vec3 { return triangle.b.sub(triangle.a).cross(triangle.c.sub(triangle.a)); } /// Whether the corners are collinear, or so close to it that the area /// normal is rounding noise. pub fn isDegenerate(triangle: Triangle) bool { const edge1 = triangle.b.sub(triangle.a); const edge2 = triangle.c.sub(triangle.a); return tolerance.isParallel(edge1.cross(edge2).lengthSq(), edge1.lengthSq() * edge2.lengthSq()); } /// The unit normal, or null for a degenerate triangle. pub fn normal(triangle: Triangle) ?Vec3 { if (triangle.isDegenerate()) return null; return triangle.areaNormal().normalized(0); } pub fn centroid(triangle: Triangle) Vec3 { return triangle.a.add(triangle.b).add(triangle.c).scale(1.0 / 3.0); } pub fn bounds(triangle: Triangle) Aabb { return Aabb.fromPoint(triangle.a).joinPoint(triangle.b).joinPoint(triangle.c); } pub fn vertex(triangle: Triangle, index: usize) Vec3 { assert(index < 3); return switch (index) { 0 => triangle.a, 1 => triangle.b, else => triangle.c, }; }};Source: lib/geometry/src/root.zig:19
zig
pub const Triangle = primitive.Triangle;Audit
| Definitions | 7 |
|---|---|
| Public names | 7 |
| Members | 3 |
| Version | 26.7.0 |
| Revision | daab053ee433 |