/** * Calculates the length of this curve. * <p> * <strong>Important note:</strong><br /> * To calculate the length of a curve it must be interpolated (hence the steps parameter), this method will do this * EVERY time it's called (creating a lot of garbage vectors in the process). This has been done for the sake of * keeping this class simple and the code as readable as possible. Therefore the length should be manually cached * somewhere in your code if it is going to be used repeatedly. * </p> * * @param steps * The number of iterations to perform between control points, the higher this number the more accurate * the returned result will be. * @return The length of this curve. * @see #getApproximateLength(int, int, int) */ public double getApproximateLength(final int steps) { return getApproximateLength(1, getControlPointCount() - 2, steps); }
/** * @return The number of control points in this curve. */ public int getControlPointCount() { return getControlPoints().size(); }
/** * Creates a new instance of <code>Curve</code>. * * @param controlPoints * see {@link #setControlPoints(List)} * @param spline * see {@link #setSpline(Spline)} */ public Curve(final List<ReadOnlyVector3> controlPoints, final Spline spline) { super(); setControlPoints(controlPoints); setSpline(spline); }
/** * Creates a new <code>Line</code> from the control points making up this curve. It will have the name * <code>curve</code>, no normals, colour or texture, these can be added to the returned line if needed. * * @param steps * The number of iterations to perform between control points, the higher this number the smoother the * returned line will be, but it will also contain more vertices, must be greater than one. * @return A <code>Line</code> representing this curve, will not be <code>null</code>. */ public Line toRenderableLine(final int steps) { return toRenderableLine(1, getControlPointCount() - 2, steps); }
/** * Creates a new <code>Point</code> from the control points making up this curve. It will have the name * <code>point</code>, no normals, colour or texture, these can be added to the returned point if needed. * * @param steps * The number of iterations to perform between control points, the higher this number the more points * will be shown, but it will also contain more vertices, must be greater than one. Use two to just show * the actual control points set for the curve. * @return A <code>Point</code> containing all the curve points, will not be <code>null</code>. */ public Point toRenderablePoint(final int steps) { return toRenderablePoint(1, getControlPointCount() - 2, steps); }
/** * Interpolates between the control points at the given indices. * * @param start * The index of the control point to start from. * @param end * The index of the control point to end at. * @param t * Should be between zero and one. Zero will return point <code>start</code> while one will return * <code>end</code>, a value in between will return an interpolated vector between the two. * @param result * The result of the interpolation will be stored in this vector. * @return The result vector as a convenience. */ public ReadOnlyVector3 interpolate(final int start, final int end, final double t, final Vector3 result) { if (start <= 0) { throw new IllegalArgumentException("start must be > 0! start=" + start); } if (end >= (getControlPointCount() - 1)) { throw new IllegalArgumentException("end must be < " + (getControlPointCount() - 1) + "! end=" + end); } final List<ReadOnlyVector3> points = getControlPoints(); return getSpline().interpolate(points.get(start - 1), points.get(start), points.get(end), points.get(end + 1), t, result); }
final Vector3 previous = Vector3.fetchTempInstance(); final int loopStart = reverse ? (_curve.getControlPointCount() - 2) : 1; final double tStep = InterpolationController.DELTA_MAX / step; double length = 0; previous.set(_curve.getControlPoints().get(i)); _curve.interpolate(startIndex, endIndex, t, target);
/** * Creates a new <code>Point</code> from the given control point indices. It will have the name <code>point</code>, * no normals, colour or texture, these can be added to the returned point if needed. * * @param start * The index of the control point to start from, must be greater than or equal to one and less than * <code>end</code>. * @param end * The index of the control point to end with, must be less than {@link #getControlPointCount() * controlPointCount} minus one and greater than <code>start</code>. * @param steps * The number of iterations to perform between control points, the higher this number the more points * will be shown, but it will also contain more vertices, must be greater than one. * @return A <code>Point</code> containing all the curve points, will not be <code>null</code>. */ public Point toRenderablePoint(final int start, final int end, final int steps) { final Vector3[] points = toVector3(start, end, steps); return new Point("point", points, null, null, null); }
@Override protected Vector3 interpolateVectors(final ReadOnlyVector3 from, final ReadOnlyVector3 to, final double delta, final Vector3 target) { assert (null != from) : "parameter 'from' can not be null"; assert (null != to) : "parameter 'to' can not be null"; final ReadOnlyVector3 p0 = getControlPointStart(); final ReadOnlyVector3 p3 = getCotnrolPointEnd(); final Spline spline = getCurve().getSpline(); return spline.interpolate(p0, from, to, p3, delta, target); }
private boolean continueLoop(final int i, final boolean reverse) { return (reverse ? i > 0 : i < _curve.getControlPointCount() - 2); }
/** * Interpolates between the control points at the given indices. * * @param start * The index of the control point to start from. * @param end * The index of the control point to end at. * @param t * Should be between zero and one. Zero will return point <code>start</code> while one will return * <code>end</code>, a value in between will return an interpolated vector between the two. * @return The interpolated vector. */ public ReadOnlyVector3 interpolate(final int start, final int end, final double t) { return interpolate(start, end, t, new Vector3()); }
/** * Interpolates between the control points at the given indices. * * @param start * The index of the control point to start from. * @param end * The index of the control point to end at. * @param t * Should be between zero and one. Zero will return point <code>start</code> while one will return * <code>end</code>, a value in between will return an interpolated vector between the two. * @param result * The result of the interpolation will be stored in this vector. * @return The result vector as a convenience. */ public ReadOnlyVector3 interpolate(final int start, final int end, final double t, final Vector3 result) { if (start <= 0) { throw new IllegalArgumentException("start must be > 0! start=" + start); } if (end >= (getControlPointCount() - 1)) { throw new IllegalArgumentException("end must be < " + (getControlPointCount() - 1) + "! end=" + end); } final List<ReadOnlyVector3> points = getControlPoints(); return getSpline().interpolate(points.get(start - 1), points.get(start), points.get(end), points.get(end + 1), t, result); }
final Vector3 previous = Vector3.fetchTempInstance(); final int loopStart = reverse ? (_curve.getControlPointCount() - 2) : 1; final double tStep = InterpolationController.DELTA_MAX / step; double length = 0; previous.set(_curve.getControlPoints().get(i)); _curve.interpolate(startIndex, endIndex, t, target);
/** * Creates a new <code>Line</code> from the control points making up this curve. It will have the name * <code>curve</code>, no normals, colour or texture, these can be added to the returned line if needed. * * @param steps * The number of iterations to perform between control points, the higher this number the smoother the * returned line will be, but it will also contain more vertices, must be greater than one. * @return A <code>Line</code> representing this curve, will not be <code>null</code>. */ public Line toRenderableLine(final int steps) { return toRenderableLine(1, getControlPointCount() - 2, steps); }
/** * Creates a new <code>Point</code> from the control points making up this curve. It will have the name * <code>point</code>, no normals, colour or texture, these can be added to the returned point if needed. * * @param steps * The number of iterations to perform between control points, the higher this number the more points * will be shown, but it will also contain more vertices, must be greater than one. Use two to just show * the actual control points set for the curve. * @return A <code>Point</code> containing all the curve points, will not be <code>null</code>. */ public Point toRenderablePoint(final int steps) { return toRenderablePoint(1, getControlPointCount() - 2, steps); }
/** * Creates a new <code>Point</code> from the given control point indices. It will have the name <code>point</code>, * no normals, colour or texture, these can be added to the returned point if needed. * * @param start * The index of the control point to start from, must be greater than or equal to one and less than * <code>end</code>. * @param end * The index of the control point to end with, must be less than {@link #getControlPointCount() * controlPointCount} minus one and greater than <code>start</code>. * @param steps * The number of iterations to perform between control points, the higher this number the more points * will be shown, but it will also contain more vertices, must be greater than one. * @return A <code>Point</code> containing all the curve points, will not be <code>null</code>. */ public Point toRenderablePoint(final int start, final int end, final int steps) { final Vector3[] points = toVector3(start, end, steps); return new Point("point", points, null, null, null); }
@Override protected Vector3 interpolateVectors(final ReadOnlyVector3 from, final ReadOnlyVector3 to, final double delta, final Vector3 target) { assert (null != from) : "parameter 'from' can not be null"; assert (null != to) : "parameter 'to' can not be null"; final ReadOnlyVector3 p0 = getControlPointStart(); final ReadOnlyVector3 p3 = getCotnrolPointEnd(); final Spline spline = getCurve().getSpline(); return spline.interpolate(p0, from, to, p3, delta, target); }
private boolean continueLoop(final int i, final boolean reverse) { return (reverse ? i > 0 : i < _curve.getControlPointCount() - 2); }
/** * Interpolates between the control points at the given indices. * * @param start * The index of the control point to start from. * @param end * The index of the control point to end at. * @param t * Should be between zero and one. Zero will return point <code>start</code> while one will return * <code>end</code>, a value in between will return an interpolated vector between the two. * @return The interpolated vector. */ public ReadOnlyVector3 interpolate(final int start, final int end, final double t) { return interpolate(start, end, t, new Vector3()); }
throw new IllegalArgumentException("start must be > 0! start=" + start); if (end >= (getControlPointCount() - 1)) { throw new IllegalArgumentException("end must be < " + (getControlPointCount() - 1) + "! end=" + end); final List<ReadOnlyVector3> controlPoints = getControlPoints(); final int p3 = index + 2; vectors[i] = getSpline().interpolate(controlPoints.get(p0), controlPoints.get(p1), controlPoints.get(p2), controlPoints.get(p3), t);