Пример #1
0
        public override double GetIntersection(Vector from, Vector to, ref Vector normalAtPoint)
        {
            // static Vector3D IntersectPoint(Vector3D rayVector, Vector3D rayPoint, Vector3D planeNormal, Vector3D planePoint)
            //rayVector parameters from to, ray point calculate point , planeNormal..attribute, planePoint .. attribute
            //line goes from camera position to one of canvas point, this is from & to vectors
            //Line line = new Line(to - from, from);
            //Vector p = line.point;
            //Vector v = line.direction;
            //Vector n = normal;
            //double dot1 = Vector.dot(n, v);
            //double dot2 = Vector.dot(n, p);
            //if (dot1 == 0)
            //    return 0;
            double t = GetIntersection(from, to);
            //find intersection point
            Vector ret = new Vector();

            //ret = p + (t * v);//
            ret = to * t + from;

            normalAtPoint = normal;//
            normalAtPoint = new Vector(ret.X, ret.Y, ret.Z);
            normalAtPoint.normalize();
            return(t);
        }
Пример #2
0
        /// <summary>
        /// Unit vector of the vector defined by vector's components
        /// </summary>
        public Vector unitVector(double x, double y, double z)
        {
            Vector v = new Vector(x, y, z);

            v.normalize();
            return(v);
        }
Пример #3
0
        public override double GetIntersection(Vector from, Vector to, ref Vector normalAtPoint)
        {
            Vector u   = new Vector(v1 - v0);
            Vector v   = new Vector(v2 - v0);
            Vector n   = Vector.CrossProd(u, v);
            Vector dir = to - from;
            Vector w0  = from - v0;
            double a   = -1 * Vector.dot(n, w0);
            double b   = Vector.dot(n, dir);

            if (Math.Abs(b) < 0.000000001)
            {
                if (a == 0)
                {
                    return(2);
                }
                else
                {
                    return(0);
                }
            }
            double r = a / b;

            if (r < 0)
            {
                return(0);
            }
            Vector I = from + r * dir;
            double uu, uv, vv, wu, wv, D;

            uu = Vector.dot(u, u);
            uv = Vector.dot(u, v);
            vv = Vector.dot(v, v);
            Vector w = I - v0;

            wu = Vector.dot(w, u);
            wv = Vector.dot(w, v);
            D  = uv * uv - uu * vv;
            double s, t;

            s = (uv * wv - vv * wu) / D;
            if (s < 0.0 || s > 1.0)         // neni v trojuhelniku
            {
                return(0);
            }
            t = (uv * wu - uu * wv) / D;
            if (t < 0.0 || (s + t) > 1.0)  // neni v trojuhelniku
            {
                return(0);
            }
            normalAtPoint = I;
            normalAtPoint.normalize();
            return(t);                       // je v trojuhelniku

            //returning point
            //V0 + s * u + t * v
            //u = V1 - V0
            //v = V2 - V0
        }
Пример #4
0
        public override double GetIntersection(Vector from, Vector to, ref Vector normalAtPoint)
        {
            to.normalize();//sphere
            double t  = GetIntersection(from, to);
            Vector v1 = to * t + from;

            v1 = v1 - position;
            v1.normalize();
            normalAtPoint = v1;
            return(t);
        }
Пример #5
0
 /// <summary>
 /// Unit vector of the vector
 /// </summary>
 public Vector unitVector(Vector v)
 {
     v.normalize();
     return(v);
 }