omdl  v0.9.5
OpenSCAD Mechanical Design Library
Triangles

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, v=1)
 Compute the center coordinate of a triangle's excircle in 2D. More...
 
function triangle2d_exradius (c, v=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...
 

Detailed Description

Triangle mathematical functions.

Requires:
include <omdl-base.scad>;

See Wikipedia for more information.

Function Documentation

◆ triangle2d_area()

function triangle2d_area ( ,
= false 
)

Compute the area of a triangle given its vertex coordinates in 2D.

Parameters
c<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.

◆ triangle2d_excenter()

function triangle2d_excenter ( ,
= 1 
)

Compute the center coordinate of a triangle's excircle in 2D.

Parameters
c<coords-2d> A list of vertex coordinates [v1, v2, v3].
v<integer> Return coordinate opposite vertex v.
Returns
<point-2d> The excircle center coordinate [x, y].

A circle outside of the triangle specified by v1, v2, and v3, tangent to the side opposite v and tangent to the extensions of the other two sides away from v. See Wikipedia for more information.

◆ triangle2d_exradius()

function triangle2d_exradius ( ,
= 1 
)

Compute the exradius of a triangle's excircle in 2D.

Parameters
c<coords-2d> A list of vertex coordinates [v1, v2, v3].
v<integer> Return coordinate opposite vertex v.
Returns
<decimal> The excircle radius of the excircle opposite v.

See Wikipedia for more information.

◆ triangle2d_incenter()

function triangle2d_incenter ( )

Compute the center coordinate of a triangle's incircle in 2D.

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

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:

◆ triangle2d_inradius()

function triangle2d_inradius ( )

Compute the inradius of a triangle's incircle in 2D.

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

See Wikipedia for more information.

◆ triangle2d_is_cw()

function triangle2d_is_cw ( )

Test the vertex ordering, or orientation, of a triangle in 2D.

Parameters
c<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.

◆ triangle2d_is_pit()

function triangle2d_is_pit ( ,
 
)

Test if a point is inside a triangle in 2d.

Parameters
c<coords-2d> A list of vertex coordinates [v1, v2, v3].
p<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.

◆ triangle2d_sss2ppp()

function triangle2d_sss2ppp ( ,
= x_axis_ci,
cw  = true 
)

Compute a set of vertex coordinates for a triangle given its side lengths in 2D.

Parameters
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.
Returns
<coords-2d> A list of vertex coordinates [v1, v2, v3], when 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

triangle2d_sss2ppp

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:

◆ triangle2d_vround3_center()

function triangle2d_vround3_center ( ,
 
)

Compute the rounding center coordinate for a given radius of a triangle vertex in 2D.

Parameters
c<coords-2d> A list of vertex coordinates [v1, v2, v3].
r<decimal> The vertex rounding radius.
Returns
<decimal> The rounding center coordinate.

◆ triangle2d_vround3_tangents()

function triangle2d_vround3_tangents ( ,
 
)

Compute the rounding tangent coordinates for a given radius of a triangle vertex in 2D.

Parameters
c<coords-2d> A list of vertex coordinates [v1, v2, v3].
r<decimal> The vertex rounding radius.
Returns
<decimal> The rounding tangent coordinates [t1, t2].

◆ triangle_aas2sss()

function triangle_aas2sss ( )

Compute the side lengths of a triangle given a side, one adjacent and the opposite angle.

Parameters
v<decimal-list-3> A list, [a1, a2, s1], a side length, one adjacent and the opposite angle.
Returns
<decimal-list-3> A list of side lengths [s1, s2, s3].

Each side length is opposite the corresponding vertex.

Object example

triangle_aas2sss

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:

◆ triangle_asa2sss()

function triangle_asa2sss ( )

Compute the side lengths of a triangle given a side and two adjacent angles.

Parameters
v<decimal-list-3> A list, [a1, s3, a2], the side length and two adjacent angles.
Returns
<decimal-list-3> A list of side lengths [s1, s2, s3].

Each side length is opposite the corresponding vertex.

Object example

triangle_asa2sss

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:

◆ triangle_centroid()

function triangle_centroid ( ,
= 2 
)

Compute the centroid of a triangle.

Parameters
c<coords-3d | coords-2d> A list of 3d or 2d vertex coordinates [v1, v2, v3].
d<integer> The number of dimensions [2:3].
Returns
<point-3d | point-2d> The centroid coordinate.

When d is assigned 0, d is set to the minimun number of coordinates of the vertices in c.

See Wikipedia for more information.

+ Here is the caller graph for this function:

◆ triangle_circumcenter()

function triangle_circumcenter ( ,
= 2 
)

Compute the coordinate of a triangle's circumcenter.

Parameters
c<coords-3d | coords-2d> A list of 3d or 2d vertex coordinates [v1, v2, v3].
d<integer> The number of dimensions [2:3].
Returns
<point-3d | point-2d> The circumcenter coordinate.

A circle that passes through all of the vertices of the triangle. The radius is the distance from the circumcenter to any of vertex. When d is assigned 0, d is set to the minimun number of coordinates of the vertices in c. See Wikipedia for more information.

+ Here is the caller graph for this function:

◆ triangle_ppp2sss()

function triangle_ppp2sss ( )

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

Parameters
c<coords-3d | coords-2d> A list, [v1, v2, v3], the 3d or 2d vertex coordinates.
Returns
<decimal-list-3> A list of side lengths [s1, s2, s3].

Each side length is opposite the corresponding vertex.

Object example

triangle_ppp2sss

No verification is performed to ensure that the given sides specify a valid triangle. See Wikipedia for more information.

◆ triangle_sas2sss()

function triangle_sas2sss ( )

Compute the side lengths of a triangle given two sides and the included angle.

Parameters
v<decimal-list-3> A list, [s1, a3, s2], the side lengths and the included angle.
Returns
<decimal-list-3> A list of side lengths [s1, s2, s3].

Each side length is opposite the corresponding vertex.

Object example

triangle_sas2sss

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: