ianmackenzie / elm-geometry-prerelease / Triangle3d

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


type alias Triangle3d =
Geometry.Types.Triangle3d

Constructors

fromVertices : ( Point3d, Point3d, Point3d ) -> Triangle3d

Construct a triangle from its three vertices:

exampleTriangle =
    Triangle3d.fromVertices
        ( Point3d.fromCoordinates ( 1, 0, 0 )
        , Point3d.fromCoordinates ( 2, 0, 0 )
        , Point3d.fromCoordinates ( 2, 1, 3 )
        )

on : SketchPlane3d -> Triangle2d -> Triangle3d

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.fromVertices
        ( Point2d.fromCoordinates ( 1, 1 )
        , Point2d.fromCoordinates ( 2, 1 )
        , Point2d.fromCoordinates ( 1, 3 )
        )
--> Triangle3d.fromVertices
-->     ( Point3d.fromCoordinates ( 1, 0, 1 )
-->     , Point3d.fromCoordinates ( 2, 0, 1 )
-->     , Point3d.fromCoordinates ( 1, 0, 3 )
-->     )

Properties

vertices : Triangle3d -> ( Point3d, Point3d, Point3d )

Get the vertices of a triangle.

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


--> p1 = Point3d.fromCoordinates ( 1, 0, 0 )
--> p2 = Point3d.fromCoordinates ( 2, 0, 0 )
--> p3 = Point3d.fromCoordinates ( 2, 1, 3 )

edges : Triangle3d -> ( LineSegment3d, LineSegment3d, LineSegment3d )

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.fromEndpoints
-->         ( Point3d.fromCoordinates ( 1, 0, 0 )
-->         , Point3d.fromCoordinates ( 2, 0, 0 )
-->         )
-->
--> e2 =
-->     LineSegment3d.fromEndpoints
-->         ( Point3d.fromCoordinates ( 2, 0, 0 )
-->         , Point3d.fromCoordinates ( 2, 1, 3 )
-->         )
-->
--> e3 =
-->     LineSegment3d.fromEndpoints
-->         ( Point3d.fromCoordinates ( 2, 1, 3 )
-->         , Point3d.fromCoordinates ( 1, 0, 0 )
-->         )

centroid : Triangle3d -> Point3d

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

Triangle3d.centroid exampleTriangle
--> Point3d.fromCoordinates ( 1.6667, 0.6667, 1 )

area : Triangle3d -> Basics.Float

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

Triangle3d.area exampleTriangle
--> 1.5811

normalDirection : Triangle3d -> Maybe Direction3d

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.fromAzimuthAndElevation
-->         (degrees -90)
-->         (degrees 18.43)
-->     )

boundingBox : Triangle3d -> BoundingBox3d

Get the minimal bounding box containing a given triangle.

Triangle3d.boundingBox exampleTriangle
--> BoundingBox3d.fromExtrema
-->     { minX = 1
-->     , maxX = 2
-->     , minY = 0
-->     , maxY = 1
-->     , minZ = 0
-->     , maxZ = 3
-->     }

circumcircle : Triangle3d -> Maybe Circle3d

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

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

Circle3d.throughPoints p1 p2 p3

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

Transformations

Transforming a triangle is equivalent to transforming its vertices.

scaleAbout : Point3d -> Basics.Float -> Triangle3d -> Triangle3d

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

Triangle3d.scaleAbout Point3d.origin 2 exampleTriangle
--> Triangle3d.fromVertices
-->     ( Point3d.fromCoordinates ( 2, 0, 0 )
-->     , Point3d.fromCoordinates ( 4, 0, 0 )
-->     , Point3d.fromCoordinates ( 4, 2, 6 )
-->     )

rotateAround : Axis3d -> Basics.Float -> Triangle3d -> Triangle3d

Rotate a triangle around a given axis by a given angle (in radians).

exampleTriangle
    |> Triangle3d.rotateAround Axis3d.z (degrees 90)
--> Triangle3d.fromVertices
-->     ( Point3d.fromCoordinates ( 0, 1, 0 )
-->     , Point3d.fromCoordinates ( 0, 2, 0 )
-->     , Point3d.fromCoordinates ( -1, 2, 3 )
-->     )

translateBy : Vector3d -> Triangle3d -> Triangle3d

Translate a triangle by a given displacement.

displacement =
    Vector3d.fromComponents ( 2, -1, 3 )

Triangle3d.translateBy displacement exampleTriangle
--> Triangle3d.fromVertices
-->     ( Point3d.fromCoordinates ( 3, -1, 3 )
-->     , Point3d.fromCoordinates ( 4, -1, 3 )
-->     , Point3d.fromCoordinates ( 4, 0, 6 )
-->     )

translateIn : Direction3d -> Basics.Float -> Triangle3d -> Triangle3d

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

Triangle3d.translateIn direction distance

is equivalent to

Triangle3d.translateBy
    (Vector3d.withLength distance direction)

mirrorAcross : Plane3d -> Triangle3d -> Triangle3d

Mirror a triangle across a given plane.

Triangle3d.mirrorAcross Plane3d.yz exampleTriangle
--> Triangle3d.fromVertices
-->     ( Point3d.fromCoordinates ( -1, 0, 0 )
-->     ( Point3d.fromCoordinates ( -2, 0, 0 )
-->     ( Point3d.fromCoordinates ( -2, 1, 3 )
-->     )

projectOnto : Plane3d -> Triangle3d -> Triangle3d

Find the orthographic projection of a triangle onto a plane.

Triangle3d.projectOnto Plane3d.xy exampleTriangle
--> Triangle3d.fromVertices
-->     ( Point3d.fromCoordinates ( 1, 0, 0 )
-->     , Point3d.fromCoordinates ( 2, 0, 0 )
-->     , Point3d.fromCoordinates ( 2, 1, 0 )
-->     )

Triangle3d.projectOnto Plane3d.xz exampleTriangle
--> Triangle3d.fromVertices
-->     ( Point3d.fromCoordinates ( 1, 0, 0 )
-->     , Point3d.fromCoordinates ( 2, 0, 0 )
-->     , Point3d.fromCoordinates ( 2, 0, 3 )
-->     )

mapVertices : (Point3d -> Point3d) -> Triangle3d -> Triangle3d

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

relativeTo : Frame3d -> Triangle3d -> Triangle3d

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

localFrame =
    Frame3d.atPoint
        (Point3d.fromCoordinates ( 2, 1, 3 ))

Triangle3d.relativeTo localFrame exampleTriangle
--> Triangle3d.fromVertices
-->     ( Point3d.fromCoordinates ( -1, -1, -3 )
-->     , Point3d.fromCoordinates ( 0, -1, -3 )
-->     , Point3d.fromCoordinates ( 0, 0, 0 )
-->     )

placeIn : Frame3d -> Triangle3d -> Triangle3d

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

localFrame =
    Frame3d.atPoint
        (Point3d.fromCoordinates ( 2, 1, 3 ))

Triangle3d.placeIn localFrame exampleTriangle
--> Triangle3d.fromVertices
-->     ( Point3d.fromCoordinates ( 3, 1, 3 )
-->     , Point3d.fromCoordinates ( 4, 1, 3 )
-->     , Point3d.fromCoordinates ( 4, 2, 6 )
-->     )

projectInto : SketchPlane3d -> Triangle3d -> Triangle2d

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.

Triangle3d.projectInto SketchPlane3d.xy exampleTriangle
--> Triangle2d.fromVertices
-->     ( Point2d.fromCoordinates ( 1, 0 )
-->     , Point2d.fromCoordinates ( 2, 0 )
-->     , Point2d.fromCoordinates ( 2, 1 )
-->     )

Triangle3d.projectInto SketchPlane3d.zx exampleTriangle
--> Triangle2d.fromVertices
-->     ( Point2d.fromCoordinates ( 0, 1 )
-->     , Point2d.fromCoordinates ( 0, 2 )
-->     , Point2d.fromCoordinates ( 3, 2 )
-->     )