public Segment getSegment(double t0, double t1) { double dt = t1-t0; Point2D.Double np1 = eval(t0); Point2D.Double dp1 = evalDt(t0); Point2D.Double np2 = new Point2D.Double(np1.x+dt*dp1.x/3, np1.y+dt*dp1.y/3); Point2D.Double np4 = eval(t1); Point2D.Double dp4 = evalDt(t1); Point2D.Double np3 = new Point2D.Double(np4.x-dt*dp4.x/3, np4.y-dt*dp4.y/3); return new Cubic(np1, np2, np3, np4); }
public double getLength() { return getLength(0.000001); }
public double minX() { double [] minMax = {0, 0}; getMinMax(p1.x, p2.x, p3.x, p4.x, minMax); return minMax[0]; } public double maxX() {
/** * Subdivides this Cubic curve into two curves at given t. * @param c0 if non-null contains portion of curve from 0->t. * @param c1 if non-null contains portion of curve from t->1. */ public void subdivide(double t, Cubic c0, Cubic c1) { if ((c0 == null) && (c1 == null)) return; Point2D.Double np = eval(t); Point2D.Double npd = evalDt(t); if (c0 != null) { c0.p1.x = p1.x; c0.p1.y = p1.y; c0.p2.x = p1.x + (p2.x-p1.x)*t; c0.p2.y = p1.y + (p2.y-p1.y)*t; c0.p3.x = np.x-npd.x*t/3; c0.p3.y = np.y-npd.y*t/3; c0.p4.x = np.x; c0.p4.y = np.y; } if (c1 != null) { c1.p1.x = np.x; c1.p1.y = np.y; c1.p2.x = np.x+(npd.x*(1-t)/3); c1.p2.y = np.y+(npd.y*(1-t)/3); c1.p3.x = p4.x + (p3.x-p4.x)*(1-t); c1.p3.y = p4.y + (p3.y-p4.y)*(1-t); c1.p4.x = p4.x; c1.p4.y = p4.y; } }
public Object clone() { return new Cubic(new Point2D.Double(p1.x, p1.y), new Point2D.Double(p2.x, p2.y), new Point2D.Double(p3.x, p3.y), new Point2D.Double(p4.x, p4.y)); }
for (;;) { float t = (min + max) / 2; p = c.eval(t); double x = p.getX(); if (Math.abs(x - interpolation) < tolerance) {
/** * Subdivides this Cubic curve into two curves at given t. * @param s0 if non-null contains portion of curve from 0->t. * @param s1 if non-null contains portion of curve from t->1. */ public void subdivide(double t, Segment s0, Segment s1) { Cubic c0=null, c1=null; if (s0 instanceof Cubic) c0 = (Cubic)s0; if (s1 instanceof Cubic) c1 = (Cubic)s1; subdivide(t, c0, c1); }
public double getLength(double maxErr) { double dx, dy; dx = p2.x-p1.x; dy = p2.y-p1.y; double leftLegLen = Math.sqrt(dx*dx+dy*dy); dx = p4.x-p3.x; dy = p4.y-p3.y; double rightLegLen = Math.sqrt(dx*dx+dy*dy); dx = p3.x-p2.x; dy = p3.y-p2.y; double crossLegLen = Math.sqrt(dx*dx+dy*dy); double eps = maxErr*(leftLegLen+rightLegLen+crossLegLen); return subLength(leftLegLen, rightLegLen, eps); }
public Object clone() { return new Cubic(new Point2D.Double(p1.x, p1.y), new Point2D.Double(p2.x, p2.y), new Point2D.Double(p3.x, p3.y), new Point2D.Double(p4.x, p4.y)); }
/** * Subdivides this Cubic curve into two curves at given t. * @param c0 if non-null contains portion of curve from 0->t. * @param c1 if non-null contains portion of curve from t->1. */ public void subdivide(double t, Cubic c0, Cubic c1) { if ((c0 == null) && (c1 == null)) return; Point2D.Double np = eval(t); Point2D.Double npd = evalDt(t); if (c0 != null) { c0.p1.x = p1.x; c0.p1.y = p1.y; c0.p2.x = p1.x + (p2.x-p1.x)*t; c0.p2.y = p1.y + (p2.y-p1.y)*t; c0.p3.x = np.x-npd.x*t/3; c0.p3.y = np.y-npd.y*t/3; c0.p4.x = np.x; c0.p4.y = np.y; } if (c1 != null) { c1.p1.x = np.x; c1.p1.y = np.y; c1.p2.x = np.x+(npd.x*(1-t)/3); c1.p2.y = np.y+(npd.y*(1-t)/3); c1.p3.x = p4.x + (p3.x-p4.x)*(1-t); c1.p3.y = p4.y + (p3.y-p4.y)*(1-t); c1.p4.x = p4.x; c1.p4.y = p4.y; } }
for (;;) { float t = (min + max) / 2; p = c.eval(t); double x = p.getX(); if (Math.abs(x - interpolation) < tolerance) {
/** * Subdivides this Cubic curve into two curves at t = 0.5. * can be done with getSegment but this is more efficent. * @param s0 if non-null contains portion of curve from 0->.5 * @param s1 if non-null contains portion of curve from .5->1 */ public void subdivide(Segment s0, Segment s1) { Cubic c0=null, c1=null; if (s0 instanceof Cubic) c0 = (Cubic)s0; if (s1 instanceof Cubic) c1 = (Cubic)s1; subdivide(c0, c1); }
public double getLength(double maxErr) { double dx, dy; dx = p2.x-p1.x; dy = p2.y-p1.y; double leftLegLen = Math.sqrt(dx*dx+dy*dy); dx = p4.x-p3.x; dy = p4.y-p3.y; double rightLegLen = Math.sqrt(dx*dx+dy*dy); dx = p3.x-p2.x; dy = p3.y-p2.y; double crossLegLen = Math.sqrt(dx*dx+dy*dy); double eps = maxErr*(leftLegLen+rightLegLen+crossLegLen); return subLength(leftLegLen, rightLegLen, eps); }
public Segment getSegment(double t0, double t1) { double dt = t1-t0; Point2D.Double np1 = eval(t0); Point2D.Double dp1 = evalDt(t0); Point2D.Double np2 = new Point2D.Double(np1.x+dt*dp1.x/3, np1.y+dt*dp1.y/3); Point2D.Double np4 = eval(t1); Point2D.Double dp4 = evalDt(t1); Point2D.Double np3 = new Point2D.Double(np4.x-dt*dp4.x/3, np4.y-dt*dp4.y/3); return new Cubic(np1, np2, np3, np4); }
public Segment reverse() { return new Cubic(new Point2D.Double(p4.x, p4.y), new Point2D.Double(p3.x, p3.y), new Point2D.Double(p2.x, p2.y), new Point2D.Double(p1.x, p1.y)); }
/** * Subdivides this Cubic curve into two curves at given t. * @param c0 if non-null contains portion of curve from 0->t. * @param c1 if non-null contains portion of curve from t->1. */ public void subdivide(double t, Cubic c0, Cubic c1) { if ((c0 == null) && (c1 == null)) return; Point2D.Double np = eval(t); Point2D.Double npd = evalDt(t); if (c0 != null) { c0.p1.x = p1.x; c0.p1.y = p1.y; c0.p2.x = p1.x + (p2.x-p1.x)*t; c0.p2.y = p1.y + (p2.y-p1.y)*t; c0.p3.x = np.x-npd.x*t/3; c0.p3.y = np.y-npd.y*t/3; c0.p4.x = np.x; c0.p4.y = np.y; } if (c1 != null) { c1.p1.x = np.x; c1.p1.y = np.y; c1.p2.x = np.x+(npd.x*(1-t)/3); c1.p2.y = np.y+(npd.y*(1-t)/3); c1.p3.x = p4.x + (p3.x-p4.x)*(1-t); c1.p3.y = p4.y + (p3.y-p4.y)*(1-t); c1.p4.x = p4.x; c1.p4.y = p4.y; } }
public double minX() { double [] minMax = {0, 0}; getMinMax(p1.x, p2.x, p3.x, p4.x, minMax); return minMax[0]; } public double maxX() {