/**Interpolate a spline between at least 4 control points following the Bezier equation. * here is the interpolation matrix * m = [ -1.0 3.0 -3.0 1.0 ] * [ 3.0 -6.0 3.0 0.0 ] * [ -3.0 3.0 0.0 0.0 ] * [ 1.0 0.0 0.0 0.0 ] * where T is the tension of the curve * the result is a value between p1 and p3, t=0 for p1, t=1 for p3 * @param u value from 0 to 1 * @param p0 control point 0 * @param p1 control point 1 * @param p2 control point 2 * @param p3 control point 3 * @return Bezier interpolation */ public static Vector3f interpolateBezier(float u, Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3) { return interpolateBezier(u, p0, p1, p2, p3, null); }
/**Interpolate a spline between at least 4 control points following the Bezier equation. * here is the interpolation matrix * m = [ -1.0 3.0 -3.0 1.0 ] * [ 3.0 -6.0 3.0 0.0 ] * [ -3.0 3.0 0.0 0.0 ] * [ 1.0 0.0 0.0 0.0 ] * where T is the tension of the curve * the result is a value between p1 and p3, t=0 for p1, t=1 for p3 * @param u value from 0 to 1 * @param p0 control point 0 * @param p1 control point 1 * @param p2 control point 2 * @param p3 control point 3 * @param store a Vector3f to store the result * @return Bezier interpolation */ public static Vector3f interpolateBezier(float u, Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3, Vector3f store) { if (store == null) { store = new Vector3f(); } store.x = interpolateBezier(u, p0.x, p1.x, p2.x, p3.x); store.y = interpolateBezier(u, p0.y, p1.y, p2.y, p3.y); store.z = interpolateBezier(u, p0.z, p1.z, p2.z, p3.z); return store; }
/** * Interpolate a position on the spline * @param value a value from 0 to 1 that represent the position between the current control point and the next one * @param currentControlPoint the current control point * @param store a vector to store the result (use null to create a new one that will be returned by the method) * @return the position */ public Vector3f interpolate(float value, int currentControlPoint, Vector3f store) { if (store == null) { store = new Vector3f(); } switch (type) { case CatmullRom: FastMath.interpolateCatmullRom(value, curveTension, CRcontrolPoints.get(currentControlPoint), CRcontrolPoints.get(currentControlPoint + 1), CRcontrolPoints.get(currentControlPoint + 2), CRcontrolPoints.get(currentControlPoint + 3), store); break; case Linear: FastMath.interpolateLinear(value, controlPoints.get(currentControlPoint), controlPoints.get(currentControlPoint + 1), store); break; case Bezier: FastMath.interpolateBezier(value, controlPoints.get(currentControlPoint), controlPoints.get(currentControlPoint + 1), controlPoints.get(currentControlPoint + 2), controlPoints.get(currentControlPoint + 3), store); break; case Nurb: CurveAndSurfaceMath.interpolateNurbs(value, this, store); break; default: break; } return store; }
/** * Compute the length on a Bezier spline between control points 1 and 2. * @param p0 control point 0 * @param p1 control point 1 * @param p2 control point 2 * @param p3 control point 3 * @return the length of the segment */ public static float getBezierP1toP2Length(Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3) { float delta = 0.02f, t = 0.0f, result = 0.0f; Vector3f v1 = p0.clone(), v2 = new Vector3f(); while (t <= 1.0f) { FastMath.interpolateBezier(t, p0, p1, p2, p3, v2); result += v1.subtractLocal(v2).length(); v1.set(v2); t += delta; } return result; }
/**Interpolate a spline between at least 4 control points following the Bezier equation. * here is the interpolation matrix * m = [ -1.0 3.0 -3.0 1.0 ] * [ 3.0 -6.0 3.0 0.0 ] * [ -3.0 3.0 0.0 0.0 ] * [ 1.0 0.0 0.0 0.0 ] * where T is the tension of the curve * the result is a value between p1 and p3, t=0 for p1, t=1 for p3 * @param u value from 0 to 1 * @param p0 control point 0 * @param p1 control point 1 * @param p2 control point 2 * @param p3 control point 3 * @return Bezier interpolation */ public static Vector3f interpolateBezier(float u, Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3) { return interpolateBezier(u, p0, p1, p2, p3, null); }
/**Interpolate a spline between at least 4 control points following the Bezier equation. * here is the interpolation matrix * m = [ -1.0 3.0 -3.0 1.0 ] * [ 3.0 -6.0 3.0 0.0 ] * [ -3.0 3.0 0.0 0.0 ] * [ 1.0 0.0 0.0 0.0 ] * where T is the tension of the curve * the result is a value between p1 and p3, t=0 for p1, t=1 for p3 * @param u value from 0 to 1 * @param p0 control point 0 * @param p1 control point 1 * @param p2 control point 2 * @param p3 control point 3 * @return Bezier interpolation */ public static Vector3f interpolateBezier(float u, Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3) { return interpolateBezier(u, p0, p1, p2, p3, null); }
/**Interpolate a spline between at least 4 control points following the Bezier equation. * here is the interpolation matrix * m = [ -1.0 3.0 -3.0 1.0 ] * [ 3.0 -6.0 3.0 0.0 ] * [ -3.0 3.0 0.0 0.0 ] * [ 1.0 0.0 0.0 0.0 ] * where T is the tension of the curve * the result is a value between p1 and p3, t=0 for p1, t=1 for p3 * @param u value from 0 to 1 * @param p0 control point 0 * @param p1 control point 1 * @param p2 control point 2 * @param p3 control point 3 * @param store a Vector3f to store the result * @return Bezier interpolation */ public static Vector3f interpolateBezier(float u, Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3, Vector3f store) { if (store == null) { store = new Vector3f(); } store.x = interpolateBezier(u, p0.x, p1.x, p2.x, p3.x); store.y = interpolateBezier(u, p0.y, p1.y, p2.y, p3.y); store.z = interpolateBezier(u, p0.z, p1.z, p2.z, p3.z); return store; }
/**Interpolate a spline between at least 4 control points following the Bezier equation. * here is the interpolation matrix * m = [ -1.0 3.0 -3.0 1.0 ] * [ 3.0 -6.0 3.0 0.0 ] * [ -3.0 3.0 0.0 0.0 ] * [ 1.0 0.0 0.0 0.0 ] * where T is the tension of the curve * the result is a value between p1 and p3, t=0 for p1, t=1 for p3 * @param u value from 0 to 1 * @param p0 control point 0 * @param p1 control point 1 * @param p2 control point 2 * @param p3 control point 3 * @param store a Vector3f to store the result * @return Bezier interpolation */ public static Vector3f interpolateBezier(float u, Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3, Vector3f store) { if (store == null) { store = new Vector3f(); } store.x = interpolateBezier(u, p0.x, p1.x, p2.x, p3.x); store.y = interpolateBezier(u, p0.y, p1.y, p2.y, p3.y); store.z = interpolateBezier(u, p0.z, p1.z, p2.z, p3.z); return store; }
/** * Interpolate a position on the spline * @param value a value from 0 to 1 that represent the position between the current control point and the next one * @param currentControlPoint the current control point * @param store a vector to store the result (use null to create a new one that will be returned by the method) * @return the position */ public Vector3f interpolate(float value, int currentControlPoint, Vector3f store) { if (store == null) { store = new Vector3f(); } switch (type) { case CatmullRom: FastMath.interpolateCatmullRom(value, curveTension, CRcontrolPoints.get(currentControlPoint), CRcontrolPoints.get(currentControlPoint + 1), CRcontrolPoints.get(currentControlPoint + 2), CRcontrolPoints.get(currentControlPoint + 3), store); break; case Linear: FastMath.interpolateLinear(value, controlPoints.get(currentControlPoint), controlPoints.get(currentControlPoint + 1), store); break; case Bezier: FastMath.interpolateBezier(value, controlPoints.get(currentControlPoint), controlPoints.get(currentControlPoint + 1), controlPoints.get(currentControlPoint + 2), controlPoints.get(currentControlPoint + 3), store); break; case Nurb: CurveAndSurfaceMath.interpolateNurbs(value, this, store); break; default: break; } return store; }
/** * Iterpolate a position on the spline * @param value a value from 0 to 1 that represent the postion between the curent control point and the next one * @param currentControlPoint the current control point * @param store a vector to store the result (use null to create a new one that will be returned by the method) * @return the position */ public Vector3f interpolate(float value, int currentControlPoint, Vector3f store) { if (store == null) { store = new Vector3f(); } switch (type) { case CatmullRom: FastMath.interpolateCatmullRom(value, curveTension, CRcontrolPoints.get(currentControlPoint), CRcontrolPoints.get(currentControlPoint + 1), CRcontrolPoints.get(currentControlPoint + 2), CRcontrolPoints.get(currentControlPoint + 3), store); break; case Linear: FastMath.interpolateLinear(value, controlPoints.get(currentControlPoint), controlPoints.get(currentControlPoint + 1), store); break; case Bezier: FastMath.interpolateBezier(value, controlPoints.get(currentControlPoint), controlPoints.get(currentControlPoint + 1), controlPoints.get(currentControlPoint + 2), controlPoints.get(currentControlPoint + 3), store); break; case Nurb: CurveAndSurfaceMath.interpolateNurbs(value, this, store); break; default: break; } return store; }
/** * Compute the length on a Bezier spline between control points 1 and 2. * @param p0 control point 0 * @param p1 control point 1 * @param p2 control point 2 * @param p3 control point 3 * @return the length of the segment */ public static float getBezierP1toP2Length(Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3) { float delta = 0.02f, t = 0.0f, result = 0.0f; Vector3f v1 = p0.clone(), v2 = new Vector3f(); while (t <= 1.0f) { FastMath.interpolateBezier(t, p0, p1, p2, p3, v2); result += v1.subtractLocal(v2).length(); v1.set(v2); t += delta; } return result; }
/** * Compute the lenght on a bezier spline between control point 1 and 2 * @param p0 control point 0 * @param p1 control point 1 * @param p2 control point 2 * @param p3 control point 3 * @return the length of the segment */ public static float getBezierP1toP2Length(Vector3f p0, Vector3f p1, Vector3f p2, Vector3f p3) { float delta = 0.02f, t = 0.0f, result = 0.0f; Vector3f v1 = p0.clone(), v2 = new Vector3f(); while (t <= 1.0f) { FastMath.interpolateBezier(t, p0, p1, p2, p3, v2); result += v1.subtractLocal(v2).length(); v1.set(v2); t += delta; } return result; }