Exemple #1
0
 public static double CalcDist(Point3D m, Point3D n)
 {
     return Math.Sqrt(
         (m.X - n.X) * (m.X - n.X) +
         (m.Y - n.Y) * (m.Y - n.Y) +
         (m.Z - n.Z) * (m.Z - n.Z));
 }
Exemple #2
0
        public void makeRectangle(Point3D origin)
        {
            this.origin = origin;
            double neg = -20;
            double pov = 20;
            double near = 100;
            double far = 140;
            path = new Point3D[]
            {
                new Point3D(neg, near, pov),
                new Point3D(neg + 20, far, pov + 20),
                new Point3D(neg + 20, far, -pov + 20),
                new Point3D(neg + 20, near, -pov + 20),
                new Point3D(neg, near, -pov),

                new Point3D(neg, near, pov),
                new Point3D(pov, near, pov),
                new Point3D(pov, near, neg),
                new Point3D(neg, near, neg),
                new Point3D(neg, near, pov),

                new Point3D(pov, near, pov),
                new Point3D(pov + 20, far, pov + 20),
                new Point3D(pov + 20, far, -pov + 20),

                new Point3D(pov + 20, far, pov + 20),
                new Point3D(neg + 20, far, pov + 20),
                new Point3D(neg + 20, far, neg + 20),
                new Point3D(pov + 20, far, neg + 20),
                new Point3D(pov + 20, far, -pov + 20),
                new Point3D(pov, near, -pov),
            };
        }
 public static double DistanceBetweenPoints(Point3D firstPoint, Point3D secondPoint)
 {
     double deltaX = firstPoint.XPos - secondPoint.XPos;
     double deltaY = firstPoint.YPos - secondPoint.YPos;
     double deltaZ = firstPoint.ZPos - secondPoint.ZPos;
     return Math.Sqrt(deltaX*deltaX + deltaY*deltaY + deltaZ*deltaZ);
 }
 public static Path GetPathFromFile(string filePath)
 {
     StreamReader sr = new StreamReader(filePath);
     using (sr)
     {
         Point3D currentPoint = new Point3D();
         while (!sr.EndOfStream)
         {
             string currentLine = sr.ReadLine();
             int value = int.Parse(currentLine.Substring(2));
             if (currentLine[0] == 'x')
             {
                 currentPoint = new Point3D();
                 currentPoint.XPos = value;
             }
             else if (currentLine[0] == 'y')
             {
                 currentPoint.YPos = value;
             }
             else if (currentLine[0] == 'z')
             {
                 currentPoint.ZPos = value;
                 path.AddPoint(currentPoint);
             }
         }
     }
     return path;
 }
 public void PathTestSimpleTest()
 {
     Point3D a = new Point3D(1, 1, 1);
     Point3D b = new Point3D(2, 2, 2);
     somePath.AddPoint(a);
     somePath.AddPoint(b);
     Assert.IsTrue(somePath.GetPath()[0].Equals(a));
     Assert.IsTrue(somePath.GetPath()[1].Equals(b));
 }
Exemple #6
0
 public Point3D CrossProduct(Point3D p1, Point3D p2)
 {
     Point3D p3;
     p3 = new Point3D(0, 0, 0);
     p3.x = p1.y * p2.z - p1.z * p2.y;
     p3.y = p1.z * p2.x - p1.x * p2.z;
     p3.z = p1.x * p2.y - p1.y * p2.x;
     return p3;
 }
Exemple #7
0
        public void Normalise(Point3D v)
        {
            double length;

            length = Math.Sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
            v.x /= length;
            v.y /= length;
            v.z /= length;
        }
 public void Point3DCreation()
 {
     Point3D somePoint = new Point3D();
     somePoint.XPos = 4;
     somePoint.YPos = 5;
     somePoint.ZPos = 6;
     Assert.IsTrue(somePoint.XPos == 4);
     Assert.IsTrue(somePoint.YPos == 5);
     Assert.IsTrue(somePoint.ZPos == 6);
 }
Exemple #9
0
 public Point3D cross(Point3D p2)
 {
     Point3D p1 = this.normalize();
     Point3D p3;
     p3 = new Point3D(0, 0, 0);
     p3.x = p1.y * p2.z - p1.z * p2.y;
     p3.y = p1.z * p2.x - p1.x * p2.z;
     p3.z = p1.x * p2.y - p1.y * p2.x;
     return p3;
 }
Exemple #10
0
        public bool EqualVertex(Point3D p1, Point3D p2)
        {
            if (Math.Abs(p1.x - p2.x) > EPSILON)
                return (false);
            if (Math.Abs(p1.y - p2.y) > EPSILON)
                return (false);
            if (Math.Abs(p1.z - p2.z) > EPSILON)
                return (false);

            return (true);
        }
Exemple #11
0
        // x is up/down, z is left/right
        public void rotateCamera(double rotx, double rotz, double roty)
        {
            double radrotx = Math.PI * rotx / 180;
            double radrotz = -Math.PI * rotz / 180;
            double radroty = Math.PI * roty / 180;
            double cosx = Math.Cos(radrotx);
            double sinx = Math.Sin(radrotx);
            double cosz = Math.Cos(radrotz);
            double sinz = Math.Sin(radrotz);
            double cosy = Math.Cos(radroty);
            double siny = Math.Cos(radroty);
            facing = facing - pos;
            axes[0] -= pos;
            axes[1] -= pos;
            axes[2] -= pos;
            if (rotx != 0)
            {
                facing = new Point3D(facing.x, facing.y * cosx + facing.z * sinx, facing.y * -1 * sinx + facing.z * cosx); // x
                //orient = new Point3D(orient.x, orient.y * cosx + orient.z * sinx, orient.y * -1 * sinx + orient.z * cosx); // x
                axes[1] = new Point3D(axes[1].x, axes[1].y * cosx + axes[1].z * sinx, axes[1].y * -1 * sinx + axes[1].z * cosx); // x
                axes[2] = new Point3D(axes[2].x, axes[2].y * cosx + axes[2].z * sinx, axes[2].y * -1 * sinx + axes[2].z * cosx); // x
            }
            if (rotz != 0)
            {
                facing = new Point3D(facing.x * cosz + facing.y * -1 * sinz, facing.x * sinz + facing.y * cosz, facing.z); // z

                axes[0] = new Point3D(axes[0].x * cosz + axes[0].y * -1 * sinz, axes[0].x * sinz + axes[0].y * cosz, axes[0].z); // z
                axes[1] = new Point3D(axes[1].x * cosz + axes[1].y * -1 * sinz, axes[1].x * sinz + axes[1].y * cosz, axes[1].z); // z
            }
            if (roty != 0)
            {
                axes[0] = new Point3D(axes[0].x * cosy + axes[0].z * -1 * siny, axes[0].y, axes[0].x * siny + axes[0].z * cosy); // y
                axes[2] = new Point3D(axes[2].x * cosy + axes[2].z * -1 * siny, axes[2].y, axes[2].x * siny + axes[2].z * cosy); // y

            }
            facing = facing + pos;

            axes[0].normalize();
            axes[1].normalize();
            axes[2].normalize();
            axes[0] += pos;
            axes[1] += pos;
            axes[2] += pos;
            /*
            orient = orient - pos;
            orient = new Point3D(orient.x, orient.y * cosx + orient.z * sinx, orient.y * -1 * sinx + orient.z * cosx);

            orient = new Point3D(orient.x * cosz + orient.y * -1 * sinz, orient.x * sinz + orient.y * cosz, orient.z);
            orient = orient + pos;
            */
        }
Exemple #12
0
        public double zoom; // distance from camera to plane

        #endregion Fields

        #region Constructors

        public CAMERA()
        {
            pos = new Point3D(0, 0, 0);
            facing = new Point3D(0, 1, 0);
            up = new Point3D(0, 0, 1);
            axes = new Point3D[]
            {
                new Point3D(1,0,0),
                new Point3D(0,1,0),
                new Point3D(0,0,1),
            };
            angleh = 45.0;
            anglev = 45.0;
            zoom = 1.0;
            front = 1.0;
            back = 1000.0; // viewing range
            projection = 0;
        }
Exemple #13
0
        public projection(CAMERA camera)
        {
            EPSILON = 0.001;
            DTOR = 0.01745329252;
            this.camera = camera;
            screen = new SCREEN();
            origin = new Point3D();
            basisa = new Point3D();
            viewVec = new Point3D();
            basisc = new Point3D();
            p1 = new Point2D();
            p2 = new Point2D();

            e1 = new Point3D();
            e2 = new Point3D();
            n1 = new Point3D();
            n2 = new Point3D();
            if (Trans_Initialise() != true)
            {
                //MessageBox.Show("Error in initializing variable");
            }
        }
Exemple #14
0
        static void Main()
        {
            Point3D m = Point3D.StartPoint;
            Point3D n = new Point3D(1, 3, 5);
            Point3D p = new Point3D(2, 4, 6);

            Console.WriteLine("Distance: {0:f2}", Distance.CalcDist(n, p));

            Path path = new Path();
            path.AddPoint(m);
            path.AddPoint(n);
            path.AddPoint(p);

            Console.WriteLine(path);

            PathStorage.Save(path, "Path.txt");

            Console.WriteLine(PathStorage.Load("Path.txt"));

            //Console.WriteLine(PathStorage.Load("noPath.txt"));

            var myMatrix = new Matrix<int>(2, 3);
            Console.WriteLine(string.Join("; ", myMatrix));
            myMatrix[0, 0] = 10;
            var newMatrix = new Matrix<int>(4, 2);
            newMatrix[1, 0] = 7;
            newMatrix = myMatrix * newMatrix;

            //Type type = typeof(Matrix<>);
            //object[] allAttributes =
            //  type.GetCustomAttributes(true);
            //foreach (VersionAttribute attr in allAttributes)
            //{
            //    Console.WriteLine("This class is version {0}.{1} ", type.attr.major, attr.minor);
            //}
        }
 public void AddPoint(Point3D point)
 {
     pathPoints.Add(point);
 }
Exemple #16
0
 public Figure3D(Point3D origin, Point3D[] path)
 {
     this.origin = origin;
     this.path = path;
 }
Exemple #17
0
        public void Trans_World2Eye(Point3D w, Point3D e)
        {
            /* Translate world so that the camera is at the origin */
            w.x -= camera.pos.x;
            w.y -= camera.pos.y;
            w.z -= camera.pos.z;

            /* Convert to eye coordinates using basis vectors */
            e.x = w.x * basisa.x + w.y * basisa.y + w.z * basisa.z;

            e.y = w.x * viewVec.x + w.y * viewVec.y + w.z * viewVec.z;
            e.z = w.x * basisc.x + w.y * basisc.y + w.z * basisc.z;
        }
Exemple #18
0
 public void Trans_Norm2Screen(Point3D norm, Point2D projected)
 {
     //MessageBox.Show("the value of  are");
     projected.h = Convert.ToInt32(screen.center.h - screen.size.h * norm.x / 2);
     projected.v = Convert.ToInt32(screen.center.v - screen.size.v * norm.z / 2);
 }
Exemple #19
0
        //public bool Trans_Point();
        public bool Trans_Line(Point3D w1, Point3D w2)
        {
            Trans_World2Eye(w1, e1);
            Trans_World2Eye(w2, e2);
            if (Trans_ClipEye(e1, e2))
            {
                Trans_Eye2Norm(e1, n1);
                Trans_Eye2Norm(e2, n2);
                if (Trans_ClipNorm(n1, n2))
                {
                    Trans_Norm2Screen(n1, p1);
                    Trans_Norm2Screen(n2, p2);
                    return (true);
                }

            }

            return (true);
        }
Exemple #20
0
        public bool Trans_Initialise()
        {
            /* Is the camera position and view vector coincident ? */
            if (EqualVertex(camera.axes[1], camera.pos))
            {
                return (false);
            }

            /* Is there a legal camera up vector ? */
            if (EqualVertex(camera.up, origin))
            {
                return (false);
            }

            viewVec.x = camera.axes[1].x - camera.pos.x;// view direction
            viewVec.y = camera.axes[1].y - camera.pos.y;
            viewVec.z = camera.axes[1].z - camera.pos.z;
            Normalise(viewVec);

            basisa = CrossProduct(camera.up, viewVec);
            Normalise(basisa);

            /* Are the up vector and view direction colinear */
            if (EqualVertex(basisa, origin))
            {
                return (false);
            }

            basisc = CrossProduct(viewVec, basisa);

            /* Do we have legal camera apertures ? */
            if (camera.angleh < EPSILON || camera.anglev < EPSILON)
            {
                return (false);
            }

            /* Calculate camera aperture statics, note: angles in degrees */
            tanthetah = Math.Tan(camera.angleh * DTOR / 2);
            tanthetav = Math.Tan(camera.anglev * DTOR / 2);

            /* Do we have a legal camera zoom ? */
            if (camera.zoom < EPSILON)
            {
                return (false);
            }

            /* Are the clipping planes legal ? */
            if (camera.front < 0 || camera.back < 0 || camera.back <= camera.front)
            {
                return (false);
            }

            return true;
        }
Exemple #21
0
        public void Trans_Eye2Norm(Point3D e, Point3D n)
        {
            double d;

            if (camera.projection == 0)
            {

                d = camera.zoom / e.y;
                n.x = d * e.x / tanthetah;
                n.y = e.y;
                n.z = d * e.z / tanthetav;

            }
            else
            {

                n.x = camera.zoom * e.x / tanthetah;
                n.y = e.y;
                n.z = camera.zoom * e.z / tanthetav;
            }
        }
Exemple #22
0
 static void Main()
 {
     Point3D firstPoint = new Point3D(0, 1, 2);
     Console.WriteLine(firstPoint);
     Console.WriteLine(Point3D.StartingPoint);
 }
Exemple #23
0
        public bool Trans_ClipEye(Point3D e1, Point3D e2)
        {
            double mu;

            /* Is the vector totally in front of the front cutting plane ? */
            if (e1.y <= camera.front && e2.y <= camera.front)
            {

                return (false);
            }

            /* Is the vector totally behind the back cutting plane ? */
            if (e1.y >= camera.back && e2.y >= camera.back)
            {

                return (false);
            }

            /* Is the vector partly in front of the front cutting plane ? */
            if ((e1.y < camera.front && e2.y > camera.front) ||
               (e1.y > camera.front && e2.y < camera.front))
            {

                mu = (camera.front - e1.y) / (e2.y - e1.y);
                if (e1.y < camera.front)
                {
                    e1.x = e1.x + mu * (e2.x - e1.x);
                    e1.z = e1.z + mu * (e2.z - e1.z);
                    e1.y = camera.front;
                }
                else
                {
                    e2.x = e1.x + mu * (e2.x - e1.x);
                    e2.z = e1.z + mu * (e2.z - e1.z);
                    e2.y = camera.front;
                }
            }
            /* Is the vector partly behind the back cutting plane ? */
            if ((e1.y < camera.back && e2.y > camera.back) ||
               (e1.y > camera.back && e2.y < camera.back))
            {
                mu = (camera.back - e1.y) / (e2.y - e1.y);
                if (e1.y < camera.back)
                {
                    e2.x = e1.x + mu * (e2.x - e1.x);
                    e2.z = e1.z + mu * (e2.z - e1.z);
                    e2.y = camera.back;
                }
                else
                {
                    e1.x = e1.x + mu * (e2.x - e1.x);
                    e1.z = e1.z + mu * (e2.z - e1.z);
                    e1.y = camera.back;
                }
            }

            return (true);
        }
Exemple #24
0
 public Figure3D(Point3D origin)
 {
     this.origin = origin;
     this.makeRectangle(origin);
 }
Exemple #25
0
 public Point3D(Point3D p)
 {
     x = p.x;
     y = p.y;
     z = p.z;
 }
Exemple #26
0
        public bool Trans_ClipNorm(Point3D n1, Point3D n2)
        {
            double mu;

            /* Is the line segment totally right of x = 1 ? */
            if (n1.x >= 1 && n2.x >= 1)
                return (false);

            /* Is the line segment totally left of x = -1 ? */
            if (n1.x <= -1 && n2.x <= -1)
                return (false);

            /* Does the vector cross x = 1 ? */
            if ((n1.x > 1 && n2.x < 1) || (n1.x < 1 && n2.x > 1))
            {

                mu = (1 - n1.x) / (n2.x - n1.x);
                if (n1.x < 1)
                {
                    n2.z = n1.z + mu * (n2.z - n1.z);
                    n2.x = 1;
                }
                else
                {
                    n1.z = n1.z + mu * (n2.z - n1.z);
                    n1.x = 1;
                }
            }

            /* Does the vector cross x = -1 ? */
            if ((n1.x < -1 && n2.x > -1) || (n1.x > -1 && n2.x < -1))
            {

                mu = (-1 - n1.x) / (n2.x - n1.x);
                if (n1.x > -1)
                {
                    n2.z = n1.z + mu * (n2.z - n1.z);
                    n2.x = -1;
                }
                else
                {
                    n1.z = n1.z + mu * (n2.z - n1.z);
                    n1.x = -1;
                }
            }

            /* Is the line segment totally above z = 1 ? */
            if (n1.z >= 1 && n2.z >= 1)
                return (false);

            /* Is the line segment totally below z = -1 ? */
            if (n1.z <= -1 && n2.z <= -1)
                return (false);

            /* Does the vector cross z = 1 ? */
            if ((n1.z > 1 && n2.z < 1) || (n1.z < 1 && n2.z > 1))
            {

                mu = (1 - n1.z) / (n2.z - n1.z);
                if (n1.z < 1)
                {
                    n2.x = n1.x + mu * (n2.x - n1.x);
                    n2.z = 1;
                }
                else
                {
                    n1.x = n1.x + mu * (n2.x - n1.x);
                    n1.z = 1;
                }
            }

            /* Does the vector cross z = -1 ? */
            if ((n1.z < -1 && n2.z > -1) || (n1.z > -1 && n2.z < -1))
            {

                mu = (-1 - n1.z) / (n2.z - n1.z);
                if (n1.z > -1)
                {
                    n2.x = n1.x + mu * (n2.x - n1.x);
                    n2.z = -1;
                }
                else
                {
                    n1.x = n1.x + mu * (n2.x - n1.x);
                    n1.z = -1;
                }

            }

            return (true);
        }
Exemple #27
0
 public void AddPoint(Point3D p)
 {
     this.points.Add(p);
 }
Exemple #28
0
 static Point3D()
 {
     Point3D.startingPoint = new Point3D(0, 0, 0);
 }