Пример #1
0
		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;
		}
Пример #2
0
        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);
        }
Пример #3
0
		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;
		}
Пример #4
0
        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);
        }