Various functions for creating and working with Triangle3d values. Triangles
are defined by their three vertices and can be constructed by passing a tuple of
vertices to the Triangle3d constructor, for example
exampleTriangle =
Triangle3d
( Point3d ( 1, 0, 0 )
, Point3d ( 2, 0, 0 )
, Point3d ( 2, 1, 3 )
)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 ( Point3d ( 1, 0, 0 ), Point3d ( 2, 0, 0 ) )
e2 ==
LineSegment3d ( Point3d ( 2, 0, 0 ), Point3d ( 2, 1, 3 ) )
e3 ==
LineSegment3d ( Point3d ( 2, 1, 3 ), Point3d ( 1, 0, 0 ) )Get the centroid (center of mass) of a triangle.
Triangle3d.centroid exampleTriangle ==
Point3d ( 1.6667, 0.6667, 1 )Get the area of a triangle. This value is always positive.
Triangle3d.area exampleTriangle ==
1.5811Transforming a triangle is equivalent to transforming its vertices.
Scale a triangle about a given point by a given scale.
Triangle3d.scaleAbout Point3d.origin 2 exampleTriangle ==
Triangle3d
( Point3d ( 2, 0, 0 )
, Point3d ( 4, 0, 0 )
, Point3d ( 4, 2, 6 )
)Rotate a triangle around a given axis by a given angle (in radians).
Triangle3d.rotateAround Axis3d.z (degrees 90) exampleTriangle ==
Triangle3d
( Point3d ( 0, 1, 0 )
, Point3d ( 0, 2, 0 )
, Point3d ( -1, 2, 3 )
)Translate a triangle by a given displacement.
displacement =
Vector3d ( 2, -1, 3 )
Triangle3d.translateBy displacement exampleTriangle ==
Triangle3d
( Point3d ( 3, -1, 3 )
, Point3d ( 4, -1, 3 )
, Point3d ( 4, 0, 6 )
)Mirror a triangle across a given plane.
Triangle3d.mirrorAcross Plane3d.yz exampleTriangle ==
Triangle3d
( Point3d ( -1, 0, 0 )
( Point3d ( -2, 0, 0 )
( Point3d ( -2, 1, 3 )
)Project a triangle onto a given plane.
Triangle3d.projectOnto Plane3d.xy exampleTriangle ==
Triangle3d
( Point3d ( 1, 0, 0 )
, Point3d ( 2, 0, 0 )
, Point3d ( 2, 1, 0 )
)
Triangle3d.projectOnto Plane3d.xz exampleTriangle ==
Triangle3d
( Point3d ( 1, 0, 0 )
, Point3d ( 2, 0, 0 )
, Point3d ( 2, 0, 3 )
)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 map; for example,
Triangle.projectOnto Plane3d.xz exampleTriangle ==
Triangle.map (Point3d.projectOnto Plane3d.xz) exampleTriangleFunctions for transforming triangles between local and global coordinates in different coordinate frames.
Take a triangle defined in global coordinates, and return it expressed in local coordinates relative to a given reference frame.
localFrame =
Frame3d.at (Point3d ( 2, 1, 3 ))
Triangle3d.relativeTo localFrame exampleTriangle ==
Triangle3d
( Point3d ( -1, -1, -3 )
, Point3d ( 0, -1, -3 )
, Point3d ( 0, 0, 0 )
)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.at (Point3d ( 2, 1, 3 ))
Triangle3d.placeIn localFrame exampleTriangle ==
Triangle3d
( Point3d ( 3, 1, 3 )
, Point3d ( 4, 1, 3 )
, Point3d ( 4, 2, 6 )
)Project a triangle into a given sketch plane. Conceptually, this projects the triangle onto the plane and then expresses the projected triangle in 2D sketch coordinates.
Triangle3d.projectInto SketchPlane3d.xy exampleTriangle ==
Triangle2d
( Point2d ( 1, 0 )
, Point2d ( 2, 0 )
, Point2d ( 2, 1 )
)
Triangle3d.projectInto SketchPlane3d.zx exampleTriangle ==
Triangle2d
( Point2d ( 0, 1 )
, Point2d ( 0, 2 )
, Point2d ( 3, 2 )
)Get the minimal bounding box containing a given triangle.
Triangle3d.boundingBox exampleTriangle ==
BoundingBox3d
{ minX = 1
, maxX = 2
, minY = 0
, maxY = 1
, minZ = 0
, maxZ = 3
}
Get the vertices of a triangle.