/** Adds a scaled vector in-place to this one. * @return a reference to this vector, for chaining. */ public Vector addScaledLocal (IVector other, float v) { return addScaled(other, v, this); }
/** Adds a scaled vector in-place to this one. * @return a reference to this vector, for chaining. */ public Vector addScaledLocal (IVector other, float v) { return addScaled(other, v, this); }
@Override // from IRay2 public boolean getIntersection (IVector start, IVector end, Vector result) { // ray is a + t*b, segment is c + s*d float ax = origin.x, ay = origin.y; float bx = direction.x, by = direction.y; float cx = start.x(), cy = start.y(); float dx = end.x() - start.x(), dy = end.y() - start.y(); float divisor = bx*dy - by*dx; if (Math.abs(divisor) < MathUtil.EPSILON) { // the lines are parallel (or the segment is zero-length) float t = Math.min(getIntersection(start), getIntersection(end)); boolean isect = (t != Float.MAX_VALUE); if (isect) { origin.addScaled(direction, t, result); } return isect; } float cxax = cx - ax, cyay = cy - ay; float s = (by*cxax - bx*cyay) / divisor; if (s < 0f || s > 1f) { return false; } float t = (dy*cxax - dx*cyay) / divisor; boolean isect = (t >= 0f); if (isect) { origin.addScaled(direction, t, result); } return isect; }
@Override // from IRay2 public boolean getIntersection (IVector start, IVector end, Vector result) { // ray is a + t*b, segment is c + s*d float ax = origin.x, ay = origin.y; float bx = direction.x, by = direction.y; float cx = start.x(), cy = start.y(); float dx = end.x() - start.x(), dy = end.y() - start.y(); float divisor = bx*dy - by*dx; if (Math.abs(divisor) < MathUtil.EPSILON) { // the lines are parallel (or the segment is zero-length) float t = Math.min(getIntersection(start), getIntersection(end)); boolean isect = (t != Float.MAX_VALUE); if (isect) { origin.addScaled(direction, t, result); } return isect; } float cxax = cx - ax, cyay = cy - ay; float s = (by*cxax - bx*cyay) / divisor; if (s < 0f || s > 1f) { return false; } float t = (dy*cxax - dx*cyay) / divisor; boolean isect = (t >= 0f); if (isect) { origin.addScaled(direction, t, result); } return isect; }
@Override // from IRay2 public boolean getIntersection (IVector center, float radius, Vector result) { // see if we start inside the circle if (origin.distanceSq(center) <= radius*radius) { result.set(origin); return true; } // then if we intersect the circle float ax = origin.x - center.x(), ay = origin.y - center.y(); float b = 2f*(direction.x*ax + direction.y*ay); float c = ax*ax + ay*ay - radius*radius; float radicand = b*b - 4f*c; if (radicand < 0f) { return false; } float t = (-b - FloatMath.sqrt(radicand)) * 0.5f; boolean isect = (t >= 0f); if (isect) { origin.addScaled(direction, t, result); } return isect; }
@Override // from IRay2 public boolean getIntersection (IVector center, float radius, Vector result) { // see if we start inside the circle if (origin.distanceSq(center) <= radius*radius) { result.set(origin); return true; } // then if we intersect the circle float ax = origin.x - center.x(), ay = origin.y - center.y(); float b = 2f*(direction.x*ax + direction.y*ay); float c = ax*ax + ay*ay - radius*radius; float radicand = b*b - 4f*c; if (radicand < 0f) { return false; } float t = (-b - FloatMath.sqrt(radicand)) * 0.5f; boolean isect = (t >= 0f); if (isect) { origin.addScaled(direction, t, result); } return isect; }