Example #1
0
        public static Polyhedron CreateTetrahedron(My_Point a, My_Point b, My_Point q)
        {
            My_Point c       = GetThirdVertexForTriangle(a, b, q);
            Vector   m       = new Vector(a, b);
            Vector   n       = new Vector(a, c);
            double   sideLen = m.Norm();
            double   hLen    = sideLen * Math.Sqrt(6) / 3.0;
            Vector   h       = m[n].Normalize() * hLen;
            Vector   r       = h + ((m + n) * (1.0 / 3.0));
            My_Point d       = new My_Point(a.X + r.X, a.Y + r.Y, a.Z + r.Z);

            Polyhedron Tetrahedron = new Polyhedron();

            Tetrahedron.faces    = new Face[4];
            Tetrahedron.faces[0] = Face.CreateTriangle(a, b, c);
            Tetrahedron.faces[1] = Face.CreateTriangle(a, b, d);
            Tetrahedron.faces[2] = Face.CreateTriangle(a, c, d);
            Tetrahedron.faces[3] = Face.CreateTriangle(b, c, d);

            double cx = (a.X + b.X + c.X + d.X) / 4;
            double cy = (a.Y + b.Y + c.Y + d.Y) / 4;
            double cz = (a.Z + b.Z + c.Z + d.Z) / 4;

            Tetrahedron.center = new My_Point(cx, cy, cz);

            return(Tetrahedron);
        }
Example #2
0
        public static Polyhedron CreateHexahedron(My_Point a, My_Point b, My_Point q)
        {
            My_Point[] cd      = GetVertecesForSquare(a, b, q);
            My_Point   c       = cd[0];
            My_Point   d       = cd[1];
            Vector     m       = new Vector(a, b);
            Vector     n       = new Vector(a, c);
            double     sideLen = m.Norm();
            Vector     h       = m[n].Normalize() * sideLen;
            My_Point   a1      = new My_Point(a.X + h.X, a.Y + h.Y, a.Z + h.Z);
            My_Point   b1      = new My_Point(b.X + h.X, b.Y + h.Y, b.Z + h.Z);
            My_Point   c1      = new My_Point(c.X + h.X, c.Y + h.Y, c.Z + h.Z);
            My_Point   d1      = new My_Point(d.X + h.X, d.Y + h.Y, d.Z + h.Z);

            Polyhedron Hexahedron = new Polyhedron();

            Hexahedron.faces    = new Face[6];
            Hexahedron.faces[0] = Face.CreateSquare(a, b, c, d);
            Hexahedron.faces[1] = Face.CreateSquare(a, b, b1, a1);
            Hexahedron.faces[2] = Face.CreateSquare(b, c, c1, b1);
            Hexahedron.faces[3] = Face.CreateSquare(c, d, d1, c1);
            Hexahedron.faces[4] = Face.CreateSquare(a, d, d1, a1);
            Hexahedron.faces[5] = Face.CreateSquare(a1, b1, c1, d1);

            double cx = (a.X + c1.X) / 2;
            double cy = (a.Y + c1.Y) / 2;
            double cz = (a.Z + c1.Z) / 2;

            Hexahedron.center = new My_Point(cx, cy, cz);

            return(Hexahedron);
        }
Example #3
0
        public static Polyhedron CreateOktahedron(My_Point a, My_Point b, My_Point q)
        {
            Polyhedron Hexahedron = CreateHexahedron(new My_Point(0, 0, 0), new My_Point(1, 0, 0), new My_Point(0, 1, 0));

            My_Point[] verts = new My_Point[6];
            for (int i = 0; i < 6; ++i)
            {
                double x = (Hexahedron.faces[i].Edges[0].First.X + Hexahedron.faces[i].Edges[1].First.X + Hexahedron.faces[i].Edges[2].First.X + Hexahedron.faces[i].Edges[3].First.X) / 2;
                double y = (Hexahedron.faces[i].Edges[0].First.Y + Hexahedron.faces[i].Edges[1].First.Y + Hexahedron.faces[i].Edges[2].First.Y + Hexahedron.faces[i].Edges[3].First.Y) / 2;
                double z = (Hexahedron.faces[i].Edges[0].First.Z + Hexahedron.faces[i].Edges[1].First.Z + Hexahedron.faces[i].Edges[2].First.Z + Hexahedron.faces[i].Edges[3].First.Z) / 2;
                verts[i] = new My_Point(x, y, z);                 //Каждая координата - центр тяжести грани
            }

            Polyhedron Oktahedron = new Polyhedron();

            Oktahedron.faces = new Face[8];

            Oktahedron.faces[0] = Face.CreateTriangle(verts[0], verts[1], verts[2]);
            Oktahedron.faces[1] = Face.CreateTriangle(verts[0], verts[2], verts[3]);
            Oktahedron.faces[2] = Face.CreateTriangle(verts[0], verts[3], verts[4]);
            Oktahedron.faces[3] = Face.CreateTriangle(verts[0], verts[4], verts[1]);
            Oktahedron.faces[4] = Face.CreateTriangle(verts[5], verts[1], verts[2]);
            Oktahedron.faces[5] = Face.CreateTriangle(verts[5], verts[2], verts[3]);
            Oktahedron.faces[6] = Face.CreateTriangle(verts[5], verts[3], verts[4]);
            Oktahedron.faces[7] = Face.CreateTriangle(verts[5], verts[4], verts[1]);

            Oktahedron.center = Hexahedron.center;

            return(Oktahedron);
        }
Example #4
0
        public static Polyhedron CreateDodecahedron()
        {
            Polyhedron Icosahedron = CreateIcosahedron();

            My_Point[] verts = new My_Point[20];
            for (int i = 0; i < 20; ++i)
            {
                double x = (Icosahedron.faces[i].Edges[0].First.X + Icosahedron.faces[i].Edges[1].First.X + Icosahedron.faces[i].Edges[2].First.X) / 3;
                double y = (Icosahedron.faces[i].Edges[0].First.Y + Icosahedron.faces[i].Edges[1].First.Y + Icosahedron.faces[i].Edges[2].First.Y) / 3;
                double z = (Icosahedron.faces[i].Edges[0].First.Z + Icosahedron.faces[i].Edges[1].First.Z + Icosahedron.faces[i].Edges[2].First.Z) / 3;
                verts[i] = new My_Point(x, y, z);                 //Каждая координата - центр тяжести грани
            }

            Polyhedron Dodecahedron = new Polyhedron();

            Dodecahedron.faces     = new Face[12];
            Dodecahedron.faces[0]  = Face.CreatePentagon(verts[0], verts[2], verts[4], verts[6], verts[8]);
            Dodecahedron.faces[1]  = Face.CreatePentagon(verts[1], verts[3], verts[5], verts[7], verts[9]);
            Dodecahedron.faces[2]  = Face.CreatePentagon(verts[2], verts[0], verts[10], verts[11], verts[12]);
            Dodecahedron.faces[3]  = Face.CreatePentagon(verts[3], verts[1], verts[11], verts[12], verts[13]);
            Dodecahedron.faces[4]  = Face.CreatePentagon(verts[4], verts[2], verts[12], verts[13], verts[14]);
            Dodecahedron.faces[5]  = Face.CreatePentagon(verts[5], verts[3], verts[13], verts[14], verts[15]);
            Dodecahedron.faces[6]  = Face.CreatePentagon(verts[6], verts[4], verts[14], verts[15], verts[16]);
            Dodecahedron.faces[7]  = Face.CreatePentagon(verts[7], verts[5], verts[15], verts[16], verts[17]);
            Dodecahedron.faces[8]  = Face.CreatePentagon(verts[8], verts[6], verts[16], verts[17], verts[18]);
            Dodecahedron.faces[9]  = Face.CreatePentagon(verts[9], verts[7], verts[17], verts[18], verts[19]);
            Dodecahedron.faces[10] = Face.CreatePentagon(verts[0], verts[8], verts[18], verts[19], verts[10]);
            Dodecahedron.faces[11] = Face.CreatePentagon(verts[9], verts[1], verts[11], verts[10], verts[19]);

            Dodecahedron.center = new My_Point(0, 0, 0);

            return(Dodecahedron);
        }
Example #5
0
        //Поворот вокруг оси
        public static void Rotate(Polyhedron polyhedron, My_Point a, My_Point b, double anglPhi)
        {
            double m = b.X - a.X;
            double n = b.Y - a.Y;
            double p = b.Z - a.Z;
            double s = Math.Sqrt(m * m + n * n);
            double d = Math.Sqrt(m * m + n * n + p * p);

            AffineMatrix m0;

            if (Math.Abs(s) < 1e-6)
            {
                AffineMatrix m1 = AffineMatrix.TranslationMatrix(-a.X, -a.Y, -a.Z);
                AffineMatrix m4 = AffineMatrix.ZaxisRotationMatrix(anglPhi);
                AffineMatrix m7 = AffineMatrix.TranslationMatrix(a.X, a.Y, a.Z);
                m0 = m7 * m4 * m1;
            }
            else
            {
                AffineMatrix m1 = AffineMatrix.TranslationMatrix(-a.X, -a.Y, -a.Z);
                AffineMatrix m2 = AffineMatrix.ZaxisRotationMatrix(n / s, m / s);
                AffineMatrix m3 = AffineMatrix.XaxisRotationMatrix(p / d, s / d);
                AffineMatrix m4 = AffineMatrix.ZaxisRotationMatrix(anglPhi);
                AffineMatrix m5 = AffineMatrix.XaxisRotationMatrix(p / d, -s / d);
                AffineMatrix m6 = AffineMatrix.ZaxisRotationMatrix(n / s, -m / s);
                AffineMatrix m7 = AffineMatrix.TranslationMatrix(a.X, a.Y, a.Z);
                m0 = m7 * m6 * m5 * m4 * m3 * m2 * m1;
            }
            Execute(polyhedron, m0);
        }
Example #6
0
        public static Face CreateTriangle(My_Point a, My_Point b, My_Point c)
        {
            Face Triangle = new Face();

            Triangle.edges = new Edge[3];

            Triangle.edges[0] = new Edge(a, b);
            Triangle.edges[1] = new Edge(b, c);
            Triangle.edges[2] = new Edge(c, a);

            return(Triangle);
        }
Example #7
0
        private static My_Point GetThirdVertexForTriangle(My_Point a, My_Point b, My_Point q)
        {
            Vector m       = new Vector(a, b);
            Vector n       = new Vector(a, q);
            double sideLen = m.Norm();
            double hLen    = sideLen * Math.Sqrt(3) / 2.0;

            double coeff = (m * n) / (m * m);
            Vector h     = (n - (coeff * m)).Normalize() * hLen;
            Vector r     = (0.5 * m) + h;

            return(new My_Point(a.X + r.X, a.Y + r.Y, a.Z + r.Z));
        }
Example #8
0
        public static Face CreateSquare(My_Point a, My_Point b, My_Point c, My_Point d)
        {
            Face Square = new Face();

            Square.edges = new Edge[4];

            Square.edges[0] = new Edge(a, b);
            Square.edges[1] = new Edge(b, c);
            Square.edges[2] = new Edge(c, d);
            Square.edges[3] = new Edge(d, a);

            return(Square);
        }
Example #9
0
        public static Face CreatePentagon(My_Point a, My_Point b, My_Point c, My_Point d, My_Point e)
        {
            Face Pentagon = new Face();

            Pentagon.edges = new Edge[5];

            Pentagon.edges[0] = new Edge(a, b);
            Pentagon.edges[1] = new Edge(b, c);
            Pentagon.edges[2] = new Edge(c, d);
            Pentagon.edges[3] = new Edge(d, e);
            Pentagon.edges[4] = new Edge(e, a);

            return(Pentagon);
        }
Example #10
0
        public static Polyhedron CreateIcosahedron()
        {
            Polyhedron Icosahedron = new Polyhedron();

            My_Point[] verts = new My_Point[12];

            // верх и низ
            verts[0] = new My_Point(0, 0, 1);
            verts[1] = new My_Point(0, 0, -1);

            double h = Math.Sqrt(5) / 5;              //0.447
            double R = h / Math.Sin(Math.PI / 5);     //0.76

            // верхний круг
            double angle = 0;

            for (int i = 2; i < 7; ++i)
            {
                verts[i] = new My_Point(R * Math.Sin(angle), R * Math.Cos(angle), h);
                angle   += 72 * Math.PI / 180;               // 180/5 = 72
            }

            // нижний круг
            angle = 36 * Math.PI / 180;
            for (int i = 7; i < 12; ++i)
            {
                verts[i] = new My_Point(R * Math.Sin(angle), R * Math.Cos(angle), -h);
                angle   += 72 * Math.PI / 180;               // 180/5 = 72
            }

            Icosahedron.faces = new Face[20];
            for (int i = 0; i < 4; ++i)
            {
                Icosahedron.faces[2 * i]     = Face.CreateTriangle(verts[0], verts[2 + i], verts[3 + i]);             //Заполнение верхней пирамиды
                Icosahedron.faces[2 * i + 1] = Face.CreateTriangle(verts[1], verts[7 + i], verts[8 + i]);             //Заполенение нижней пирамиды
            }
            Icosahedron.faces[8] = Face.CreateTriangle(verts[0], verts[2], verts[6]);
            Icosahedron.faces[9] = Face.CreateTriangle(verts[1], verts[7], verts[11]);

            for (int i = 0; i < 4; ++i)
            {
                Icosahedron.faces[10 + 2 * i] = Face.CreateTriangle(verts[2 + i], verts[3 + i], verts[7 + i]);
                Icosahedron.faces[11 + 2 * i] = Face.CreateTriangle(verts[7 + i], verts[8 + i], verts[3 + i]);
            }
            Icosahedron.faces[18] = Face.CreateTriangle(verts[6], verts[2], verts[11]);
            Icosahedron.faces[19] = Face.CreateTriangle(verts[11], verts[7], verts[2]);

            Icosahedron.center = new My_Point(0, 0, 0);
            return(Icosahedron);
        }
Example #11
0
        //Действия
        private void Draw()
        {
            if (polyhedron == null)
            {
                return;
            }
            g.Clear(Color.White);

            My_Point.DrawPoint0(g, Color.LimeGreen);

            Polyhedron proj = polyhedron.Clone() as Polyhedron;

            AffineTransform.IsometricProjection(proj);

            proj.Draw(g, Color.Black);
        }
Example #12
0
        private static My_Point[] GetVertecesForSquare(My_Point a, My_Point b, My_Point q)
        {
            Vector m       = new Vector(a, b);
            Vector n       = new Vector(a, q);
            double sideLen = m.Norm();

            double   coeff = (m * n) / (m * m);
            Vector   h     = (n - (coeff * m)).Normalize() * sideLen;
            Vector   r     = m + h;
            My_Point c     = new My_Point(a.X + r.X, a.Y + r.Y, a.Z + r.Z);
            My_Point d     = new My_Point(a.X + h.X, a.Y + h.Y, a.Z + h.Z);

            return(new My_Point[2] {
                c, d
            });
        }
Example #13
0
 public My_Point(My_Point a)
 {
     x = a.x;
     y = a.y;
     z = a.z;
 }
Example #14
0
 public Edge(My_Point a, My_Point b)
 {
     this.a = new My_Point(a);
     this.b = new My_Point(b);
 }
Example #15
0
 public Vector(My_Point a)
 {
     this.x = a.X;
     this.y = a.Y;
     this.z = a.Z;
 }
Example #16
0
 public Vector(My_Point a, My_Point b)
 {
     this.x = b.X - a.X;
     this.y = b.Y - a.Y;
     this.z = b.Z - a.Z;
 }
Example #17
0
 public void Copy(My_Point a)
 {
     x = a.x;
     y = a.y;
     z = a.z;
 }