private void p(Vector3 result, double t) { if(t < 0) t = 1 + t; int end = mIsClosed ? 0 : 3; int start = mIsClosed ? 0 : 2; int currentIndex = start + (int) Math.floor((t == 1 ? t - DELTA : t) * (mNumPoints - end)); double tdivnum = (t * (mNumPoints - end)) - (currentIndex - start); mCurrentPoint.setAll(0, 0, 0); if (!mIsClosed) { // Limit the bounds for AccelerateDecelerateInterpolator currentIndex = Math.max(currentIndex, 2); currentIndex = Math.min(currentIndex, mPoints.size() - 2); } for (int j = -2; j <= 1; j++) { double b = b(j, tdivnum); int index = mIsClosed ? (currentIndex + j + 1) % (mNumPoints) : currentIndex + j; if (index < 0) index = mNumPoints - index - 2; Vector3 p = mPoints.get(index); mCurrentPoint.x += b * p.x; mCurrentPoint.y += b * p.y; mCurrentPoint.z += b * p.z; } result.setAll(mCurrentPoint); }
double curveLength = getLength(resolution * 100); calculatePoint(point, 0); newPoints.add(point); calculatePoint(point, (double) i / (numSegments - 1)); newPoints.add(point); currentLength = 0; calculatePoint(point, 1); newPoints.add(point);
public void calculatePoint(Vector3 result, final double t) { if (mCalculateTangents) { double prevt = t == 0 ? t + DELTA : t - DELTA; double nextt = t == 1 ? t - DELTA : t + DELTA; p(mCurrentTangent, prevt); p(mTempNext, nextt); mCurrentTangent.subtract(mTempNext); mCurrentTangent.multiply(.5); mCurrentTangent.normalize(); } p(result,t); }
public int selectPoint(Vector3 point) { double minDist = Double.MAX_VALUE; mSelectedIndex = -1; for (int i = 0; i < mNumPoints; i++) { Vector3 p = mPoints.get(i); double distance = pow2(p.x - point.x) + pow2(p.y - point.y) + pow2(p.z - point.z); if (distance < minDist && distance < EPSILON) { minDist = distance; mSelectedIndex = i; } } return mSelectedIndex; }
/** * Returns an approximation of the length of the curve. The more segments the more precise the result. * * @param segments * @return */ public double getLength(int segments) { double totalLength = 0; mSegmentLengths = new double[segments + 1]; mSegmentLengths[0] = 0; calculatePoint(mTempPrevLen, 0); for (int i = 1; i <= segments; i++) { double t = (double) i / (double) segments; calculatePoint(mTempPointLen, t); double dist = mTempPrevLen.distanceTo(mTempPointLen); totalLength += dist; mSegmentLengths[i] = dist; mTempPrevLen.setAll(mTempPointLen); } return totalLength; }
public int selectPoint(Vector3 point) { double minDist = Double.MAX_VALUE; mSelectedIndex = -1; for (int i = 0; i < mNumPoints; i++) { Vector3 p = mPoints.get(i); double distance = pow2(p.x - point.x) + pow2(p.y - point.y) + pow2(p.z - point.z); if (distance < minDist && distance < EPSILON) { minDist = distance; mSelectedIndex = i; } } return mSelectedIndex; }
/** * Returns an approximation of the length of the curve. The more segments the more precise the result. * * @param segments * @return */ public double getLength(int segments) { double totalLength = 0; mSegmentLengths = new double[segments + 1]; mSegmentLengths[0] = 0; calculatePoint(mTempPrevLen, 0); for (int i = 1; i <= segments; i++) { double t = (double) i / (double) segments; calculatePoint(mTempPointLen, t); double dist = mTempPrevLen.distanceTo(mTempPointLen); totalLength += dist; mSegmentLengths[i] = dist; mTempPrevLen.setAll(mTempPointLen); } return totalLength; }
double curveLength = getLength(resolution * 100); calculatePoint(point, 0); newPoints.add(point); calculatePoint(point, (double) i / (double) (numSegments - 1)); newPoints.add(point); currentLength = 0; calculatePoint(point, 1); newPoints.add(point);
public void calculatePoint(Vector3 result, final double t) { if (mCalculateTangents) { double prevt = t == 0 ? t + DELTA : t - DELTA; double nextt = t == 1 ? t - DELTA : t + DELTA; p(mCurrentTangent, prevt); p(mTempNext, nextt); mCurrentTangent.subtract(mTempNext); mCurrentTangent.multiply(.5); mCurrentTangent.normalize(); } p(result,t); }
private void p(Vector3 result, double t) { if(t < 0) t = 1 + t; int end = mIsClosed ? 0 : 3; int start = mIsClosed ? 0 : 2; int currentIndex = start + (int) Math.floor((t == 1 ? t - DELTA : t) * (mNumPoints - end)); double tdivnum = (t * (mNumPoints - end)) - (currentIndex - start); mCurrentPoint.setAll(0, 0, 0); if (!mIsClosed) { // Limit the bounds for AccelerateDecelerateInterpolator currentIndex = Math.max(currentIndex, 2); currentIndex = Math.min(currentIndex, mPoints.size() - 2); } for (int j = -2; j <= 1; j++) { double b = b(j, tdivnum); int index = mIsClosed ? (currentIndex + j + 1) % (mNumPoints) : currentIndex + j; if (index < 0) index = mNumPoints - index - 2; Vector3 p = mPoints.get(index); mCurrentPoint.x += b * p.x; mCurrentPoint.y += b * p.y; mCurrentPoint.z += b * p.z; } result.setAll(mCurrentPoint); }