/** Simple linear interpolation derivative * @param out The {@link Vector} to set to the result. * @param t The location (ranging 0..1) on the line. * @param p0 The start point. * @param p1 The end point. * @param tmp A temporary vector to be used by the calculation. * @return The value specified by out for chaining */ public static <T extends Vector<T>> T linear_derivative (final T out, final float t, final T p0, final T p1, final T tmp) { // B1'(t) = p1-p0 return out.set(p1).sub(p0); }
/** Simple linear interpolation derivative * @param out The {@link Vector} to set to the result. * @param t The location (ranging 0..1) on the line. * @param p0 The start point. * @param p1 The end point. * @param tmp A temporary vector to be used by the calculation. * @return The value specified by out for chaining */ public static <T extends Vector<T>> T linear_derivative (final T out, final float t, final T p0, final T p1, final T tmp) { // B1'(t) = p1-p0 return out.set(p1).sub(p0); }
/** Simple linear interpolation * @param out The {@link Vector} to set to the result. * @param t The location (ranging 0..1) on the line. * @param p0 The start point. * @param p1 The end point. * @param tmp A temporary vector to be used by the calculation. * @return The value specified by out for chaining */ public static <T extends Vector<T>> T linear (final T out, final float t, final T p0, final T p1, final T tmp) { // B1(t) = p0 + (p1-p0)*t return out.set(p0).scl(1f - t).add(tmp.set(p1).scl(t)); // Could just use lerp... }
/** Simple linear interpolation * @param out The {@link Vector} to set to the result. * @param t The location (ranging 0..1) on the line. * @param p0 The start point. * @param p1 The end point. * @param tmp A temporary vector to be used by the calculation. * @return The value specified by out for chaining */ public static <T extends Vector<T>> T linear (final T out, final float t, final T p0, final T p1, final T tmp) { // B1(t) = p0 + (p1-p0)*t return out.set(p0).scl(1f - t).add(tmp.set(p1).scl(t)); // Could just use lerp... }
/** Quadratic Bezier curve * @param out The {@link Vector} to set to the result. * @param t The location (ranging 0..1) on the curve. * @param p0 The first bezier point. * @param p1 The second bezier point. * @param p2 The third bezier point. * @param tmp A temporary vector to be used by the calculation. * @return The value specified by out for chaining */ public static <T extends Vector<T>> T quadratic (final T out, final float t, final T p0, final T p1, final T p2, final T tmp) { // B2(t) = (1 - t) * (1 - t) * p0 + 2 * (1-t) * t * p1 + t*t*p2 final float dt = 1f - t; return out.set(p0).scl(dt * dt).add(tmp.set(p1).scl(2 * dt * t)).add(tmp.set(p2).scl(t * t)); }
/** Quadratic Bezier curve * @param out The {@link Vector} to set to the result. * @param t The location (ranging 0..1) on the curve. * @param p0 The first bezier point. * @param p1 The second bezier point. * @param p2 The third bezier point. * @param tmp A temporary vector to be used by the calculation. * @return The value specified by out for chaining */ public static <T extends Vector<T>> T quadratic (final T out, final float t, final T p0, final T p1, final T p2, final T tmp) { // B2(t) = (1 - t) * (1 - t) * p0 + 2 * (1-t) * t * p1 + t*t*p2 final float dt = 1f - t; return out.set(p0).scl(dt * dt).add(tmp.set(p1).scl(2 * dt * t)).add(tmp.set(p2).scl(t * t)); }
@Override public float approxLength (int samples) { float tempLength = 0; for(int i = 0; i < samples; ++i) { tmp2.set(tmp3); valueAt(tmp3, (i)/((float)samples-1)); if(i>0) tempLength += tmp2.dst(tmp3); } return tempLength; } }
@Override public float approxLength (int samples) { float tempLength = 0; for (int i = 0; i < samples; ++i) { tmp2.set(tmp3); valueAt(tmp3, (i) / ((float)samples - 1)); if (i > 0) tempLength += tmp2.dst(tmp3); } return tempLength; } }
@Override public float approxLength (int samples) { float tempLength = 0; for (int i = 0; i < samples; ++i) { tmp2.set(tmp3); valueAt(tmp3, (i) / ((float)samples - 1)); if (i > 0) tempLength += tmp2.dst(tmp3); } return tempLength; } }
@Override public float approxLength (int samples) { float tempLength = 0; for (int i = 0; i < samples; ++i) { tmp2.set(tmp3); valueAt(tmp3, (i) / ((float)samples - 1)); if (i > 0) tempLength += tmp2.dst(tmp3); } return tempLength; } }
@Override public float approxLength (int samples) { float tempLength = 0; for(int i = 0; i < samples; ++i) { tmp2.set(tmp3); valueAt(tmp3, (i)/((float)samples-1)); if(i>0) tempLength += tmp2.dst(tmp3); } return tempLength; } }
@Override public float approxLength (int samples) { float tempLength = 0; for (int i = 0; i < samples; ++i) { tmp2.set(tmp3); valueAt(tmp3, (i) / ((float)samples - 1)); if (i > 0) tempLength += tmp2.dst(tmp3); } return tempLength; } }
/** Cubic Bezier curve * @param out The {@link Vector} to set to the result. * @param t The location (ranging 0..1) on the curve. * @param p0 The first bezier point. * @param p1 The second bezier point. * @param p2 The third bezier point. * @param p3 The fourth bezier point. * @param tmp A temporary vector to be used by the calculation. * @return The value specified by out for chaining */ public static <T extends Vector<T>> T cubic (final T out, final float t, final T p0, final T p1, final T p2, final T p3, final T tmp) { // B3(t) = (1-t) * (1-t) * (1-t) * p0 + 3 * (1-t) * (1-t) * t * p1 + 3 * (1-t) * t * t * p2 + t * t * t * p3 final float dt = 1f - t; final float dt2 = dt * dt; final float t2 = t * t; return out.set(p0).scl(dt2 * dt).add(tmp.set(p1).scl(3 * dt2 * t)).add(tmp.set(p2).scl(3 * dt * t2)) .add(tmp.set(p3).scl(t2 * t)); }
/** Calculates the catmullrom value for the given span (i) at the given position (u). * @param out The Vector to set to the result. * @param i The span (0<=i<spanCount) spanCount = continuous ? points.length : points.length - degree * @param u The position (0<=u<=1) on the span * @param points The control points * @param continuous If true the b-spline restarts at 0 when reaching 1 * @param tmp A temporary vector used for the calculation * @return The value of out */ public static <T extends Vector<T>> T calculate (final T out, final int i, final float u, final T[] points, final boolean continuous, final T tmp) { final int n = points.length; final float u2 = u * u; final float u3 = u2 * u; out.set(points[i]).scl(1.5f * u3 - 2.5f * u2 + 1.0f); if (continuous || i > 0) out.add(tmp.set(points[(n + i - 1) % n]).scl(-0.5f * u3 + u2 - 0.5f * u)); if (continuous || i < (n - 1)) out.add(tmp.set(points[(i + 1) % n]).scl(-1.5f * u3 + 2f * u2 + 0.5f * u)); if (continuous || i < (n - 2)) out.add(tmp.set(points[(i + 2) % n]).scl(0.5f * u3 - 0.5f * u2)); return out; }
/** Cubic Bezier curve * @param out The {@link Vector} to set to the result. * @param t The location (ranging 0..1) on the curve. * @param p0 The first bezier point. * @param p1 The second bezier point. * @param p2 The third bezier point. * @param p3 The fourth bezier point. * @param tmp A temporary vector to be used by the calculation. * @return The value specified by out for chaining */ public static <T extends Vector<T>> T cubic (final T out, final float t, final T p0, final T p1, final T p2, final T p3, final T tmp) { // B3(t) = (1-t) * (1-t) * (1-t) * p0 + 3 * (1-t) * (1-t) * t * p1 + 3 * (1-t) * t * t * p2 + t * t * t * p3 final float dt = 1f - t; final float dt2 = dt * dt; final float t2 = t * t; return out.set(p0).scl(dt2 * dt).add(tmp.set(p1).scl(3 * dt2 * t)).add(tmp.set(p2).scl(3 * dt * t2)) .add(tmp.set(p3).scl(t2 * t)); }
/** Calculates the cubic b-spline value for the given span (i) at the given position (u). * @param out The Vector to set to the result. * @param i The span (0<=i<spanCount) spanCount = continuous ? points.length : points.length - 3 (cubic degree) * @param u The position (0<=u<=1) on the span * @param points The control points * @param continuous If true the b-spline restarts at 0 when reaching 1 * @param tmp A temporary vector used for the calculation * @return The value of out */ public static <T extends Vector<T>> T cubic (final T out, final int i, final float u, final T[] points, final boolean continuous, final T tmp) { final int n = points.length; final float dt = 1f - u; final float t2 = u * u; final float t3 = t2 * u; out.set(points[i]).scl((3f * t3 - 6f * t2 + 4f) * d6); if (continuous || i > 0) out.add(tmp.set(points[(n + i - 1) % n]).scl(dt * dt * dt * d6)); if (continuous || i < (n - 1)) out.add(tmp.set(points[(i + 1) % n]).scl((-3f * t3 + 3f * t2 + 3f * u + 1f) * d6)); if (continuous || i < (n - 2)) out.add(tmp.set(points[(i + 2) % n]).scl(t3 * d6)); return out; }
/** Cubic Bezier curve derivative * @param out The {@link Vector} to set to the result. * @param t The location (ranging 0..1) on the curve. * @param p0 The first bezier point. * @param p1 The second bezier point. * @param p2 The third bezier point. * @param p3 The fourth bezier point. * @param tmp A temporary vector to be used by the calculation. * @return The value specified by out for chaining */ public static <T extends Vector<T>> T cubic_derivative (final T out, final float t, final T p0, final T p1, final T p2, final T p3, final T tmp) { // B3'(t) = 3 * (1-t) * (1-t) * (p1 - p0) + 6 * (1 - t) * t * (p2 - p1) + 3 * t * t * (p3 - p2) final float dt = 1f - t; final float dt2 = dt * dt; final float t2 = t * t; return out.set(p1).sub(p0).scl(dt2 * 3).add(tmp.set(p2).sub(p1).scl(dt * t * 6)).add(tmp.set(p3).sub(p2).scl(t2 * 3)); }
/** Cubic Bezier curve derivative * @param out The {@link Vector} to set to the result. * @param t The location (ranging 0..1) on the curve. * @param p0 The first bezier point. * @param p1 The second bezier point. * @param p2 The third bezier point. * @param p3 The fourth bezier point. * @param tmp A temporary vector to be used by the calculation. * @return The value specified by out for chaining */ public static <T extends Vector<T>> T cubic_derivative (final T out, final float t, final T p0, final T p1, final T p2, final T p3, final T tmp) { // B3'(t) = 3 * (1-t) * (1-t) * (p1 - p0) + 6 * (1 - t) * t * (p2 - p1) + 3 * t * t * (p3 - p2) final float dt = 1f - t; final float dt2 = dt * dt; final float t2 = t * t; return out.set(p1).sub(p0).scl(dt2 * 3).add(tmp.set(p2).sub(p1).scl(dt * t * 6)).add(tmp.set(p3).sub(p2).scl(t2 * 3)); }
/** Quadratic Bezier curve derivative * @param out The {@link Vector} to set to the result. * @param t The location (ranging 0..1) on the curve. * @param p0 The first bezier point. * @param p1 The second bezier point. * @param p2 The third bezier point. * @param tmp A temporary vector to be used by the calculation. * @return The value specified by out for chaining */ public static <T extends Vector<T>> T quadratic_derivative (final T out, final float t, final T p0, final T p1, final T p2, final T tmp) { // B2'(t) = 2 * (1 - t) * (p1 - p0) + 2 * t * (p2 - p1) final float dt = 1f - t; return out.set(p1).sub(p0).scl(2).scl(1 - t).add(tmp.set(p2).sub(p1).scl(t).scl(2)); }
/** Quadratic Bezier curve derivative * @param out The {@link Vector} to set to the result. * @param t The location (ranging 0..1) on the curve. * @param p0 The first bezier point. * @param p1 The second bezier point. * @param p2 The third bezier point. * @param tmp A temporary vector to be used by the calculation. * @return The value specified by out for chaining */ public static <T extends Vector<T>> T quadratic_derivative (final T out, final float t, final T p0, final T p1, final T p2, final T tmp) { // B2'(t) = 2 * (1 - t) * (p1 - p0) + 2 * t * (p2 - p1) final float dt = 1f - t; return out.set(p1).sub(p0).scl(2).scl(1 - t).add(tmp.set(p2).sub(p1).scl(t).scl(2)); }