예제 #1
0
		public bool Intersect(NuGenRay3F r)
		{
			bool inside = true;
			int [] quadrant = new int[3];
			int i;
			int whichPlane;
			float [] max = new float[3];
			float [] candidatePlane = new float[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)
				{
					max[i] = (candidatePlane[i]-r.Point[i]) / r.Direction[i];
				}

				else
				{
					max[i] = -1.0f;
				}
			}

			whichPlane = 0;

			for (i = 1; i < 3; i++)
			{

				if (max[whichPlane] < max[i]) whichPlane = i;
			}

			if (max[whichPlane] < 0.0) return false;

			for (i = 0; i < 3; i++)
			{

				if (whichPlane != i) 
				{
					coord[i] = r.Point[i] + max[whichPlane] * r.Direction[i];

					if (coord[i] < lower[i] || coord[i] > upper[i])
					{
						return false;
					}
				} 

				else 
				{
					coord[i] = candidatePlane[i];
				}
			}

			return true;
		}
예제 #2
0
        public bool Intersect(NuGenRay3F r)
        {
            bool inside = true;

            int [] quadrant = new int[3];
            int    i;
            int    whichPlane;

            float []   max            = new float[3];
            float []   candidatePlane = new float[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)
                {
                    max[i] = (candidatePlane[i] - r.Point[i]) / r.Direction[i];
                }

                else
                {
                    max[i] = -1.0f;
                }
            }

            whichPlane = 0;

            for (i = 1; i < 3; i++)
            {
                if (max[whichPlane] < max[i])
                {
                    whichPlane = i;
                }
            }

            if (max[whichPlane] < 0.0)
            {
                return(false);
            }

            for (i = 0; i < 3; i++)
            {
                if (whichPlane != i)
                {
                    coord[i] = r.Point[i] + max[whichPlane] * r.Direction[i];

                    if (coord[i] < lower[i] || coord[i] > upper[i])
                    {
                        return(false);
                    }
                }

                else
                {
                    coord[i] = candidatePlane[i];
                }
            }

            return(true);
        }