/** @return The span closest to the specified value, restricting to the specified spans. */ public int nearest (final T in, int start, final int count) { while (start < 0) start += spanCount; int result = start % spanCount; float dst = in.dst2(controlPoints[result]); for (int i = 1; i < count; i++) { final int idx = (start + i) % spanCount; final float d = in.dst2(controlPoints[idx]); if (d < dst) { dst = d; result = idx; } } return result; }
/** @return The span closest to the specified value, restricting to the specified spans. */ public int nearest (final T in, int start, final int count) { while (start < 0) start += spanCount; int result = start % spanCount; float dst = in.dst2(controlPoints[result]); for (int i = 1; i < count; i++) { final int idx = (start + i) % spanCount; final float d = in.dst2(controlPoints[idx]); if (d < dst) { dst = d; result = idx; } } return result; }
public float approximate (final T in, final int near) { int n = near; final T nearest = controlPoints[n]; final T previous = controlPoints[n > 0 ? n - 1 : spanCount - 1]; final T next = controlPoints[(n + 1) % spanCount]; final float dstPrev2 = in.dst2(previous); final float dstNext2 = in.dst2(next); T P1, P2, P3; if (dstNext2 < dstPrev2) { P1 = nearest; P2 = next; P3 = in; } else { P1 = previous; P2 = nearest; P3 = in; n = n > 0 ? n - 1 : spanCount - 1; } float L1Sqr = P1.dst2(P2); float L2Sqr = P3.dst2(P2); float L3Sqr = P3.dst2(P1); float L1 = (float)Math.sqrt(L1Sqr); float s = (L2Sqr + L1Sqr - L3Sqr) / (2f * L1); float u = MathUtils.clamp((L1 - s) / L1, 0f, 1f); return (n + u) / spanCount; }
public float approximate (final T in, final int near) { int n = near; final T nearest = controlPoints[n]; final T previous = controlPoints[n > 0 ? n - 1 : spanCount - 1]; final T next = controlPoints[(n + 1) % spanCount]; final float dstPrev2 = in.dst2(previous); final float dstNext2 = in.dst2(next); T P1, P2, P3; if (dstNext2 < dstPrev2) { P1 = nearest; P2 = next; P3 = in; } else { P1 = previous; P2 = nearest; P3 = in; n = n > 0 ? n - 1 : spanCount - 1; } float L1Sqr = P1.dst2(P2); float L2Sqr = P3.dst2(P2); float L3Sqr = P3.dst2(P1); float L1 = (float)Math.sqrt(L1Sqr); float s = (L2Sqr + L1Sqr - L3Sqr) / (2f * L1); float u = MathUtils.clamp((L1 - s) / L1, 0f, 1f); return (n + u) / spanCount; }
@Override public float approximate (final T v) { // TODO: make a real approximate method T p1 = points.get(0); T p2 = points.get(points.size - 1); T p3 = v; float l1Sqr = p1.dst2(p2); float l2Sqr = p3.dst2(p2); float l3Sqr = p3.dst2(p1); float l1 = (float)Math.sqrt(l1Sqr); float s = (l2Sqr + l1Sqr - l3Sqr) / (2 * l1); return MathUtils.clamp((l1 - s) / l1, 0f, 1f); }
@Override public float approximate (final T v) { // TODO: make a real approximate method T p1 = points.get(0); T p2 = points.get(points.size - 1); T p3 = v; float l1Sqr = p1.dst2(p2); float l2Sqr = p3.dst2(p2); float l3Sqr = p3.dst2(p1); float l1 = (float)Math.sqrt(l1Sqr); float s = (l2Sqr + l1Sqr - l3Sqr) / (2 * l1); return MathUtils.clamp((l1 - s) / l1, 0f, 1f); }
/** @return The span closest to the specified value, restricting to the specified spans. */ public int nearest (final T in, int start, final int count) { while (start < 0) start += spanCount; int result = start % spanCount; float dst = in.dst2(knots.get(result)); for (int i = 1; i < count; i++) { final int idx = (start + i) % spanCount; final float d = in.dst2(knots.get(idx)); if (d < dst) { dst = d; result = idx; } } return result; }
/** @return The span closest to the specified value, restricting to the specified spans. */ public int nearest (final T in, int start, final int count) { while (start < 0) start += spanCount; int result = start % spanCount; float dst = in.dst2(knots.get(result)); for (int i = 1; i < count; i++) { final int idx = (start + i) % spanCount; final float d = in.dst2(knots.get(idx)); if (d < dst) { dst = d; result = idx; } } return result; }
public float approximate (final T in, final int near) { int n = near; final T nearest = knots.get(n); final T previous = knots.get(n > 0 ? n - 1 : spanCount - 1); final T next = knots.get((n + 1) % spanCount); final float dstPrev2 = in.dst2(previous); final float dstNext2 = in.dst2(next); T P1, P2, P3; if (dstNext2 < dstPrev2) { P1 = nearest; P2 = next; P3 = in; } else { P1 = previous; P2 = nearest; P3 = in; n = n > 0 ? n - 1 : spanCount - 1; } float L1Sqr = P1.dst2(P2); float L2Sqr = P3.dst2(P2); float L3Sqr = P3.dst2(P1); float L1 = (float)Math.sqrt(L1Sqr); float s = (L2Sqr + L1Sqr - L3Sqr) / (2 * L1); float u = MathUtils.clamp((L1 - s) / L1, 0f, 1f); return (n + u) / spanCount; }
public float approximate (final T in, final int near) { int n = near; final T nearest = knots.get(n); final T previous = knots.get(n > 0 ? n - 1 : spanCount - 1); final T next = knots.get((n + 1) % spanCount); final float dstPrev2 = in.dst2(previous); final float dstNext2 = in.dst2(next); T P1, P2, P3; if (dstNext2 < dstPrev2) { P1 = nearest; P2 = next; P3 = in; } else { P1 = previous; P2 = nearest; P3 = in; n = n > 0 ? n - 1 : spanCount - 1; } float L1Sqr = P1.dst2(P2); float L2Sqr = P3.dst2(P2); float L3Sqr = P3.dst2(P1); float L1 = (float)Math.sqrt(L1Sqr); float s = (L2Sqr + L1Sqr - L3Sqr) / (2 * L1); float u = MathUtils.clamp((L1 - s) / L1, 0f, 1f); return (n + u) / spanCount; }
@Override public boolean reportNeighbor (Steerable<T> neighbor) { // Calculate the position of the hiding spot for this obstacle T hidingSpot = getHidingPosition(neighbor.getPosition(), neighbor.getBoundingRadius(), target.getPosition()); // Work in distance-squared space to find the closest hiding // spot to the owner float distance2 = hidingSpot.dst2(owner.getPosition()); if (distance2 < distance2ToClosest) { distance2ToClosest = distance2; bestHidingSpot.set(hidingSpot); return true; } return false; }
/** @return The span closest to the specified value, restricting to the specified spans. */ public int nearest (final T in, int start, final int count) { while (start < 0) start += spanCount; int result = start % spanCount; float dst = in.dst2(controlPoints[result]); for (int i = 1; i < count; i++) { final int idx = (start + i) % spanCount; final float d = in.dst2(controlPoints[idx]); if (d < dst) { dst = d; result = idx; } } return result; }
/** Returns the square distance of the nearest point on line segment {@code a-b}, from point {@code c}. Also, the {@code out} * vector is assigned to the nearest point. * @param out the output vector that contains the nearest point on return * @param a the start point of the line segment * @param b the end point of the line segment * @param c the point to calculate the distance from */ public float calculatePointSegmentSquareDistance (T out, T a, T b, T c) { out.set(a); tmpB.set(b); tmpC.set(c); T ab = tmpB.sub(a); float abLen2 = ab.len2(); if (abLen2 != 0) { float t = (tmpC.sub(a)).dot(ab) / abLen2; out.mulAdd(ab, MathUtils.clamp(t, 0, 1)); } return out.dst2(c); }
public float approximate (final T in, final int near) { int n = near; final T nearest = controlPoints[n]; final T previous = controlPoints[n > 0 ? n - 1 : spanCount - 1]; final T next = controlPoints[(n + 1) % spanCount]; final float dstPrev2 = in.dst2(previous); final float dstNext2 = in.dst2(next); T P1, P2, P3; if (dstNext2 < dstPrev2) { P1 = nearest; P2 = next; P3 = in; } else { P1 = previous; P2 = nearest; P3 = in; n = n > 0 ? n - 1 : spanCount - 1; } float L1Sqr = P1.dst2(P2); float L2Sqr = P3.dst2(P2); float L3Sqr = P3.dst2(P1); float L1 = (float)Math.sqrt(L1Sqr); float s = (L2Sqr + L1Sqr - L3Sqr) / (2f * L1); float u = MathUtils.clamp((L1 - s) / L1, 0f, 1f); return (n + u) / spanCount; }
float squareDistance = ownerPosition.dst2(currentAgent.getPosition());
float distanceSquare = ownerPosition.dst2(outputCollision.point); if (distanceSquare < minDistanceSquare) { minDistanceSquare = distanceSquare;
@Override public float approximate (final T v) { // TODO: make a real approximate method T p1 = points.get(0); T p2 = points.get(points.size - 1); T p3 = v; float l1Sqr = p1.dst2(p2); float l2Sqr = p3.dst2(p2); float l3Sqr = p3.dst2(p1); float l1 = (float)Math.sqrt(l1Sqr); float s = (l2Sqr + l1Sqr - l3Sqr) / (2 * l1); return MathUtils.clamp((l1 - s) / l1, 0f, 1f); }
/** @return The span closest to the specified value, restricting to the specified spans. */ public int nearest (final T in, int start, final int count) { while (start < 0) start += spanCount; int result = start % spanCount; float dst = in.dst2(knots.get(result)); for (int i = 1; i < count; i++) { final int idx = (start + i) % spanCount; final float d = in.dst2(knots.get(idx)); if (d < dst) { dst = d; result = idx; } } return result; }
@Override public boolean reportNeighbor (Steerable<T> neighbor) { // Calculate the position of the hiding spot for this obstacle T hidingSpot = getHidingPosition(neighbor.getPosition(), neighbor.getBoundingRadius(), target.getPosition()); // Work in distance-squared space to find the closest hiding // spot to the owner float distance2 = hidingSpot.dst2(owner.getPosition()); if (distance2 < distance2ToClosest) { distance2ToClosest = distance2; bestHidingSpot.set(hidingSpot); return true; } return false; }
/** Returns the square distance of the nearest point on line segment {@code a-b}, from point {@code c}. Also, the {@code out} * vector is assigned to the nearest point. * @param out the output vector that contains the nearest point on return * @param a the start point of the line segment * @param b the end point of the line segment * @param c the point to calculate the distance from */ public float calculatePointSegmentSquareDistance (T out, T a, T b, T c) { out.set(a); tmpB.set(b); tmpC.set(c); T ab = tmpB.sub(a); float abLen2 = ab.len2(); if (abLen2 != 0) { float t = (tmpC.sub(a)).dot(ab) / abLen2; out.mulAdd(ab, MathUtils.clamp(t, 0, 1)); } return out.dst2(c); }