A CubicSpline3d is a cubic Bézier curve
in 3D defined by four control points. This module contains functionality for
Splines can be constructed by passing a tuple of control points to the
CubicSpline3d constructor, for example
exampleSpline =
CubicSpline3d
( Point3d ( 1, 1, 1 )
, Point3d ( 3, 1, 1 )
, Point3d ( 3, 3, 1 )
, Point3d ( 3, 3, 3 )
)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 ) =
CubicSpline3d.controlPoints exampleSpline
--> p1 = Point3d ( 1, 1, 1 )
--> p2 = Point3d ( 3, 1, 1 )
--> p3 = Point3d ( 3, 3, 1 )
--> p4 = Point3d ( 3, 3, 3 )Get the start point of a spline. This is equal to the spline's first control point.
CubicSpline3d.startPoint exampleSpline
--> Point3d ( 1, 1, 1 )Get the end point of a spline. This is equal to the spline's last control point.
CubicSpline3d.endPoint exampleSpline
--> Point3d ( 3, 3, 3 )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.
CubicSpline3d.startDerivative exampleSpline
--> Vector3d ( 6, 0, 0 )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.
CubicSpline3d.endDerivative exampleSpline
--> Vector3d ( 0, 0, 6 )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.
CubicSpline3d.point exampleSpline 0
--> Point3d ( 1, 1, 1 )
CubicSpline3d.point exampleSpline 0.5
--> Point3d ( 2.75, 2, 1.25 )
CubicSpline3d.point exampleSpline 1
--> Point3d ( 3, 3, 3 )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.
CubicSpline3d.derivative exampleSpline 0
--> Vector3d ( 6, 0, 0 )
CubicSpline3d.derivative exampleSpline 0.5
--> Vector3d ( 1.5, 3, 1.5 )
CubicSpline3d.derivative exampleSpline 1
--> Vector3d ( 0, 0, 6 )Note that the derivative interpolates linearly from end to end.
Scale a spline about the given center point by the given scale.
CubicSpline3d.scaleAbout Point3d.origin 2 exampleSpline
--> CubicSpline3d
--> ( Point3d ( 2, 2, 2 )
--> , Point3d ( 6, 2, 2 )
--> , Point3d ( 6, 6, 2 )
--> , Point3d ( 6, 6, 6 )
--> )Rotate a spline counterclockwise around a given axis by a given angle (in radians).
CubicSpline3d.rotateAround Axis3d.z (degrees 90) exampleSpline
--> CubicSpline3d
--> ( Point3d ( -1, 1, 1 )
--> , Point3d ( -1, 3, 1 )
--> , Point3d ( -3, 3, 1 )
--> , Point3d ( -3, 3, 3 )
--> )Translate a spline by a given displacement.
displacement =
Vector3d ( 2, 3, 1 )
CubicSpline3d.translateBy displacement exampleSpline
--> CubicSpline3d
--> ( Point3d ( 3, 4, 2 )
--> , Point3d ( 5, 4, 2 )
--> , Point3d ( 5, 6, 2 )
--> , Point3d ( 5, 6, 4 )
--> )Mirror a spline across a plane.
CubicSpline3d.mirrorAcross Plane3d.xy exampleSpline
--> CubicSpline3d
--> ( Point3d ( 1, 1, -1 )
--> , Point3d ( 3, 1, -1 )
--> , Point3d ( 3, 3, -1 )
--> , Point3d ( 3, 3, -3 )
--> )Project a spline onto a plane.
CubicSpline3d.projectOnto Plane3d.xy exampleSpline
--> CubicSpline3d
--> ( Point3d ( 1, 1, 0 )
--> , Point3d ( 3, 1, 0 )
--> , Point3d ( 3, 3, 0 )
--> , Point3d ( 3, 3, 0 )
--> )Take a spline defined in global coordinates, and return it expressed in local coordinates relative to a given reference frame.
localFrame =
Frame3d.at (Point3d ( 1, 2, 3 ))
CubicSpline3d.relativeTo localFrame exampleSpline
--> CubicSpline3d
--> ( Point3d ( 0, -1, -2 )
--> , Point3d ( 2, -1, -2 )
--> , Point3d ( 2, 1, -2 )
--> , Point3d ( 2, 1, 0 )
--> )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 =
Frame3d.at (Point3d ( 1, 2, 3 ))
CubicSpline3d.placeIn localFrame exampleSpline
--> CubicSpline3d
--> ( Point3d ( 2, 3, 4 )
--> , Point3d ( 4, 3, 4 )
--> , Point3d ( 4, 5, 4 )
--> , Point3d ( 4, 5, 6 )
--> )Project a spline into a given sketch plane. Conceptually, this projects the spline onto the plane and then expresses the projected spline in 2D sketch coordinates.
CubicSpline3d.projectInto SketchPlane3d.yz exampleSpline
--> CubicSpline2d
--> ( Point2d ( 1, 1 )
--> , Point2d ( 1, 1 )
--> , Point2d ( 3, 1 )
--> , Point2d ( 3, 3 )
--> )
Construct a spline from its three control points. This is the same as just using the
CubicSpline3dconstructor directly;is equivalent to