Exemplo n.º 1
0
        public sXYZ DuplicatesXYZ()
        {
            sXYZ n = new sXYZ(this.X, this.Y, this.Z);

            n.objectGUID = this.objectGUID;
            return(n);
        }
Exemplo n.º 2
0
        public void ComputeFaceNormal(sMesh m)
        {
            sLine l0 = new sLine(m.vertices[this.A].location, m.vertices[this.B].location);
            sLine l1 = new sLine(m.vertices[this.A].location, m.vertices[this.C].location);

            this.normal = sXYZ.CrossProduct(l0.direction, l1.direction);
        }
Exemplo n.º 3
0
        public void SetVertex(int vertexID, sXYZ loc, sColor col)
        {
            sVertex v = new sVertex(vertexID, loc);

            v.color = col;
            this.vertices.Add(v);
        }
Exemplo n.º 4
0
        public void SetVertex(int vertexID, sXYZ loc, object dataIn)
        {
            sVertex v = new sVertex(vertexID, loc);

            v.data = dataIn;
            this.vertices.Add(v);
        }
Exemplo n.º 5
0
        public double DistanceTo(sXYZ vec)
        {
            double xx = (double)(this.X - vec.X);
            double yy = (double)(this.Y - vec.Y);
            double zz = (double)(this.Z - vec.Z);

            return(Math.Sqrt(xx * xx + yy * yy + zz * zz));
        }
Exemplo n.º 6
0
        public void ComputeNormal(sMesh m)
        {
            sXYZ nv = sXYZ.Zero();

            foreach (int f in this.faceIndices)
            {
                nv += m.faces[f].normal;
            }
            this.normal = nv;
        }
        public sLine(sXYZ sp, sXYZ ep)
        {
            this.startPoint = sp;
            this.endPoint   = ep;
            this.length     = sp.DistanceTo(ep);
            this.direction  = ep - sp;
            this.direction.Unitize();

            this.curveType = eCurveType.LINE;
        }
        public double GetClosestDistanceTo(sXYZ p, out double t)
        {
            sXYZ  minuteVec = new sXYZ(0.00001, 0, 0);
            sLine ln        = new sLine(p, p + minuteVec);

            double t0;
            double t1;
            double dis = this.GetClosestDistanceBetween(ln, out t0, out t1);

            t = t0;
            return(dis);
        }
        public sPlane(sXYZ ori, sXYZ x, sXYZ y)
        {
            this.origin = ori;
            this.Xaxis  = x;
            this.Yaxis  = y;
            this.Zaxis  = sXYZ.CrossProduct(x, y);
            this.Zaxis *= -1;

            this.Xaxis.Unitize();
            this.Yaxis.Unitize();
            this.Zaxis.Unitize();
        }
Exemplo n.º 10
0
        public static sXYZ Rotate(sXYZ v, sXYZ axis, double angle)
        {
            sXYZ result = new sXYZ();

            double tr  = t(angle);
            double cos = c(angle);
            double sin = s(angle);

            result.X = a1(angle, axis, tr, cos) * v.X + a2(angle, axis, tr, sin) * v.Y + a3(angle, axis, tr, sin) * v.Z;
            result.Y = b1(angle, axis, tr, sin) * v.X + b2(angle, axis, tr, cos) * v.Y + b3(angle, axis, tr, sin) * v.Z;
            result.Z = c1(angle, axis, tr, sin) * v.X + c2(angle, axis, tr, sin) * v.Y + c3(angle, axis, tr, cos) * v.Z;

            return(result);
        }
Exemplo n.º 11
0
        public static sXYZ CrossProduct(sXYZ v1, sXYZ v2)
        {
            v1.Unitize();
            v2.Unitize();

            double x, y, z;

            x = v1.Y * v2.Z - v2.Y * v1.Z;
            y = (v1.X * v2.Z - v2.X * v1.Z) * -1;
            z = v1.X * v2.Y - v2.X * v1.Y;

            var rtnvector = new sXYZ(x, y, z);

            rtnvector.Unitize();
            return(rtnvector);
        }
Exemplo n.º 12
0
 public sXYZ ProjectTo(sXYZ to)
 {
     return((this * to) * (to * to) * to);
 }
Exemplo n.º 13
0
 private static double a1(double angle, sXYZ axis, double tr, double cos)
 {
     return((tr * axis.X * axis.X) + cos);
 }
Exemplo n.º 14
0
        public void SetVertex(int vertexID, sXYZ loc)
        {
            sVertex v = new sVertex(vertexID, loc);

            this.vertices.Add(v);
        }
Exemplo n.º 15
0
 private static double b2(double angle, sXYZ axis, double tr, double cos)
 {
     return((tr * axis.Y * axis.Y) + cos);
 }
Exemplo n.º 16
0
 public sVertex(int id, sXYZ p)
 {
     this.ID          = id;
     this.location    = p;
     this.faceIndices = new List <int>();
 }
        public sXYZ PointAtLength(double lengthParam)
        {
            sXYZ dir = this.direction * lengthParam;

            return(dir);
        }
        public sXYZ PointAt(double normalizedParam)
        {
            sXYZ dir = this.direction * (this.length * normalizedParam);

            return(this.startPoint + dir);
        }
Exemplo n.º 19
0
 private static double c1(double angle, sXYZ axis, double tr, double sin)
 {
     return((tr * axis.X * axis.Z) - (sin * axis.Y));
 }
        public double GetClosestDistanceBetween(sLine ln, out double t0, out double t1)
        {
            sXYZ u = this.endPoint - this.startPoint;
            sXYZ v = ln.endPoint - ln.startPoint;
            sXYZ w = this.startPoint - ln.startPoint;

            double a = u * u; // sXYZ.Dot(u, u);
            double b = u * v; // sXYZ.Dot(u, v);
            double c = v * v; // sXYZ.Dot(v, v);
            double d = u * w; // sXYZ.Dot(u, w);
            double e = v * w; // sXYZ.Dot(v, w);

            double D  = (a * c) - (b * b);
            double sc = 0.0;
            double sN = 0.0;
            double sD = D;
            double tc = 0.0;
            double tN = 0.0;
            double tD = D;


            if (D < 0.00001)
            {
                //parallel
                sN = 0.0;
                sD = 1.0;
                tN = e;
                tD = c;
            }
            else
            {
                sN = (b * e - c * d);
                tN = (a * e - b * d);
                if (sN < 0.0)
                {
                    sN = 0.0;
                    tN = e;
                    tD = c;
                }
                else if (sN > sD)
                {
                    sN = sD;
                    tN = e + b;
                    tD = c;
                }
            }

            if (tN < 0.0)
            {
                tN = 0.0;
                if (-d < 0.0)
                {
                    sN = 0.0;
                }
                else if (-d > a)
                {
                    sN = sD;
                }
                else
                {
                    sN = -d;
                    sD = a;
                }
            }
            else if (tN > tD)
            {
                tN = tD;
                if ((-d + b) < 0.0)
                {
                    sN = 0;
                }
                else if ((-d + b) > a)
                {
                    sN = sD;
                }
                else
                {
                    sN = (-d + b);
                    sD = a;
                }
            }

            if (Math.Abs(sN) < 0.0001)
            {
                sc = 0.0;
            }
            else
            {
                sc = (sN / sD);
            }
            if (Math.Abs(tN) < 0.0001)
            {
                tc = 0.0;
            }
            else
            {
                tc = (tN / tD);
            }


            sXYZ cp = w + (sc * u) - (tc * v);

            t0 = sc;
            t1 = tc;
            return(cp.GetLength());
        }
Exemplo n.º 21
0
 public sXYZ RejectTo(sXYZ to)
 {
     return(this - ProjectTo(to));
 }
Exemplo n.º 22
0
 private static double c3(double angle, sXYZ axis, double tr, double cos)
 {
     return((tr * axis.Z * axis.Z) + cos);
 }
Exemplo n.º 23
0
 private static double c2(double angle, sXYZ axis, double tr, double sin)
 {
     return((tr * axis.Y * axis.Z) + (sin * axis.X));
 }