Package geomss.geom.nurbs
Class CurveUtils
- java.lang.Object
-
- geomss.geom.nurbs.CurveUtils
-
public final class CurveUtils extends java.lang.Object
A collection of utility methods for working with NURBS curves.Modified by: Joseph A. Huwaldt
- Version:
- February 17, 2025
- Author:
- Samuel Gerber, Date: May 14, 2009, Version 1.0.
-
-
Constructor Summary
Constructors Constructor Description CurveUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static double[][]
allocate2DArray(int rows, int cols)
Allocate a recyclable 2D array of double values using factory methods.static BasicNurbsCurve
arcLengthParameterize(NurbsCurve crv, Parameter<javax.measure.quantity.Length> tol)
Return a NurbsCurve, with the same degree as the input curve, which is an approximate arc-length re-parameterization of the input NurbsCurve.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.static BasicNurbsCurve
connectCurves(NurbsCurve... curves)
Connect together or "concatenate" a list of curves end-to-start.static BasicNurbsCurve
connectCurves(java.util.List<NurbsCurve> curves)
Connect together or "concatenate" a list of curves end-to-start.static BasicNurbsCurve
createBlend(Curve crv1, Curve crv2, Parameter<javax.measure.quantity.Length> eps, double sEnd1, double sEnd2, int degree)
Return a blending curve between two curve ends.static BasicNurbsCurve
createFillet(Curve crv1, Curve crv2, Parameter<javax.measure.quantity.Length> eps, double sEnd1, double sFil1, double sEnd2, double sFil2, int itype, int degree)
Return a fillet curve between two curves.static BasicNurbsCurve
createFillet(GeomPoint p1, GeomPoint p2, GeomPoint p3, GeomPoint p4, Parameter<javax.measure.quantity.Length> radius, Parameter<javax.measure.quantity.Length> eps)
Return a circular fillet curve between two planar non-parallel lines.static GeomList<BasicNurbsCurve>
decomposeToBezier(NurbsCurve curve)
Decompose a NURBS curve into a list of Bezier segments.static NurbsCurve
degreeElevate(NurbsCurve curve, int t)
Elevate the degree of a curve by the specified number of times.static NurbsCurve
elevateToDegree(NurbsCurve curve, int degree)
Elevate the degree of a curve to the specified degree.static javolution.util.FastTable<java.lang.Double>
getBezierStartParameters(NurbsCurve crv)
Returns a list containing the parameters at the start (and end) of each Bezier segment of the specified NURBS curve.static boolean
isBezierEndPointNearest(GeomPoint point, java.util.List<ControlPoint> P)
Returnstrue
if an end point is the closest point in the specified Bezier curve segment to the target point.static boolean
isSimpleConvexPolygon(java.util.List<ControlPoint> P)
Return true if the supplied control point polygon is simple and convex.static Float64Vector
knotVectorUnion(Float64Vector Ua, Float64Vector Ub)
Return the union between two knot vectors.static void
recycle2DArray(double[][] arr)
Recycle any 2D array of doubles that was created by allocate2DArray().static BasicNurbsCurve
thinKnotsToTolerance(BasicNurbsCurve original, Parameter<javax.measure.quantity.Length> tol)
Attempt to minimize the number of knots in the specified NURBS curve while maintaining the same shape (to within tolerance) of the original curve.
-
-
-
Constructor Detail
-
CurveUtils
public CurveUtils()
-
-
Method Detail
-
elevateToDegree
public static NurbsCurve elevateToDegree(NurbsCurve curve, int degree)
Elevate the degree of a curve to the specified degree. If the specified degree is ≤ the current degree of the curve, then no change is made and a reference to the input curve is returned.- Parameters:
curve
- The curve to have the degree elevated. May not be null.degree
- The desired degree for the curve to be elevated to.- Returns:
- The input NurbsCurve with the degree elevated to the specified degree.
-
degreeElevate
public static NurbsCurve degreeElevate(NurbsCurve curve, int t)
Elevate the degree of a curve by the specified number of times.- Parameters:
curve
- The curve to have the degree elevated. May not be null.t
- The number of times to elevate the degree.- Returns:
- The input NurbsCurve with the degree elevated by the specified amount.
-
decomposeToBezier
public static GeomList<BasicNurbsCurve> decomposeToBezier(NurbsCurve curve)
Decompose a NURBS curve into a list of Bezier segments. The returned list contains NURBS curves each of which represents a single Bezier segment.- Parameters:
curve
- The curve to be decomposed into Bezier segments. May not be null.- Returns:
- A list of Bezier curve segments (will be at least degree = 2).
-
getBezierStartParameters
public static javolution.util.FastTable<java.lang.Double> getBezierStartParameters(NurbsCurve crv)
Returns a list containing the parameters at the start (and end) of each Bezier segment of the specified NURBS curve. This first element of this list will always be zero and the last will always be 1.- Parameters:
crv
- The NURBS curve to return the Bezier segment start parameters for. May not be null.- Returns:
- A list containing the parameters of the start and end of each Bezier segment.
-
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 for creating a Bezier curve segment of the specified degree.
-
connectCurves
public static BasicNurbsCurve connectCurves(java.util.List<NurbsCurve> curves) throws java.lang.IllegalArgumentException
Connect together or "concatenate" a list of curves end-to-start. The end of each curve (u=1) is connected to the start (u=0) of the next curve. No check is made for the curve ends being near each other. The resulting curve will have the physical dimension of the highest dimension curve in the input list. The resulting curve will have the degree of the highest degree curve in the input list.- Parameters:
curves
- The list of curves to be connected together. May not be null.- Returns:
- A single
BasicNurbsCurve
made up of the input curves connected together end-to-start. - Throws:
java.lang.IllegalArgumentException
- if there are less than 2 curves.
-
connectCurves
public static BasicNurbsCurve connectCurves(NurbsCurve... curves) throws java.lang.IllegalArgumentException
Connect together or "concatenate" a list of curves end-to-start. The end of each curve (u=1) is connected to the start (u=0) of the next curve. No check is made for the curve ends being near each other. The resulting curve will have the physical dimension of the highest dimension curve in the input list. The resulting curve will have the degree of the highest degree curve in the input list.- Parameters:
curves
- The list of curves to be connected together. May not be null.- Returns:
- A single
BasicNurbsCurve
made up of the input curves connected together end-to-start. - Throws:
java.lang.IllegalArgumentException
- if there are less than 2 curves.
-
createFillet
public static BasicNurbsCurve createFillet(Curve crv1, Curve crv2, Parameter<javax.measure.quantity.Length> eps, double sEnd1, double sFil1, double sEnd2, double sFil2, int itype, int degree)
Return a fillet curve between two curves. Parameter values indicate the points between which the fillet is to be produced. The output curve will have the physical dimension of the highest dimension of the two input curves.- Parameters:
crv1
- The 1st input curve. May not be null.crv2
- The 2nd input curve. May not be null.eps
- The geometry tolerance to use when determining if this a planar curve. If null is passed, then the curve would have be be exactly planar to be a circular or conic segment.sEnd1
- Parameter value on the first curve telling that the part of the curve lying on this side of sFil1 shall not be replaced by the fillet.sFil1
- Parameter value of the starting point of the fillet on the first curve.sEnd2
- Parameter value on the second curve telling that the part of the curve lying on this side of sFil2 shall not be replaced by the fillet.sFil2
- Parameter value of the starting point of the fillet on the second curve.itype
- Indicator of type of fillet. = 1 - Circle, interpolating point and tangent on first curve and the point on the 2nd curve, but not the tangent on curve 2. = 2 - Planar conic if possible else - A generic polynomial segment.degree
- Degree of fillet curve to return.- Returns:
- A
BasicNurbsCurve
fillet curve.
-
createFillet
public static BasicNurbsCurve createFillet(GeomPoint p1, GeomPoint p2, GeomPoint p3, GeomPoint p4, Parameter<javax.measure.quantity.Length> radius, Parameter<javax.measure.quantity.Length> eps)
Return a circular fillet curve between two planar non-parallel lines. The output curve will have the physical dimension of the highest dimension of the two input lines. The corner where the fillet is applied depends on the directions of the input lines. It is the corner that is to the left of each input line when standing at the start of the line and looking toward the end of the line.- Parameters:
p1
- The 1st end of the 1st input line. May not be null.p2
- The 2nd end of the 1st input line. May not be null.p3
- The 1st end of the 2nd input line. May not be null.p4
- The 2nd end of the 2nd input line. May not be null.radius
- The radius of the circular fillet. May not be null.eps
- The geometry tolerance to use in determining if the input line segments are co-planar. If null is passed, the input lines must be exactly co-planar.- Returns:
- A
BasicNurbsCurve
circular arc fillet curve.
-
createBlend
public static BasicNurbsCurve createBlend(Curve crv1, Curve crv2, Parameter<javax.measure.quantity.Length> eps, double sEnd1, double sEnd2, int degree)
Return a blending curve between two curve ends. Parameter values indicate which ends of the input curves the blend curve is to touch. The output curve will be a conic section if possible otherwise it will be a polynomial curve and will have the physical dimension of the highest dimension of the two input curves.- Parameters:
crv1
- The 1st input curve. May not be null.crv2
- The 2nd input curve. May not be null.eps
- The geometry tolerance to use when determining if the output is a planar curve. If null is passed, then the curve would have be be exactly planar to be a circular or conic segment.sEnd1
- Parameter value on crv1 indicating which end of curve 1 should start the blend.sEnd2
- Parameter value on crv2 indicating which end of curve 2 should end the blend.degree
- Degree of blend curve to return.- Returns:
- A
BasicNurbsCurve
blending curve between the input curves.
-
arcLengthParameterize
public static BasicNurbsCurve arcLengthParameterize(NurbsCurve crv, Parameter<javax.measure.quantity.Length> tol)
Return a NurbsCurve, with the same degree as the input curve, which is an approximate arc-length re-parameterization of the input NurbsCurve.- Parameters:
crv
- The NurbsCurve to be approximately re-parameterized. May not be null.tol
- The geometric tolerance to use when re-parameterizing the input curve. May not be null or zero.- Returns:
- The arc-length parameterized curve that is approximately the same as the input curve.
-
thinKnotsToTolerance
public static BasicNurbsCurve thinKnotsToTolerance(BasicNurbsCurve original, Parameter<javax.measure.quantity.Length> tol)
Attempt to minimize the number of knots in the specified NURBS curve while maintaining the same shape (to within tolerance) of the original curve.- Parameters:
original
- The original curve to have the knots thinned to tolerance. May not be null.tol
- The allowable tolerance between the original curve and the curve with the knots thinned. May not be null.- Returns:
- A curve that represents the original curve to within the given tolerance but with fewer knots. If no knots could be removed, the original curve is returned.
-
isSimpleConvexPolygon
public static boolean isSimpleConvexPolygon(java.util.List<ControlPoint> P)
Return true if the supplied control point polygon is simple and convex.- Parameters:
P
- The list of control points to evaluate. May not be null.- Returns:
- true if the control point polygon is simple and convex.
-
isBezierEndPointNearest
public static boolean isBezierEndPointNearest(GeomPoint point, java.util.List<ControlPoint> P)
Returnstrue
if an end point is the closest point in the specified Bezier curve segment to the target point. Returnsfalse
if the closest point may be interior to the curve segment.- Parameters:
point
- The point to find the closest/farthest point on this curve to/from. May not be null.P
- The control point polygon for the Bezier curve. May not be null.- Returns:
true
if an end point of the specified segment is closest to the target point.
-
knotVectorUnion
public static Float64Vector knotVectorUnion(Float64Vector Ua, Float64Vector Ub)
Return the union between two knot vectors. This merges two knot vectors together to obtain on combined knot vector. Warning: The results of this method are useless if the knot vectors being merged are not from NURBS curves of the same degree.- Parameters:
Ua
- The 1st knot vector to merge. May not be null.Ub
- The 2nd knot vector to merge. May not be null.- Returns:
- The union of Ua and Ub.
-
allocate2DArray
public static double[][] allocate2DArray(int rows, int cols)
Allocate a recyclable 2D array of double values using factory methods.WARNING: The array returned may not be zeroed and may be larger than the requested number of rows & columns! The array returned by this method can be recycled by recycle2DArray().
- Parameters:
rows
- The minimum number of rows (1st index) for the returned array.cols
- The minimum number of columns (2nd index) for the returned array.- Returns:
- A 2D array of doubles allocated using factory methods.
- See Also:
recycle2DArray(double[][])
-
recycle2DArray
public static void recycle2DArray(double[][] arr)
Recycle any 2D array of doubles that was created by allocate2DArray().- Parameters:
arr
- The array to be recycled. The array must have been created by this the allocate2DArray() method! May not be null.- See Also:
allocate2DArray(int, int)
-
-