![]() |
omdl
v1.0
OpenSCAD Mechanical Design Library
|
Triangle mathematical functions. More...
Collaboration diagram for Triangles:Files | |
| file | triangle.scad |
| Triangle shapes, conversions, properties, and tests functions. | |
Shapes | |
| function | triangle_ppp2sss (c) |
| Compute the side lengths of a triangle given its vertex coordinates. More... | |
| function | triangle_sas2sss (v) |
| Compute the side lengths of a triangle given two sides and the included angle. More... | |
| function | triangle_asa2sss (v) |
| Compute the side lengths of a triangle given a side and two adjacent angles. More... | |
| function | triangle_aas2sss (v) |
| Compute the side lengths of a triangle given a side, one adjacent and the opposite angle. More... | |
| function | triangle2d_sss2ppp (v, a=x_axis_ci, cw=true) |
| Compute a set of vertex coordinates for a triangle given its side lengths in 2D. More... | |
Properties | |
| function | triangle2d_area (c, s=false) |
| Compute the area of a triangle given its vertex coordinates in 2D. More... | |
| function | triangle_centroid (c, d=2) |
| Compute the centroid of a triangle. More... | |
| function | triangle2d_incenter (c) |
| Compute the center coordinate of a triangle's incircle in 2D. More... | |
| function | triangle2d_inradius (c) |
| Compute the inradius of a triangle's incircle in 2D. More... | |
| function | triangle2d_excenter (c, vi=1) |
| Compute the center coordinate of a triangle's excircle in 2D. More... | |
| function | triangle2d_exradius (c, vi=1) |
| Compute the exradius of a triangle's excircle in 2D. More... | |
| function | triangle_circumcenter (c, d=2) |
| Compute the coordinate of a triangle's circumcenter. More... | |
Tests | |
| function | triangle2d_is_cw (c) |
| Test the vertex ordering, or orientation, of a triangle in 2D. More... | |
| function | triangle2d_is_pit (c, p) |
| Test if a point is inside a triangle in 2d. More... | |
Rounding | |
| function | triangle2d_vround3_center (c, r) |
| Compute the rounding center coordinate for a given radius of a triangle vertex in 2D. More... | |
| function | triangle2d_vround3_tangents (c, r) |
| Compute the rounding tangent coordinates for a given radius of a triangle vertex in 2D. More... | |
Triangle mathematical functions.
| file | group | script | results | no test | skipped | passed | failed | warning |
|---|---|---|---|---|---|---|---|---|
| math/triangle.scad | Triangles | Script | Results | 16 | 0 | 0 | 0 | 0 |
See complete validation results.
| Requires: |
|---|
| include <omdl-base.scad>; |
The following conventions apply to all functions in this group.
c is always a list of three coordinate points [v1, v2, v3]; v is always a scalar input list (sides and/or angles), with element order encoded in the function name (e.g. triangle_sas2sss takes [s1, a3, s2]).vi is the vertex-selector parameter (1-indexed: 1 = v1, 2 = v2, 3 = v3); out-of-range values return a stated fallback without error.d controls output dimensionality: d = 2 (default) silently discards the z-component of 3d input; d = 3 preserves it; d = 0 auto-detects from the minimum coordinate length of c.cw = true (default) orders output vertices clockwise; s = true in triangle2d_area() returns a signed area – negative for clockwise, positive for counter-clockwise – matching polygon_area().assert is present; degenerate input (collinear vertices, zero sides, angles >= 180 degrees) produces undef, nan, or inf silently.c to round a different vertex.See Wikipedia for more general information.
| function triangle_ppp2sss | ( | c | ) |
Compute the side lengths of a triangle given its vertex coordinates.
| c | <points-3d | points-2d> A list, [v1, v2, v3], the 3d or 2d vertex coordinates. |
Each side length is opposite the corresponding vertex.
Object example
See Wikipedia for more information.
| function triangle_sas2sss | ( | v | ) |
Compute the side lengths of a triangle given two sides and the included angle.
| v | <decimal-list-3> A list, [s1, a3, s2], the side lengths and the included angle. |
Each side length is opposite the corresponding vertex.
Object example
See Wikipedia for more information.
Here is the caller graph for this function:| function triangle_asa2sss | ( | v | ) |
Compute the side lengths of a triangle given a side and two adjacent angles.
| v | <decimal-list-3> A list, [a1, s3, a2], the side length and two adjacent angles. |
Each side length is opposite the corresponding vertex.
Object example
No validation is performed on the input values. If a1 and a2 sum to 180° or more, the derived angle a3 = 180 - a1 - a2 is zero or negative and sin(a3) is zero or negative, causing division by zero or producing negative side lengths without warning.
Here is the caller graph for this function:| function triangle_aas2sss | ( | v | ) |
Compute the side lengths of a triangle given a side, one adjacent and the opposite angle.
| v | <decimal-list-3> A list, [a1, a2, s1], a side length, one adjacent and the opposite angle. |
Each side length is opposite the corresponding vertex.
Object example
No validation is performed on the input values. If a1 and a2 sum to 180° or more, sin(a3) is zero or negative and division by zero or negative side lengths result without warning. If a1 is zero, division by sin(a1) also produces inf or nan.
Here is the caller graph for this function:| function triangle2d_sss2ppp | ( | v | , |
| a | = x_axis_ci, |
||
| cw | = true |
||
| ) |
Compute a set of vertex coordinates for a triangle given its side lengths in 2D.
| v | <decimal-list-3> A list, [s1, s2, s3], the side lengths. |
| a | <integer> The axis alignment index < x_axis_ci | y_axis_ci >. |
| cw | <boolean> Order vertices clockwise. |
cw = true, else [v1, v3, v2].Each side length is opposite the corresponding vertex. The triangle will be constructed with v1 at the origin. Side s2 will be on the 'x' axis or side s3 will be on the 'y' axis as determined by parameter a.
Object example
No verification is performed to ensure that the given sides specify a valid triangle. See Wikipedia for more information.
Here is the caller graph for this function:| function triangle2d_area | ( | c | , |
| s | = false |
||
| ) |
Compute the area of a triangle given its vertex coordinates in 2D.
| c | <points-2d> A list of vertex coordinates [v1, v2, v3]. |
| s | <boolean> When true, return the signed area; when false (default), return the absolute area. |
s = true.When s = true the sign encodes vertex ordering: negative for clockwise and positive for counter-clockwise, following the same convention as polygon_area(). When s = false the absolute value is returned regardless of vertex ordering.
| function triangle_centroid | ( | c | , |
| d | = 2 |
||
| ) |
Compute the centroid of a triangle.
| c | <points-3d | points-2d> A list of 3d or 2d vertex coordinates [v1, v2, v3]. |
| d | <integer> The number of dimensions [2:3]. |
The output dimensionality is controlled by d:
d = 2 (default): returns a 2d point using only the x and y components of each vertex. When 3d coordinates are passed with the default d = 2, the z-component is silently discarded.d = 3: returns a 3d point using x, y, and z components.d = 0: auto-detects dimensionality as the minimum coordinate length across all three vertices, useful for mixed-dimension input.See Wikipedia for more information.
Here is the caller graph for this function:| function triangle2d_incenter | ( | c | ) |
Compute the center coordinate of a triangle's incircle in 2D.
| c | <points-2d> A list of vertex coordinates [v1, v2, v3]. |
The interior point for which distances to the sides of the triangle are equal. See Wikipedia for more information.
Here is the caller graph for this function:| function triangle2d_inradius | ( | c | ) |
Compute the inradius of a triangle's incircle in 2D.
| c | <points-2d> A list of vertex coordinates [v1, v2, v3]. |
See Wikipedia for more information.
| function triangle2d_excenter | ( | c | , |
| vi | = 1 |
||
| ) |
Compute the center coordinate of a triangle's excircle in 2D.
| c | <points-2d> A list of vertex coordinates [v1, v2, v3]. |
| vi | <integer> The vertex index (1, 2, or 3). Returns the excircle center opposite vertex vi. |
A circle outside of the triangle specified by v1, v2, and v3, tangent to the side opposite vertex vi and tangent to the extensions of the other two sides away from vertex vi. Returns origin2d for any vi value other than 1, 2, or 3. See Wikipedia for more information.
| function triangle2d_exradius | ( | c | , |
| vi | = 1 |
||
| ) |
Compute the exradius of a triangle's excircle in 2D.
| c | <points-2d> A list of vertex coordinates [v1, v2, v3]. |
| vi | <integer> The vertex index (1, 2, or 3). Returns the exradius of the excircle opposite vertex vi. |
vi, or 0 for any vi value other than 1, 2, or 3.The exradius opposite vertex vi is computed from the semi-perimeter s and the three side lengths using the formula r_i = sqrt(s * (s-s_j) * (s-s_k) / (s-s_i)), where s_i, s_j, s_k are the sides opposite each vertex in order. See Wikipedia for more information.
| function triangle_circumcenter | ( | c | , |
| d | = 2 |
||
| ) |
Compute the coordinate of a triangle's circumcenter.
| c | <points-3d | points-2d> A list of 3d or 2d vertex coordinates [v1, v2, v3]. |
| d | <integer> The number of dimensions [2:3]. |
The circumcenter is the center of the circumscribed circle — the circle that passes through all three vertices. The circumradius is the distance from the circumcenter to any vertex.
The output dimensionality is controlled by d:
d = 2 (default): returns a 2d point using only the x and y components of each vertex. When 3d coordinates are passed with the default d = 2, the z-component is silently discarded.d = 3: returns a 3d point using x, y, and z components.d = 0: auto-detects dimensionality as the minimum coordinate length across all three vertices, useful for mixed-dimension input.See Wikipedia for more information.
Here is the caller graph for this function:| function triangle2d_is_cw | ( | c | ) |
Test the vertex ordering, or orientation, of a triangle in 2D.
| c | <points-2d> A list of vertex coordinates [v1, v2, v3]. |
| function triangle2d_is_pit | ( | c | , |
| p | |||
| ) |
Test if a point is inside a triangle in 2d.
| c | <points-2d> A list of vertex coordinates [v1, v2, v3]. |
| p | <point-2d> A test point coordinate [x, y]. |
Uses barycentric coordinates to test point inclusion. Points that lie exactly on an edge or vertex of the triangle are considered outside (strict interior test); the boundary is excluded.
Returns undef when the three vertices are collinear (zero-area triangle), matching the convention used by triangle2d_is_cw() and triangle2d_area().
See Wikipedia for more information.
| function triangle2d_vround3_center | ( | c | , |
| r | |||
| ) |
Compute the rounding center coordinate for a given radius of a triangle vertex in 2D.
| c | <points-2d> A list of vertex coordinates [v1, v2, v3]. |
| r | <decimal> The vertex rounding radius. |
Computes the center of the circular arc of radius r that rounds the corner at vertex v2 (c[1]). The arc is tangent to both edges meeting at v2.
r must satisfy 0 < r < ir, where ir is the triangle's inradius (triangle2d_inradius()). Passing r >= ir causes division by zero and is caught by an internal assert.
| function triangle2d_vround3_tangents | ( | c | , |
| r | |||
| ) |
Compute the rounding tangent coordinates for a given radius of a triangle vertex in 2D.
| c | <points-2d> A list of vertex coordinates [v1, v2, v3]. |
| r | <decimal> The vertex rounding radius. |
Computes the two points on the edges adjacent to vertex v2 (c[1]) at which a rounding arc of radius r is tangent. t1 lies on the edge v2 to v1 and t2 lies on the edge v2 to v3.
r must satisfy 0 < r < ir (the triangle's inradius); this constraint is enforced by triangle2d_vround3_center(), which is called internally.