public bool Intersect( NuGenRay3D ray, ref double t, ref double u, ref double v, ref NuGenVec3D normal ) { NuGenVec3D e1 = p1 - p0; NuGenVec3D e2 = p2 - p0; NuGenVec3D p = NuGenVec3D.Cross(ray.Direction, e2); double a = NuGenVec3D.Dot(e1, p); if (a > -NuGenVector.TINY_DOUBLE && a < NuGenVector.TINY_DOUBLE) return false; double f = 1.0 / a; NuGenVec3D s = ray.Point - p0; u = f * NuGenVec3D.Dot(s, p); if (u < 0.0 || u > 1.0) return false; NuGenVec3D q = NuGenVec3D.Cross(s, e1); v = f * NuGenVec3D.Dot(ray.Direction, q); if (v < 0.0 || (u + v) > 1.0) return false; t = f * NuGenVec3D.Dot(e2, q); normal = NuGenVec3D.Cross(e1, e2); normal.Normalize(); return true; }
public bool Intersect(NuGenRay3D ray, ref double t, ref NuGenVec3D normal) { NuGenVec3D l = center - ray.Point; double s = NuGenVec3D.Dot(l, ray.Direction); double l2 = l.SquaredLength; double rr = radius * radius; if (s < 0.0 && l2 > rr) { return(false); } double m2 = l2 - s * s; if (m2 > rr) { return(false); } double q = Math.Sqrt(rr - m2); if (l2 > rr) { t = s - q; } else { t = s + q; } normal = (ray.Point + ray.Direction * t) - center; normal.Normalize(); return(true); }
public bool Intersect(NuGenRay3D ray, ref double t, ref NuGenVec3D normal) { NuGenVec3D l = center - ray.Point; double s = NuGenVec3D.Dot(l, ray.Direction); double l2 = l.SquaredLength; double rr = radius * radius; if (s < 0.0 && l2 > rr) return false; double m2 = l2 - s * s; if (m2 > rr) return false; double q = Math.Sqrt(rr - m2); if (l2 > rr) t = s - q; else t = s + q; normal = (ray.Point + ray.Direction * t) - center; normal.Normalize(); return true; }
public bool Intersect( NuGenRay3D ray, ref double t, ref double u, ref double v, ref NuGenVec3D normal ) { NuGenVec3D e1 = p1 - p0; NuGenVec3D e2 = p2 - p0; NuGenVec3D p = NuGenVec3D.Cross(ray.Direction, e2); double a = NuGenVec3D.Dot(e1, p); if (a > -NuGenVector.TINY_DOUBLE && a < NuGenVector.TINY_DOUBLE) { return(false); } double f = 1.0 / a; NuGenVec3D s = ray.Point - p0; u = f * NuGenVec3D.Dot(s, p); if (u < 0.0 || u > 1.0) { return(false); } NuGenVec3D q = NuGenVec3D.Cross(s, e1); v = f * NuGenVec3D.Dot(ray.Direction, q); if (v < 0.0 || (u + v) > 1.0) { return(false); } t = f * NuGenVec3D.Dot(e2, q); normal = NuGenVec3D.Cross(e1, e2); normal.Normalize(); return(true); }
public bool Intersect(NuGenRay3D r) { bool inside = true; int[] quadrant = new int[3]; int i; int whichPlane; double[] maxT = new double[3]; double[] candidatePlane = new double[3]; NuGenVec3D coord = new NuGenVec3D(0, 0, 0); for (i = 0; i < 3; i++) { if (r.Point[i] < lower[i]) { quadrant[i] = 1; candidatePlane[i] = lower[i]; inside = false; } else if (r.Point[i] > upper[i]) { quadrant[i] = 0; candidatePlane[i] = upper[i]; inside = false; } else { quadrant[i] = 2; } } if (inside) { return(true); } for (i = 0; i < 3; i++) { if (quadrant[i] != 2 && r.Direction[i] != 0.0) { maxT[i] = (candidatePlane[i] - r.Point[i]) / r.Direction[i]; } else { maxT[i] = -1.0; } } whichPlane = 0; for (i = 1; i < 3; i++) { if (maxT[whichPlane] < maxT[i]) { whichPlane = i; } } if (maxT[whichPlane] < 0.0) { return(false); } for (i = 0; i < 3; i++) { if (whichPlane != i) { coord[i] = r.Point[i] + maxT[whichPlane] * r.Direction[i]; if (coord[i] < lower[i] || coord[i] > upper[i]) { return(false); } } else { coord[i] = candidatePlane[i]; } } return(true); }