Package geomss.geom.nurbs
Class KnotVector
- java.lang.Object
-
- geomss.geom.nurbs.KnotVector
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,javolution.lang.Immutable
,javolution.lang.ValueType
,javolution.xml.XMLSerializable
public class KnotVector extends java.lang.Object implements java.lang.Cloneable, javolution.xml.XMLSerializable, javolution.lang.ValueType
An immutable collection of knot values that are associated with a NURBS curve or surface.Modified by: Joseph A. Huwaldt
- Version:
- February 17, 2025
- Author:
- Samuel Gerber, Date: May 14, 2009, Version 1.0.
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description double[][]
basisFunctionDerivatives(int span, double s, int grade)
Calculates all the derivatives of all the unweighted basis functions from0
up to the given grade,d^{grade}Nik(s)/d^{grade}s
.double[]
basisFunctions(double s)
Returns the basis function values for the given parameter value (Nik(s)).double[]
basisFunctions(int span, double s)
Returns the unweighted basis function values for the given parameter value (Nik(s)), when the span that the parameter value lies in is already known.static KnotVector
bezierKnotVector(int degree)
Return a knot vector that can be used to create a Bezier curve segment of the specified degree using the BasicNurbsCurve class.java.lang.Object
clone()
Returns a copy of this KnotVector instanceallocated
by the calling thread (possibly on the stack).KnotVector
copy()
Returns a copy of this KnotVector instanceallocated
by the calling thread (possibly on the stack).boolean
equals(java.lang.Object obj)
Compares this ControlPoint against the specified object for strict equality (same values and same units).int
findMultiplicity(int index)
Find the multiplicity of the knot with the specified index in this knot vector.int
findSpan(double s)
Returns the span (position of corresponding knot values in knot vector) a given parameter value belongs to.Float64
get(int i)
Return the knot at the specified index.Float64Vector
getAll()
Return the knot values as an vector ofFloat64
values.int
getDegree()
Return the degree of the KnotVectorint
getNu()
Return the length of the knot vector (nu).int
getNumberOfSegments()
Return the number of segments in the knot vector.double
getValue(int i)
Return the knot value at a specific index as adouble
.int
hashCode()
Returns the hash code for this parameter.boolean
isOpen()
Returntrue
if the knot vector is open andfalse
if it is closed.boolean
isValid()
Returntrue
if this KnotVector contains valid and finite numerical components.int
length()
Return the number of elements in the knot vector.static KnotVector
newInstance(int degree, double... knots)
Create a KnotVector from the given knot values of the desired degree.static KnotVector
newInstance(int degree, java.util.List<java.lang.Double> knots)
Create a KnotVector from the given list of knot values of the desired degree.static KnotVector
newInstance(int degree, Float64Vector knots)
Create a KnotVector from the given knot values of the desired degree.static void
recycle2DArray(double[][] arr)
Recycle any 2D array of doubles that was created by this classes factory methods.KnotVector
reverse()
Return a copy of this knot vector with the parameterization reversed.java.lang.String
toString()
Returns the string representation of this knot vector that consists of the degree followed by the knot values.javolution.text.Text
toText()
Returns the text representation of this knot vector that consists of the degree followed by the knot values.
-
-
-
Method Detail
-
newInstance
public static KnotVector newInstance(int degree, Float64Vector knots)
Create a KnotVector from the given knot values of the desired degree.- Parameters:
degree
- degree of NURBS curveknots
- knot values. May not be null.- Returns:
- A KnotVector consisting of the given knots and degree.
- Throws:
java.lang.IllegalArgumentException
- if the knot vector is not valid.
-
newInstance
public static KnotVector newInstance(int degree, java.util.List<java.lang.Double> knots) throws java.lang.IllegalArgumentException
Create a KnotVector from the given list of knot values of the desired degree.- Parameters:
degree
- degree of NURBS curveknots
- A list of knot values. May not be null.- Returns:
- A KnotVector consisting of the given knots and degree.
- Throws:
java.lang.IllegalArgumentException
- if the knot vector is not valid.
-
newInstance
public static KnotVector newInstance(int degree, double... knots) throws java.lang.IllegalArgumentException
Create a KnotVector from the given knot values of the desired degree.- Parameters:
degree
- degree of NURBS curveknots
- knot values. May not be null.- Returns:
- A KnotVector consisting of the given knots and degree.
- Throws:
java.lang.IllegalArgumentException
- if the knot vector is not valid.
-
bezierKnotVector
public static KnotVector bezierKnotVector(int degree)
Return a knot vector that can be used to create a Bezier curve segment of the specified degree using the BasicNurbsCurve class.- Parameters:
degree
- The degree of the knot vector to return.- Returns:
- A knot vector appropriate for creating a Bezier curve segment.
-
findSpan
public int findSpan(double s)
Returns the span (position of corresponding knot values in knot vector) a given parameter value belongs to.- Parameters:
s
- parameter value to find the span for- Returns:
- Position of span.
-
basisFunctions
public double[] basisFunctions(double s)
Returns the basis function values for the given parameter value (Nik(s)). This function first calculates the span which is needed in order to calculate the basis functions values.- Parameters:
s
- Parameter value to calculate basis functions for.- Returns:
- basis function values. WARNING: the returned array will likely be longer than [0..degree], so do NOT depend on array.length in any iterations over the array!. The additional array elements will contain garbage and should not be used. The returned array was allocated using javolution.context.ArrayFactory.DOUBLES_FACTORY and could be recycled by the user when no longer needed.
-
basisFunctions
public double[] basisFunctions(int span, double s)
Returns the unweighted basis function values for the given parameter value (Nik(s)), when the span that the parameter value lies in is already known.- Parameters:
span
- The spans
lies ins
- The parameter value to calculate basis functions for.- Returns:
- basis function values. WARNING: the returned array will likely be longer than [0..degree], so do NOT depend on array.length in any iterations over the array!. The additional array elements will contain garbage and should not be used. The returned array was allocated using javolution.context.ArrayFactory.DOUBLES_FACTORY and could be recycled by the user when no longer needed.
-
basisFunctionDerivatives
public double[][] basisFunctionDerivatives(int span, double s, int grade)
Calculates all the derivatives of all the unweighted basis functions from0
up to the given grade,d^{grade}Nik(s)/d^{grade}s
.Examples:
1st derivative (grade = 1), this returns[Nik(s), dNik(s)/ds]
;
2nd derivative (grade = 2), this returns[Nik(s), dNik(s)/ds, d^2Nik(s)/d^2s]
; etc.- Parameters:
span
- The spans
lies ins
- The parameter value to calculate basis functions for.grade
- The grade to calculate the derivatives for (1=1st derivative, 2=2nd derivative, etc).- Returns:
- Basis function derivative values. WARNING: the returned array is recycled
and will likely be longer than [0..grade+1][0..degree+1], so do NOT depend on
array.length in any iterations over the array!. The additional array elements will
contain garbage and should not be used. The returned array could be recycled by
calling
KnotVector.recycle2DArray(arr)
when no longer needed. - Throws:
java.lang.IllegalArgumentException
- if the grade is < 0.- See Also:
basisFunctions(double)
,recycle2DArray(double[][])
-
getNu
public int getNu()
Return the length of the knot vector (nu).- Returns:
- The length of the knot vector.
-
length
public int length()
Return the number of elements in the knot vector.- Returns:
- The number of elements in the knot vector.
-
getAll
public Float64Vector getAll()
Return the knot values as an vector ofFloat64
values.- Returns:
- the vector of knot values
-
get
public Float64 get(int i)
Return the knot at the specified index.- Parameters:
i
- Index to get knot value for- Returns:
- the knot value at index
i
-
getValue
public double getValue(int i)
Return the knot value at a specific index as adouble
.- Parameters:
i
- Index to get knot value for- Returns:
- the knot value at index
i
returned as adouble
.
-
getDegree
public int getDegree()
Return the degree of the KnotVector- Returns:
- Degree of the KnotVector
-
getNumberOfSegments
public int getNumberOfSegments()
Return the number of segments in the knot vector.- Returns:
- The number of segments in the knot vector.
-
isOpen
public boolean isOpen()
Returntrue
if the knot vector is open andfalse
if it is closed.- Returns:
- true if the knot vector is open.
-
isValid
public boolean isValid()
Returntrue
if this KnotVector contains valid and finite numerical components. A value offalse
will be returned if any of the knot values are NaN or Inf.- Returns:
- true if the KnotVector contains valid and finite values.
-
findMultiplicity
public int findMultiplicity(int index)
Find the multiplicity of the knot with the specified index in this knot vector.- Parameters:
index
- the index of the knot to observe (the largest index of a repeated series of knots).- Returns:
- the multiplicity of the knot
-
reverse
public KnotVector reverse()
Return a copy of this knot vector with the parameterization reversed.- Returns:
- A copy of this KnotVector with the parameterization reversed.
-
copy
public KnotVector copy()
Returns a copy of this KnotVector instanceallocated
by the calling thread (possibly on the stack).- Specified by:
copy
in interfacejavolution.lang.ValueType
- Returns:
- an identical and independent copy of this point.
-
clone
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
Returns a copy of this KnotVector instanceallocated
by the calling thread (possibly on the stack).- Returns:
- an identical and independent copy of this point.
- Throws:
java.lang.CloneNotSupportedException
- Never thrown.
-
equals
public boolean equals(java.lang.Object obj)
Compares this ControlPoint against the specified object for strict equality (same values and same units).- Overrides:
equals
in classjava.lang.Object
- Parameters:
obj
- the object to compare with.- Returns:
true
if this point is identical to that point;false
otherwise.
-
hashCode
public int hashCode()
Returns the hash code for this parameter.- Overrides:
hashCode
in classjava.lang.Object
- Returns:
- the hash code value.
-
toText
public javolution.text.Text toText()
Returns the text representation of this knot vector that consists of the degree followed by the knot values. For example:{degree=2,{0.0, 0.0, 0.0, 1.0, 1.0, 1.0}}
- Returns:
- the text representation of this geometry element.
-
toString
public java.lang.String toString()
Returns the string representation of this knot vector that consists of the degree followed by the knot values. For example:{degree=2,{0.0, 0.0, 0.0, 1.0, 1.0, 1.0}}
- Overrides:
toString
in classjava.lang.Object
- Returns:
- the text representation of this geometry element.
-
recycle2DArray
public static void recycle2DArray(double[][] arr)
Recycle any 2D array of doubles that was created by this classes factory methods.- Parameters:
arr
- The array to be recycled. The array must have been created by this class or by CurveUtils.allocate2DArray()!
-
-