@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; }