opensolid/geometry/1.0.0

NOTE: this package is not compatible with Elm 0.19.1

OpenSolid.Polyline3d

Polyline3d

Various functions for creating and working with Polyline3d values. Polylines can be constructed by passing an ordered list of vertices to the Polyline3d constructor, for example

examplePolyline =
    Polyline3d
        [ Point2d ( 0, 0, 0 )
        , Point2d ( 1, 0, 0 )
        , Point2d ( 1, 2, 0 )
        , Point2d ( 1, 2, 3 )
        ]

Accessors

vertices : Polyline3d -> List Point3d

Get the vertices of a polyline.

Polyline3d.vertices examplePolyline ==
    [ Point3d ( 0, 0, 0 )
    , Point3d ( 1, 0, 0 )
    , Point3d ( 1, 2, 0 )
    , Point3d ( 1, 2, 3 )
    ]
segments : Polyline3d -> List LineSegment3d

Get the individual segments of a polyline.

Polyline3d.segments examplePolyline ==
    [ LineSegment3d ( Point3d ( 0, 0, 0 ), Point3d ( 1, 0, 0 ) )
    , LineSegment3d ( Point3d ( 1, 0, 0 ), Point3d ( 1, 2, 0 ) )
    , LineSegment3d ( Point3d ( 1, 2, 0 ), Point3d ( 1, 2, 3 ) )
    ]

Length

length : Polyline3d -> Float

Get the overall length of a polyline (the sum of the lengths of its segments).

Polyline3d.length examplePolyline ==
    6

Transformations

Transforming a polyline is equivalent to transforming each of its vertices.

scaleAbout : Point3d -> Float -> Polyline3d -> Polyline3d

Scale a polyline about the given center point by the given scale.

point =
    Point3d ( 1, 0, 0 )


Polyline3d.scaleAbout point 2 examplePolyline ==
    Polyline3d
        [ Point3d ( -1, 0, 0 )
        , Point3d ( 1, 0, 0 )
        , Point3d ( 1, 4, 0 )
        , Point3d ( 1, 4, 6 )
        ]
rotateAround : Axis3d -> Float -> Polyline3d -> Polyline3d

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

Polyline3d.rotateAround Axis3d.z (degrees 90) examplePolyline ==
    Polyline3d
        [ Point3d ( 0, 0, 0 )
        , Point3d ( 0, 1, 0 )
        , Point3d ( -2, 1, 0 )
        , Point3d ( -2, 1, 3 )
        ]
translateBy : Vector3d -> Polyline3d -> Polyline3d

Translate a polyline by the given displacement.

displacement =
    Vector3d ( 1, 2, 3 )


Polyline3d.translateBy displacement examplePolyline ==
    Polyline3d
        [ Point3d ( 1, 2, 3 )
        , Point3d ( 2, 2, 3 )
        , Point3d ( 2, 4, 3 )
        , Point3d ( 2, 4, 6 )
        ]
mirrorAcross : Plane3d -> Polyline3d -> Polyline3d

Mirror a polyline across the given plane.

Polyline3d.mirrorAcross Plane3d.xz examplePolyline ==
    Polyline3d
        [ Point3d ( 0, 0, 0 )
        , Point3d ( 1, 0, 0 )
        , Point3d ( 1, -2, 0 )
        , Point3d ( 1, -2, 3 )
        ]
projectOnto : Plane3d -> Polyline3d -> Polyline3d

Project (flatten) a polyline onto the given plane.

Polyline3d.projectOnto Plane3d.xz examplePolyline ==
    Polyline3d
        [ Point3d ( 0, 0, 0 )
        , Point3d ( 1, 0, 0 )
        , Point3d ( 1, 0, 0 )
        , Point3d ( 1, 0, 3 )
        ]
map : (Point3d -> Point3d) -> Polyline3d -> Polyline3d

Transform each vertex of a polyline by the given function. All other transformations can be defined in terms of map, for example

Polyline3d.mirrorAcross Plane3d.xz examplePolyline ==
    Polyline3d.map (Point3d.mirrorAcross Plane3d.xz) examplePolyline

Coordinate frames

relativeTo : Frame3d -> Polyline3d -> Polyline3d

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

localFrame =
    Frame3d.at (Point3d ( 1, 2, 3 ))


Polyline3d.relativeTo localFrame examplePolyline ==
    Polyline3d
        [ Point3d ( -1, -2, -3 )
        , Point3d ( 0, -2, -3 )
        , Point3d ( 0, 0, -3 )
        , Point3d ( 0, 0, 0 )
        ]
placeIn : Frame3d -> Polyline3d -> Polyline3d

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

localFrame =
    Frame3d.at (Point3d ( 1, 2, 3 ))


Polyline3d.placeIn localFrame examplePolyline ==
    Polyline3d
        [ Point3d ( 1, 2, 3 )
        , Point3d ( 2, 2, 3 )
        , Point3d ( 2, 4, 3 )
        , Point3d ( 2, 4, 6 )
        ]

Sketch planes

projectInto : SketchPlane3d -> Polyline3d -> Polyline2d

Project a polyline into a given sketch plane. Conceptually, this projects the polyline onto the plane and then expresses the projected polyline in 2D sketch coordinates.

Polyline3d.projectInto Plane3d.xy examplePolyline ==
    Polyline2d
        [ Point2d ( 0, 0 )
        , Point2d ( 1, 0 )
        , Point2d ( 1, 2 )
        , Point2d ( 1, 2 )
        ]

Bounds

boundingBox : Polyline3d -> Maybe BoundingBox3d

Get the minimal bounding box containing a given polyline. Returns Nothing if the polyline has no vertices.

Polyline3d.boundingBox examplePolyline ==
    Just
        (BoundingBox3d
            { minX = 0
            , maxX = 1
            , minY = 0
            , maxY = 2
            , minZ = 0
            , maxZ = 3
            }
        )