Class NurbsBase
This class represents a base class that is common to most curve types.
public abstract class NurbsBase : IGeometry<NurbsBase>, IEquatable<NurbsBase>, ITransformable<NurbsBase>
protected NurbsBase()
protected NurbsBase(int degree, KnotVector knots, List<Point4> controlPoints)
Type | Name | Description |
---|---|---|
System.Int32 | degree | |
KnotVector | knots | |
System.Collections.Generic.List<Point4> | controlPoints |
Gets the control points in their rational form.
public List<Point3> ControlPointLocations { get; protected set; }
Type | Description |
---|---|
System.Collections.Generic.List<Point3> |
Gets the control points in their homogenized form.
public List<Point4> ControlPoints { get; protected set; }
Type | Description |
---|---|
System.Collections.Generic.List<Point4> |
Gets the degree of the curve.
public int Degree { get; protected set; }
Type | Description |
---|---|
System.Int32 |
public virtual Point3 EndPoint { get; }
Type | Description |
---|---|
Point3 |
Checks if a curve is closed.
A curve is closed if the first point and the last are the same.
public virtual bool IsClosed { get; }
Type | Description |
---|---|
System.Boolean | True if the curve is closed. |
Checks if a curve is periodic.
A curve is periodic, where the number of overlapping points is equal the curve degree.
public bool IsPeriodic { get; }
Type | Description |
---|---|
System.Boolean | True if the curve is periodic. |
Gets the knots vectors of the curve.
public KnotVector Knots { get; protected set; }
Type | Description |
---|---|
KnotVector |
public virtual double Length { get; }
Type | Description |
---|---|
System.Double |
public virtual Point3 MidPoint { get; }
Type | Description |
---|---|
Point3 |
public virtual Point3 StartPoint { get; }
Type | Description |
---|---|
Point3 |
Gets the list of weight values.
public List<double> Weights { get; protected set; }
Type | Description |
---|---|
System.Collections.Generic.List<System.Double> |
Converts a curve where the knotVector is clamped.
public NurbsBase ClampEnds()
Type | Description |
---|---|
NurbsBase | A curve with clamped knots. |
Creates a periodic curve.
This method uses the control point wrapping solution.
https://pages.mtu.edu/~shene/COURSES/cs3621/NOTES/spline/B-spline/bspline-curve-closed.html
public virtual NurbsBase Close()
Type | Description |
---|---|
NurbsBase | A periodic curve. |
public virtual double ClosestParameter(Point3 pt)
Type | Name | Description |
---|---|---|
Point3 | pt |
Type | Description |
---|---|
System.Double |
public virtual Point3 ClosestPoint(Point3 point)
Type | Name | Description |
---|---|---|
Point3 | point |
Type | Description |
---|---|
Point3 |
Computes the curvature vector of the curve at the parameter. The vector has length equal to the radius of the curvature circle and with direction to the center of the circle.
public Vector3 CurvatureAt(double t)
Type | Name | Description |
---|---|---|
System.Double | t | Evaluation parameter. Parameter should be between 0.0 and 1.0. |
Type | Description |
---|---|
Vector3 | The curvature vector. |
Decompose a curve into a collection of Beziers curves.
public List<NurbsBase> DecomposeIntoBeziers()
Type | Description |
---|---|
System.Collections.Generic.List<NurbsBase> | A collection of Beziers. |
Determines the derivatives of a curve at a given parameter.
public List<Vector3> DerivativeAt(double t, int numberOfDerivatives = 1)
Type | Name | Description |
---|---|---|
System.Double | t | Parameter on the curve at which the point is to be evaluated. Parameter should be between 0.0 and 1.0. |
System.Int32 | numberOfDerivatives | The number of derivatives required. |
Type | Description |
---|---|
System.Collections.Generic.List<Vector3> | The derivatives. |
Divides a curve for a given max segment length, including the end points.
The result is not split curves but a collection of t values and lengths that can be used for splitting.
As with all arc length methods, the result is an approximation.
public (List<Point3> Points, List<double> Parameters) Divide(double maxSegmentLength, bool equalSegmentLengths = false)
Type | Name | Description |
---|---|---|
System.Double | maxSegmentLength | The maximum length the segments have to be split in. |
System.Boolean | equalSegmentLengths | Force to have all the segments of the same lengths. |
Type | Description |
---|---|
System.ValueTuple<System.Collections.Generic.List<Point3>, System.Collections.Generic.List<System.Double>> | A tuple define the t values where the curve is divided and the lengths between each division. |
Divides a curve for a given number of time, including the end points.
The result is not split curves but a collection of t values and lengths that can be used for splitting.
As with all arc length methods, the result is an approximation.
public (List<Point3> Points, List<double> Parameters) Divide(int numberOfSegments)
Type | Name | Description |
---|---|---|
System.Int32 | numberOfSegments | The number of parts to split the curve into. |
Type | Description |
---|---|
System.ValueTuple<System.Collections.Generic.List<Point3>, System.Collections.Generic.List<System.Double>> | A tuple define the t values where the curve is divided and the lengths between each division. |
Divides a curve by a given chord length. Last chord will be of whatever length is left at the end of the curve.
public List<double> DivideByChordLength(double chordLength)
Type | Name | Description |
---|---|---|
System.Double | chordLength | Desired chord length. |
Type | Description |
---|---|
System.Collections.Generic.List<System.Double> | Collection of curve parameters along the curve. |
Elevates the degree of a curve. Implementation of Algorithm A5.9 of The NURBS Book by Piegl and Tiller.
public NurbsBase ElevateDegree(int desiredDegree)
Type | Name | Description |
---|---|---|
System.Int32 | desiredDegree | The expected final degree. If the supplied degree is less or equal the curve is returned unmodified. |
Type | Description |
---|---|
NurbsBase | The curve after degree elevation. |
Compares two curves for equality.
Two curves are equal when the have same control points, weights, knots and degree.
public bool Equals(NurbsBase other)
Type | Name | Description |
---|---|---|
NurbsBase | other | The other curve. |
Type | Description |
---|---|
System.Boolean | Return true if the curves are equal. |
Compares if two curves are the same.
Two curves are equal when the have same degree, same control points order and dimension, and same knots.
public override bool Equals(object obj)
Type | Name | Description |
---|---|---|
System.Object | obj | The curve object. |
Type | Description |
---|---|
System.Boolean | Return true if the curves are equal. |
Computes the parameter values of all local extrema.
public IReadOnlyList<double> Extrema()
Type | Description |
---|---|
System.Collections.Generic.IReadOnlyList<System.Double> | The parameter values of all the local extrema. |
Gets the bounding box of the curve.
public virtual BoundingBox GetBoundingBox()
Type | Description |
---|---|
BoundingBox |
public override int GetHashCode()
Type | Description |
---|---|
System.Int32 |
Joins all the curves, if it is possible.
public static PolyCurve Join(IList<NurbsBase> curves)
Type | Name | Description |
---|---|---|
System.Collections.Generic.IList<NurbsBase> | curves | The curves to join. |
Type | Description |
---|---|
PolyCurve | The polycurve that is the result of joining all the curves. |
public virtual double LengthAt(double t)
Type | Name | Description |
---|---|---|
System.Double | t |
Type | Description |
---|---|
System.Double |
Computes the offset of the curve.
public virtual NurbsBase Offset(double distance, Plane pln)
Type | Name | Description |
---|---|---|
System.Double | distance | The distance of the offset. If negative the offset will be in the opposite side. |
Plane | pln | The plane for the offset operation. |
Type | Description |
---|---|
NurbsBase | The offset curve. |
Evaluates a point at a given chord length from a parameter on the curve.
public double ParameterAtChordLength(double t, double chordLength)
Type | Name | Description |
---|---|---|
System.Double | t | |
System.Double | chordLength |
Type | Description |
---|---|
System.Double |
Computes the parameter along the curve which coincides with a given length.
public virtual double ParameterAtLength(double segmentLength)
Type | Name | Description |
---|---|---|
System.Double | segmentLength | Length of segment to measure. Must be less than or equal to the length of the curve. |
Type | Description |
---|---|
System.Double | The parameter on the curve at the given length. |
Calculates the 3D plane at the given parameter. Defined as the Frenet frame, is constructed from the velocity and the acceleration of the curve. https://janakiev.com/blog/framing-parametric-curves/
public Plane PerpendicularFrameAt(double t)
Type | Name | Description |
---|---|---|
System.Double | t | Evaluation parameter. Parameter should be between 0.0 and 1.0. |
Type | Description |
---|---|
Plane | The perpendicular frame. |
Creates rotation minimized perpendicular frames (RMF) at given t parameters along the curve.
Double reflection method taken from Wang, W., J¨uttler, B., Zheng, D., and Liu, Y. 2008. "Computation of rotation minimizing frame."
https://www.microsoft.com/en-us/research/wp-content/uploads/2016/12/Computation-of-rotation-minimizing-frames.pdf
public List<Plane> PerpendicularFrames(List<double> uValues, Vector3? startTangent = null, Vector3? endTangent = null)
Type | Name | Description |
---|---|---|
System.Collections.Generic.List<System.Double> | uValues | The curve parameter values to locate perpendicular curve frames |
System.Nullable<Vector3> | startTangent | If not null override start tangent vector. |
System.Nullable<Vector3> | endTangent | If not null override end tangent vector. |
Type | Description |
---|---|
System.Collections.Generic.List<Plane> | A collection of planes. |
public virtual Point3 PointAt(double t)
Type | Name | Description |
---|---|---|
System.Double | t |
Type | Description |
---|---|
Point3 |
public virtual Point3 PointAtLength(double length)
Type | Name | Description |
---|---|---|
System.Double | length |
Type | Description |
---|---|
Point3 |
Evaluates a point at the normalized length.
public virtual Point3 PointAtNormalizedLength(double normalizedLength)
Type | Name | Description |
---|---|---|
System.Double | normalizedLength | The length factor is normalized between 0.0 and 1.0. |
Type | Description |
---|---|
Point3 | The point at the length. |
Reduce the degree of a NURBS curve. Implementation of Algorithm A5.11 of The NURBS Book by Piegl and Tiller. ToDo: Remove the tolerance, just let reduce and output the max deviation. ToDo: Try this method to reduce the bezier, looks more accurate. https://pomax.github.io/bezierinfo/chapters/reordering/reorder.js
public NurbsBase ReduceDegree(double tolerance = 0.001)
Type | Name | Description |
---|---|---|
System.Double | tolerance | Tolerance value declaring if the curve is degree reducible. Default value set to 10e-4, refer to Eq 5.30 for the meaning. |
Type | Description |
---|---|
NurbsBase | The curve after degree reduction, the curve will be degree - 1 from the input. |
Reverses the parametrization of the curve.
public virtual NurbsBase Reverse()
Type | Description |
---|---|
NurbsBase | A reversed curve. |
Splits a curve into two parts at a given parameter.
public List<NurbsBase> SplitAt(double t)
Type | Name | Description |
---|---|---|
System.Double | t | The parameter at which to split the curve. |
Type | Description |
---|---|
System.Collections.Generic.List<NurbsBase> | Two curves. |
Splits a curve at given parameters and returns the segments as curves.
public List<NurbsBase> SplitAt(double[] parameters)
Type | Name | Description |
---|---|---|
System.Double[] | parameters | The parameters at which to split the curve. Values should be between 0.0 and 1.0. |
Type | Description |
---|---|
System.Collections.Generic.List<NurbsBase> | Collection of curve segments. |
Extract sub-curve defined by domain.
public NurbsBase SubCurve(Interval domain)
Type | Name | Description |
---|---|---|
Interval | domain | Domain of sub-curve |
Type | Description |
---|---|
NurbsBase | The sub curve. |
Computes the curve tangent at the given parameter.
public virtual Vector3 TangentAt(double t)
Type | Name | Description |
---|---|---|
System.Double | t | The parameter to sample the curve. Parameter should be between 0.0 and 1.0. |
Type | Description |
---|---|
Vector3 | The unitized tangent vector at the given parameter. |
Implements the override method to string.
public override string ToString()
Type | Description |
---|---|
System.String | The representation of a curve in string. |
Applies a transformation on the geometry object and returns the transformed geometry.
public NurbsBase Transform(TransformMatrix t)
Type | Name | Description |
---|---|---|
TransformMatrix | t | The transformation matrix that represents the transformation. |
Type | Description |
---|---|
NurbsBase | The transformed geometry |