omdl  v0.6.1
OpenSCAD Mechanical Design Library
Triangles

Triangle mathematical functions. More...

+ Collaboration diagram for Triangles:

Files

file  math_triangle.scad
 Triangle solutions mathematical functions.
 

Functions

function triangle_sss2lp (s1, s2, s3, cw=true)
 Compute the vertex coordinates of a triangle given its side lengths. More...
 
function triangle_ls2lp (v, cw=true)
 Compute the vertex coordinates of a triangle given its side lengths. More...
 
function triangle_ppp2ls (v1, v2, v3)
 Compute the side lengths of a triangle given its vertex coordinates. More...
 
function triangle_lp2ls (v)
 Compute the side lengths of a triangle given its vertex coordinates. More...
 
function triangle_area_ppp (v1, v2, v3, s=false)
 Compute the signed area of a triangle given its vertex coordinates. More...
 
function triangle_area_lp (v, s=false)
 Compute the signed area of a triangle given its vertex coordinates. More...
 
function triangle_centroid_ppp (v1, v2, v3)
 Compute the centroid (geometric center) of a triangle. More...
 
function triangle_centroid_lp (v)
 Compute the centroid (geometric center) of a triangle. More...
 
function triangle_incenter_ppp (v1, v2, v3)
 Compute the coordinate for the triangle's incircle. More...
 
function triangle_incenter_lp (v)
 Compute the coordinate for the triangle's incircle. More...
 
function triangle_inradius_ppp (v1, v2, v3)
 Compute the inradius of a triangle's incircle. More...
 
function triangle_inradius_lp (v)
 Compute the inradius of a triangle's incircle. More...
 
function triangle_is_cw_ppp (v1, v2, v3)
 Test the vertex ordering, or orientation, of a triangle. More...
 
function triangle_is_cw_lp (v)
 Test the vertex ordering, or orientation, of a triangle. More...
 
function triangle_is_pit_ppp (v1, v2, v3, t)
 Test if a point is inside a triangle in a Euclidean 2d-space using Barycentric. More...
 
function triangle_is_pit_lp (v, t)
 Test if a point is inside a triangle in a Euclidean 2d-space using Barycentric. More...
 

Detailed Description

Triangle mathematical functions.

See Wikipedia for more information.

Function Documentation

function triangle_area_lp ( ,
= false 
)

Compute the signed area of a triangle given its vertex coordinates.

Parameters
v<coords-2d> A list of vertex coordinates [v1, v2, v3].
s<boolean> Return the vertex ordering sign.
Returns
<decimal> The area of the given triangle.
function triangle_area_ppp ( v1  ,
v2  ,
v3  ,
= false 
)

Compute the signed area of a triangle given its vertex coordinates.

Parameters
v1<point-2d> A vertex coordinate [x, y] for vertex 1.
v2<point-2d> A vertex coordinate [x, y] for vertex 2.
v3<point-2d> A vertex coordinate [x, y] for vertex 3.
s<boolean> Return the vertex ordering sign.
Returns
<decimal> The area of the given triangle.
function triangle_centroid_lp ( )

Compute the centroid (geometric center) of a triangle.

Parameters
v<coords-2d> A list of vertex coordinates [v1, v2, v3].
Returns
<point-2d> The centroid coordinate point [x, y].

+ Here is the caller graph for this function:

function triangle_centroid_ppp ( v1  ,
v2  ,
v3   
)

Compute the centroid (geometric center) of a triangle.

Parameters
v1<point-2d> A vertex coordinate [x, y] for vertex 1.
v2<point-2d> A vertex coordinate [x, y] for vertex 2.
v3<point-2d> A vertex coordinate [x, y] for vertex 3.
Returns
<point-2d> The centroid coordinate point [x, y].

+ Here is the caller graph for this function:

function triangle_incenter_lp ( )

Compute the coordinate for the triangle's incircle.

Parameters
v<coords-2d> A list of vertex coordinates [v1, v2, v3].
Returns
<point-2d> The incircle coordinate point [x, y].

The interior point for which distances to the sides of the triangle are equal.

+ Here is the caller graph for this function:

function triangle_incenter_ppp ( v1  ,
v2  ,
v3   
)

Compute the coordinate for the triangle's incircle.

Parameters
v1<point-2d> A vertex coordinate [x, y] for vertex 1.
v2<point-2d> A vertex coordinate [x, y] for vertex 2.
v3<point-2d> A vertex coordinate [x, y] for vertex 3.
Returns
<point-2d> The incircle coordinate point [x, y].

The interior point for which distances to the sides of the triangle are equal.

+ Here is the caller graph for this function:

function triangle_inradius_lp ( )

Compute the inradius of a triangle's incircle.

Parameters
v<coords-2d> A list of vertex coordinates [v1, v2, v3].
Returns
<decimal> The incircle radius.
function triangle_inradius_ppp ( v1  ,
v2  ,
v3   
)

Compute the inradius of a triangle's incircle.

Parameters
v1<point-2d> A vertex coordinate [x, y] for vertex 1.
v2<point-2d> A vertex coordinate [x, y] for vertex 2.
v3<point-2d> A vertex coordinate [x, y] for vertex 3.
Returns
<decimal> The incircle radius.
function triangle_is_cw_lp ( )

Test the vertex ordering, or orientation, of a triangle.

Parameters
v<coords-2d> A list of vertex coordinates [v1, v2, v3].
Returns
<boolean> true if the vertices are ordered clockwise, false if the vertices are ordered counterclockwise, and undef if the ordering can not be determined.
function triangle_is_cw_ppp ( v1  ,
v2  ,
v3   
)

Test the vertex ordering, or orientation, of a triangle.

Parameters
v1<point-2d> A vertex coordinate [x, y] for vertex 1.
v2<point-2d> A vertex coordinate [x, y] for vertex 2.
v3<point-2d> A vertex coordinate [x, y] for vertex 3.
Returns
<boolean> true if the vertices are ordered clockwise, false if the vertices are ordered counterclockwise, and undef if the ordering can not be determined.
function triangle_is_pit_lp ( ,
 
)

Test if a point is inside a triangle in a Euclidean 2d-space using Barycentric.

Parameters
v<coords-2d> A list of vertex coordinates [v1, v2, v3].
t<point-2d> A test point coordinate [x, y].
Returns
<boolean> true when the point is inside the polygon and false otherwise.
function triangle_is_pit_ppp ( v1  ,
v2  ,
v3  ,
 
)

Test if a point is inside a triangle in a Euclidean 2d-space using Barycentric.

Parameters
v1<point-2d> A vertex coordinate [x, y] for vertex 1.
v2<point-2d> A vertex coordinate [x, y] for vertex 2.
v3<point-2d> A vertex coordinate [x, y] for vertex 3.
t<point-2d> A test point coordinate [x, y].
Returns
<boolean> true when the point is inside the polygon and false otherwise.

See Wikipedia for more information.

function triangle_lp2ls ( )

Compute the side lengths of a triangle given its vertex coordinates.

Parameters
v<coords-2d> A list of vertex coordinates [v1, v2, v3].
Returns
<decimal-list-3> A list of side lengths [s1, s2, s3].
Note
Side lengths ordered according to vertex ordering.
function triangle_ls2lp ( ,
cw  = true 
)

Compute the vertex coordinates of a triangle given its side lengths.

Parameters
v<decimal-list-3> The list of side lengths [s1, s2, s3].
cw<boolean> Order vertices clockwise.
Returns
<coords-2d> A list of vertex coordinates [v1, v2, v3].

Geometry requires that s1 + s2 is greater then s3. A coordinates will be 'nan' when specified triangle does not exists.

Note
Vertex v1 at the origin. Side length s1 is measured along the positive x-axis.
function triangle_ppp2ls ( v1  ,
v2  ,
v3   
)

Compute the side lengths of a triangle given its vertex coordinates.

Parameters
v1<point-2d> A vertex coordinate [x, y] for vertex 1.
v2<point-2d> A vertex coordinate [x, y] for vertex 2.
v3<point-2d> A vertex coordinate [x, y] for vertex 3.
Returns
<decimal-list-3> A list of side lengths [s1, s2, s3].
Note
Side lengths ordered according to vertex ordering.
function triangle_sss2lp ( s1  ,
s2  ,
s3  ,
cw  = true 
)

Compute the vertex coordinates of a triangle given its side lengths.

Parameters
s1<decimal> The length of the side 1.
s2<decimal> The length of the side 2.
s3<decimal> The length of the side 3.
cw<boolean> Order vertices clockwise.
Returns
<coords-2d> A list of vertex coordinates [v1, v2, v3].

Geometry requires that s1 + s2 is greater then s3. A coordinates will be 'nan' when specified triangle does not exists.

Note
Vertex v1 at the origin. Side length s1 is measured along the positive x-axis.

+ Here is the caller graph for this function: