Class CubicBezierApproximator

java.lang.Object
org.apache.fop.afp.util.CubicBezierApproximator

public final class CubicBezierApproximator extends Object
This class can be used to convert a cubic bezier curve within a path into multiple quadratic bezier curves which will approximate the original cubic curve. The various techniques are described here: http://www.timotheegroleau.com/Flash/articles/cubic_bezier_in_flash.htm
  • Constructor Details

    • CubicBezierApproximator

      private CubicBezierApproximator()
  • Method Details

    • fixedMidPointApproximation

      public static double[][] fixedMidPointApproximation(double[] cubicControlPointCoords)
      This method will take in an array containing the x and y coordinates of the four control points that describe the cubic bezier curve to be approximated using the fixed mid point approximation. The curve will be approximated using four quadratic bezier curves the points for which will be returned in a two dimensional array, with each array within that containing the points for a single quadratic curve. The returned data will not include the start point for any of the curves; the first point passed in to this method should already have been set as the current position and will be the assumed start of the first curve.
      Parameters:
      cubicControlPointCoords - an array containing the x and y coordinates of the four control points.
      Returns:
      an array of arrays containing the x and y coordinates of the quadratic curves that approximate the original supplied cubic bezier curve.
    • movePoint

      private static Point2D.Double movePoint(Point2D point, double dx, double dy)
    • getMidPoint

      private static Point2D getMidPoint(Point2D p0, Point2D p1)
      This method will calculate the coordinates of a point half way along a segment [P0, P1]
      Parameters:
      p0 - - The point describing the start of the segment.
      p1 - - The point describing the end of the segment.
      Returns:
      a Point object describing the coordinates of the calculated point on the segment.
    • getPointOnSegment

      private static Point2D getPointOnSegment(Point2D p0, Point2D p1, double ratio)
      This method will calculate the coordinates of a point on a segment [P0, P1] whose distance along the segment [P0, P1] from P0, is the given ratio of the length the [P0, P1] segment.
      Parameters:
      p0 - The point describing the start of the segment.
      p1 - The point describing the end of the segment.
      ratio - The distance of the point being calculated from P0 as a ratio of the segment length.
      Returns:
      a Point object describing the coordinates of the calculated point on the segment.