A CubicSpline2d is a cubic Bézier curve
in 2D defined by four control points. This module contains functionality for
Splines can be constructed by passing a tuple of control points to the
CubicSpline2d constructor, for example
exampleSpline =
CubicSpline2d
( Point2d ( 1, 1 )
, Point2d ( 3, 4 )
, Point2d ( 5, 1 )
, Point2d ( 7, 4 )
)Construct a spline in Hermite form, from the position and derivative values at its start and end points, like so:
The spline is based on a parameter that ranges from 0 to 1; as a result, in most cases the length of each derivative vector should be roughly equal to the length of the resulting spline.
Get the control points of a spline as a tuple.
( p1, p2, p3, p4 ) =
CubicSpline2d.controlPoints exampleSpline
--> p1 = Point2d ( 1, 1 )
--> p2 = Point2d ( 3, 4 )
--> p3 = Point2d ( 5, 1 )
--> p4 = Point2d ( 7, 4 )Get the start point of a spline. This is equal to the spline's first control point.
CubicSpline2d.startPoint exampleSpline
--> Point2d ( 1, 1 )Get the end point of a spline. This is equal to the spline's last control point.
CubicSpline2d.endPoint exampleSpline
--> Point2d ( 7, 4 )Get the start derivative of a spline. This is equal to three times the vector from the spline's first control point to its second.
CubicSpline2d.startDerivative exampleSpline
--> Vector2d ( 6, 9 )Get the end derivative of a spline. This is equal to three times the vector from the spline's third control point to its fourth.
CubicSpline2d.endDerivative exampleSpline
--> Vector2d ( 6, 9 )Get a point along a spline, based on a parameter that ranges from 0 to 1. A parameter value of 0 corresponds to the start point of the spline and a value of 1 corresponds to the end point.
CubicSpline2d.point exampleSpline 0
--> Point2d ( 1, 1 )
CubicSpline2d.point exampleSpline 0.5
--> Point2d ( 4, 2.5 )
CubicSpline2d.point exampleSpline 1
--> Point2d ( 7, 4 )Get the deriative value at a point along a spline, based on a parameter that ranges from 0 to 1. A parameter value of 0 corresponds to the start derivative of the spline and a value of 1 corresponds to the end derivative.
CubicSpline2d.derivative exampleSpline 0
--> Vector2d ( 6, 9 )
CubicSpline2d.derivative exampleSpline 0.5
--> Vector2d ( 6, 0 )
CubicSpline2d.derivative exampleSpline 1
--> Vector2d ( 6, 9 )Scale a spline about the given center point by the given scale.
CubicSpline2d.scaleAbout Point2d.origin 2 exampleSpline
--> CubicSpline2d
--> ( Point2d ( 2, 2 )
--> , Point2d ( 6, 8 )
--> , Point2d ( 10, 2 )
--> , Point2d ( 14, 8 )
--> )Rotate a spline counterclockwise around a given center point by a given angle (in radians).
CubicSpline2d.rotateAround Point2d.origin (degrees 90) exampleSpline
--> CubicSpline2d
--> ( Point2d ( -1, 1 )
--> , Point2d ( -4, 3 )
--> , Point2d ( -1, 5 )
--> , Point2d ( -4, 7 )
--> )Translate a spline by a given displacement.
displacement =
Vector2d ( 2, 3 )
CubicSpline2d.translateBy displacement exampleSpline
--> CubicSpline2d
--> ( Point2d ( 3, 4 )
--> , Point2d ( 5, 7 )
--> , Point2d ( 7, 4 )
--> , Point2d ( 9, 7 )
--> )Mirror a spline across an axis.
CubicSpline2d.mirrorAcross Axis2d.x exampleSpline
--> CubicSpline2d
--> ( Point2d ( 1, -1 )
--> , Point2d ( 3, -4 )
--> , Point2d ( 5, -1 )
--> , Point2d ( 7, -4 )
--> )Take a spline defined in global coordinates, and return it expressed in local coordinates relative to a given reference frame.
localFrame =
Frame2d.at (Point2d ( 1, 2 ))
CubicSpline2d.relativeTo localFrame exampleSpline
--> CubicSpline2d
--> ( Point2d ( 0, -1 )
--> , Point2d ( 2, 2 )
--> , Point2d ( 4, -1 )
--> , Point2d ( 6, 2 )
--> )Take a spline considered to be defined in local coordinates relative to a given reference frame, and return that spline expressed in global coordinates.
localFrame =
Frame2d.at (Point2d ( 1, 2 ))
CubicSpline2d.placeIn localFrame exampleSpline
--> CubicSpline2d
--> ( Point2d ( 2, 3 )
--> , Point2d ( 4, 6 )
--> , Point2d ( 6, 3 )
--> , Point2d ( 8, 6 )
--> )Take a spline defined in 2D coordinates within a particular sketch plane and return the corresponding spline in 3D.
CubicSpline2d.placeOnto SketchPlane3d.xz exampleSpline
--> CubicSpline3d
--> ( Point3d ( 1, 0, 1 )
--> , Point3d ( 3, 0, 4 )
--> , Point3d ( 5, 0, 1 )
--> , Point3d ( 7, 0, 4 )
--> )
Construct a spline from its four control points. This is the same as just using the
CubicSpline2dconstructor directly;is equivalent to