ianmackenzie/elm-geometry/2.0.0

NOTE: the latest version is 4.0.0

Triangle3d

A Triangle3d represents a triangle in 3D space, and is defined by its three vertices. This module contains triangle-related functionality such as:

  • Finding the area and centroid of triangles
  • Scaling, rotating, translating, mirroring and projecting triangles
  • Converting triangles between different coordinate systems
type alias Triangle3d units coordinates =
Triangle3d units coordinates

Constructors

( Point3d units coordinates
, Point3d units coordinates
, Point3d units coordinates
)
-> Triangle3d units coordinates

Construct a triangle from its three vertices:

exampleTriangle =
    Triangle3d.fromVertices
        ( Point3d.meters 1 0 0
        , Point3d.meters 2 0 0
        , Point3d.meters 2 1 3
        )
Point3d units coordinates
-> Point3d units coordinates
-> Point3d units coordinates
-> Triangle3d units coordinates

Construct a triangle from the first point, to the second, to the third:

exampleTriangle =
    Triangle3d.from
        (Point3d.meters 1 0 0)
        (Point3d.meters 2 0 0)
        (Point3d.meters 2 1 3)

Useful with map3 functions such as Json.Decode.map3.

on :
SketchPlane3d units coordinates3d { defines : coordinates2d }
-> Triangle2d units coordinates2d
-> Triangle3d units coordinates3d

Construct a 3D triangle lying on a sketch plane by providing a 2D triangle specified in XY coordinates within the sketch plane.

Triangle3d.on SketchPlane3d.xz <|
    Triangle2d.from
        (Point2d.meters 1 1)
        (Point2d.meters 2 1)
        (Point2d.meters 1 3)
--> Triangle3d.from
-->     (Point3d.meters 1 0 1)
-->     (Point3d.meters 2 0 1)
-->     (Point3d.meters 1 0 3)

Properties

Triangle3d units coordinates
-> ( Point3d units coordinates
, Point3d units coordinates
, Point3d units coordinates
)

Get the vertices of a triangle.

( p1, p2, p3 ) =
    Triangle3d.vertices exampleTriangle


--> p1 = Point3d.meters 1 0 0
--> p2 = Point3d.meters 2 0 0
--> p3 = Point3d.meters 2 1 3
Triangle3d units coordinates
-> ( LineSegment3d units coordinates
, LineSegment3d units coordinates
, LineSegment3d units coordinates
)

Get the edges of a triangle: from the first vertex to the second, from the second to the third, and from the third back to the first.

( e1, e2, e3 ) =
    Triangle3d.edges exampleTriangle


--> e1 =
-->     LineSegment3d.from
-->         (Point3d.meters 1 0 0)
-->         (Point3d.meters 2 0 0)
-->
--> e2 =
-->     LineSegment3d.from
-->         (Point3d.meters 2 0 0)
-->         (Point3d.meters 2 1 3)
-->
--> e3 =
-->     LineSegment3d.from
-->         (Point3d.meters 2 1 3)
-->         (Point3d.meters 1 0 0)
centroid : Triangle3d units coordinates -> Point3d units coordinates

Get the centroid (center of mass) of a triangle.

Triangle3d.centroid exampleTriangle
--> Point3d.meters 1.6667 0.6667 1
area : Triangle3d units coordinates -> Quantity Float (Squared units)

Get the area of a triangle. This value is always positive.

Triangle3d.area exampleTriangle
--> Area.squareMeters 1.5811
normalDirection : Triangle3d units coordinates -> Maybe (Direction3d coordinates)

Attempt to find the normal direction to a triangle. The resulting direction will be oriented such that the triangle vertices are in counterclockwise order around it according to the right-hand rule. If the triangle is degenerate (its three vertices are collinear), returns Nothing.

Triangle3d.normalDirection exampleTriangle
--> Just (Direction3d.yz (Angle.degrees 161.57))
boundingBox : Triangle3d units coordinates -> BoundingBox3d units coordinates

Get the minimal bounding box containing a given triangle.

Triangle3d.boundingBox exampleTriangle
--> BoundingBox3d.fromExtrema
-->     { minX = Length.meters 1
-->     , maxX = Length.meters 2
-->     , minY = Length.meters 0
-->     , maxY = Length.meters 1
-->     , minZ = Length.meters 0
-->     , maxZ = Length.meters 3
-->     }
Triangle3d units coordinates
-> Maybe (Circle3d units coordinates)

Attempt to find the circumcircle of a triangle, a circle that passes through each of the triangle's vertices;

Triangle3d.circumcircle triangle

is equivalent to

let
    ( p1, p2, p3 ) =
        Triangle3d.vertices triangle
in
Circle3d.throughPoints p1 p2 p3

If the triangle is degenerate (its three vertices are collinear), returns Nothing.

Unit conversions

at :
Quantity Float (Rate units2 units1)
-> Triangle3d units1 coordinates
-> Triangle3d units2 coordinates

Convert a triangle from one units type to another, by providing a conversion factor given as a rate of change of destination units with respect to source units.

at_ :
Quantity Float (Rate units1 units2)
-> Triangle3d units1 coordinates
-> Triangle3d units2 coordinates

Convert a triangle from one units type to another, by providing an 'inverse' conversion factor given as a rate of change of source units with respect to destination units.

Transformations

These transformations generally behave just like the ones in the Point3d module.

Point3d units coordinates
-> Float
-> Triangle3d units coordinates
-> Triangle3d units coordinates

Scale a triangle about a given point by a given scale.

Axis3d units coordinates
-> Angle
-> Triangle3d units coordinates
-> Triangle3d units coordinates

Rotate a triangle around a given axis by a given angle.

Vector3d units coordinates
-> Triangle3d units coordinates
-> Triangle3d units coordinates

Translate a triangle by a given displacement.

Direction3d coordinates
-> Quantity Float units
-> Triangle3d units coordinates
-> Triangle3d units coordinates

Translate a triangle in a given direction by a given distance.

Plane3d units coordinates
-> Triangle3d units coordinates
-> Triangle3d units coordinates

Mirror a triangle across a given plane.

Plane3d units coordinates
-> Triangle3d units coordinates
-> Triangle3d units coordinates

Find the orthographic projection of a triangle onto a plane.

(Point3d units1 coordinates1 -> Point3d units2 coordinates2)
-> Triangle3d units1 coordinates1
-> Triangle3d units2 coordinates2

Transform each vertex of a triangle by a given function and create a new triangle from the resulting points. Most other transformation functions can be defined in terms of mapVertices; for example,

Triangle3d.projectOnto plane

is equivalent to

Triangle3d.mapVertices (Point3d.projectOnto plane)

Coordinate conversions

Frame3d units globalCoordinates { defines : localCoordinates }
-> Triangle3d units globalCoordinates
-> Triangle3d units localCoordinates

Take a triangle defined in global coordinates, and return it expressed in local coordinates relative to a given reference frame.

Frame3d units globalCoordinates { defines : localCoordinates }
-> Triangle3d units localCoordinates
-> Triangle3d units globalCoordinates

Take a triangle considered to be defined in local coordinates relative to a given reference frame, and return that triangle expressed in global coordinates.

SketchPlane3d units coordinates3d { defines : coordinates2d }
-> Triangle3d units coordinates3d
-> Triangle2d units coordinates2d

Project a triangle into a given sketch plane. Conceptually, this finds the orthographic projection of the triangle onto the plane and then expresses the projected triangle in 2D sketch coordinates.