Class BSpline


  • public class BSpline
    extends java.lang.Object
    Class to represent a B-spline (non-rational and with evenly spaced knots).
    Author:
    jsevy
    • Constructor Summary

      Constructors 
      Constructor Description
      BSpline​(int degree, double[] controlPoints, int[] multiplicities, boolean throughEndpoints)
      Create a spline of the specified degree using the supplied x,y coordinate pairs as the control points.
      BSpline​(int degree, java.util.Vector<SplineControlPoint> controlPoints)
      Create e new B-spline of the specified degree using the supplied control points
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static void drawSpline​(java.awt.Graphics graphics, int degree, double[] controlPoints, int[] multiplicities, boolean throughEndpoints, double tolerance)
      An extension method that supports the drawing of a B-spline.
      java.util.Vector<RealPoint> getCurvePoints​(double tolerance)
      Get a set of points on the spline curve, where the maximum distance between two adjacent points is given by tolerance.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • BSpline

        public BSpline​(int degree,
                       java.util.Vector<SplineControlPoint> controlPoints)
        Create e new B-spline of the specified degree using the supplied control points
        Parameters:
        degree - Degree of the spline polynomial pieces
        controlPoints - The set of control points used to define the spline
      • BSpline

        public BSpline​(int degree,
                       double[] controlPoints,
                       int[] multiplicities,
                       boolean throughEndpoints)
        Create a spline of the specified degree using the supplied x,y coordinate pairs as the control points.
        Parameters:
        degree - The degree of the underlying piecewise-polynomial segments
        controlPoints - The control points used to define the shape of the spline, {x1, y1, x2, y2, ..., xn, yn}
        multiplicities - Array giving the multiplicity of each of the control points. The size of the multiplicities must be half the size of the controlPoints array.
        throughEndpoints - Set true to force the spline curve to pass through the end control points. This is accomplished by forcing the multiplicity of the first and last control points to degree + 1. Note that this will give a different spline curve than that typically referred to as a "clamped" spline, in which the spline knots are repeated at the beginning and end to force the spline to pass through these points. The repeated control-point approach has the advantage of having the "open" spline (where throughEndpoints is false) being a subset of the "closed" curve; this is not true for "unclamped" and "clamped" splines.
    • Method Detail

      • drawSpline

        public static void drawSpline​(java.awt.Graphics graphics,
                                      int degree,
                                      double[] controlPoints,
                                      int[] multiplicities,
                                      boolean throughEndpoints,
                                      double tolerance)
        An extension method that supports the drawing of a B-spline. If the supplied Graphics is an instance of DXFGraphics, this generates a native DXF spline type. For other Graphics types, this draws the spline as a set of line segments since there are no native spline-drawing routines in the standard Java. The tolerance parameter indicates the maximum length of each line segment to control the smoothness of the representation. For the common case of a spline that passes through the first and last control points, set the multiplicity of these equal to the spline degree plus 1, or set the throughEndpoints parameter to true, which does the same internally.
        Parameters:
        degree - The degree of the spline; must be greater than 0
        controlPoints - The control points that define the shape of the spline, {x1, y1, x2, y2, ..., xn, yn}.
        multiplicities - The multiplicities for the control points; the number of multiplicity values must equal the number of control points (i.e., the array size must be half that of the controlPoints array)
        throughEndpoints - If true, the spline will be forced to pass through the endpoints by setting the end control point multiplicities to degree + 1
        tolerance - For non-DXF Graphics types, the spline is drawn as a set of connected line segments; the tolerance specifies that maximum lenth of each line segment to control the smoothness of the representation. Ignored for DXFGraphics, which has a true spline representation.
        graphics - The graphics object specifying parameters for the arc (color, thickness)
      • getCurvePoints

        public java.util.Vector<RealPoint> getCurvePoints​(double tolerance)
        Get a set of points on the spline curve, where the maximum distance between two adjacent points is given by tolerance.
        Parameters:
        tolerance - The maximum distance between any two adjacent points in the return vector
        Returns:
        A vector containing a set of points which lie on the spline curve
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object