bool checkPointBelongLine(Point4D M, Point4D N, Point4D A, double eps)
        {
            if (M.Equals(A) || N.Equals(A))
            {
                return(true);
            }
            double t = Math.Abs(calculateCosVectors(N.X - M.X,
                                                    N.Y - M.Y,
                                                    N.Z - M.Z,
                                                    N.W - M.W,
                                                    A.X - M.X,
                                                    A.Y - M.Y,
                                                    A.Z - M.Z,
                                                    A.W - M.W));

            return(1 - eps < t && t < 1 + eps);
        }
        //проверка параллельности двух прямых
        int checkParallelLines(Point4D M, Point4D N, Point4D A, Point4D B, double eps)
        {
            /*
             * Point4D Q1 = new Point4D(M.X + B.X - A.X,
             *                       M.Y + B.Y - A.Y,
             *                       M.Z + B.Z - A.Z, 1);
             * if (checkPointBelongLine(M, N, Q1, eps))
             *  return 1;
             *
             * Point4D Q2 = new Point4D(A.X + N.X - M.X,
             *                       A.Y + N.Y - M.Y,
             *                       A.Z + N.Z - M.Z, 1);
             * if (checkPointBelongLine(A, B, Q2, eps))
             *  return 1;
             */

            if (checkСrossLines(M, N, A, B) == 0)
            {
                double ValueA = calculateCosVectors(N.X - M.X,
                                                    N.Y - M.Y,
                                                    N.Z - M.Z,
                                                    N.W - M.W,
                                                    N.X - A.X,
                                                    N.Y - A.Y,
                                                    N.Z - A.Z,
                                                    N.W - A.W);
                double ValueB = calculateCosVectors(A.X - B.X,
                                                    A.Y - B.Y,
                                                    A.Z - B.Z,
                                                    A.W - B.W,
                                                    A.X - N.X,
                                                    A.Y - N.Y,
                                                    A.Z - N.Z,
                                                    A.W - N.W);
                if (ValueA != 0 && ValueB != 0)
                {
                    if (Math.Abs(ValueA) == Math.Abs(ValueB))
                    {
                        return(1);
                    }
                }
            }
            return(0);
        }
        //MN - прямая, ABC - прямая
        //пересечение двух прямых
        Point4D intersectionLines(Point4D M, Point4D N, Point4D A, Point4D B, double eps)
        {
            if (checkСrossLines(M, N, A, B) == 0 &&
                checkSameLines(M, N, A, B, eps) == 0 &&
                checkParallelLines(M, N, A, B, eps) == 0 && !A.Equals(B))
            {
                Point4D Vector = calculateCompositionVectors(B.X - A.X,
                                                             B.Y - A.Y,
                                                             B.Z - A.Z,
                                                             N.X - M.X,
                                                             N.Y - M.Y,
                                                             N.Z - M.Z);

                Point4D Z = new Point4D(Vector.X + A.X, Vector.Y + A.Y, Vector.Z + A.Z, 1);
                Point4D T = intersectionFlatLine(M, N, A, B, Z, eps);
                return(T);
            }
            return(null);
        }
        //MN - прямая, ABC - плоскость
        //пересечение прямой с плоскостью
        Point4D intersectionFlatLine(Point4D M, Point4D N, Point4D A, Point4D B, Point4D C, double eps)
        {
            double[] coefficient = methodNewell(A, B, C);
            double   a           = coefficient[0],
                     b           = coefficient[1],
                     c           = coefficient[2],
                     d           = coefficient[3];
            double t             = (-1) * ((M.X * a + M.Y * b + M.Z * c + d) /
                                           ((N.X - M.X) * a + (N.Y - M.Y) * b + (N.Z - M.Z) * c));

            if ((-1) * eps <= t && t <= eps + 1)
            {
                Point4D T = new Point4D(0, 0, 0, 1);
                T.X = (M.X + (N.X - M.X) * t);
                T.Y = (M.Y + (N.Y - M.Y) * t);
                T.Z = (M.Z + (N.Z - M.Z) * t);
                return(T);
            }
            return(null); //должно вернуть 0
        }
        //проверка совпадения двух прямых
        int checkSameLines(Point4D M, Point4D N, Point4D A, Point4D B, double eps)
        {
            if (checkPointBelongLine(M, N, A, eps))
            {
                if (checkPointBelongLine(M, N, B, eps))
                {
                    return(1);
                }
            }

            if (checkPointBelongLine(A, B, M, eps))
            {
                if (checkPointBelongLine(A, B, N, eps))
                {
                    return(1);
                }
            }

            return(0);
        }
        /////////////////////////////////////////////////////////////////////////////////////////////////////

        //метод Ньюэла
        double[] methodNewell(Point4D p1, Point4D p2, Point4D p3)
        {
            double[] coefficient = new double[4];
            coefficient[0] = (p1.Y - p2.Y) * (p1.Z + p2.Z) +
                             (p2.Y - p3.Y) * (p2.Z + p3.Z) +
                             (p3.Y - p1.Y) * (p3.Z + p1.Z);

            coefficient[1] = (p1.Z - p2.Z) * (p1.X + p2.X) +
                             (p2.Z - p3.Z) * (p2.X + p3.X) +
                             (p3.Z - p1.Z) * (p3.X + p1.X);

            coefficient[2] = (p1.X - p2.X) * (p1.Y + p2.Y) +
                             (p2.X - p3.X) * (p2.Y + p3.Y) +
                             (p3.X - p1.X) * (p3.Y + p1.Y);

            coefficient[3] = -(coefficient[0] * p1.X +
                               coefficient[1] * p1.Y +
                               coefficient[2] * p1.Z);
            return(coefficient);
        }
        //проверка параллельности прямой и плоскости
        int checkLineParallelFlat(Point4D M, Point4D N, Point4D A, Point4D B, Point4D C, double eps)
        {
            if (checkLineBelongFlat(M, N, A, B, C) == 0)
            {
                double[] coefficient = methodNewell(A, B, C);
                double   a           = coefficient[0],
                         b           = coefficient[1],
                         c           = coefficient[2],
                         d           = coefficient[3];

                if (a * (M.X - N.X) + b * (M.Y - N.Y) + c * (M.Z - N.Z) == 0)
                {
                    return(1);
                }
            }


            //if (intersectionFlatLine(M, N, A, B, C, eps) == null && checkLineBelongFlat(M, N, A, B, C) == 0)
            //    return 1;
            return(0);
        }
        public void VisibleMN(Point4D M, Point4D N, Point4D A, Point4D B, Point4D C, Point4D L, Point4D T, double eps, ref bool isVisMN, ref bool isVisM, ref bool isVisN, ref bool isNoVis)
        {
            isVisMN = false; isVisM = false; isVisN = false; isNoVis = false;
            Section4D VisibleSection = sectionVisibleLine(M, N, A, B, C, L, T, eps);
            Section4D compare1       = new Section4D(M, N);
            Section4D compare2       = new Section4D(M, T);
            Section4D compare3       = new Section4D(T, N);

            if (VisibleSection == null)
            {
                return;
            }
            if (!compare1.CheckNull())
            {
                if (VisibleSection.Equals(compare1))
                {
                    isVisMN = true;
                    return;
                }
            }

            if (!compare2.CheckNull())
            {
                if (VisibleSection.Equals(compare2))
                {
                    isVisM = true;
                    return;
                }
            }

            if (!compare3.CheckNull())
            {
                if (VisibleSection.Equals(compare3))
                {
                    isVisN = true;
                    return;
                }
            }
            isNoVis = true;
        }
Пример #9
0
        public Axonomertry(Point4D[] p4d, Point4D p4dT, Section4D section4d, int lengthAxis, int indent, double eps, bool changeL)
        {
            red        = new Pen(Color.Red);
            green      = new Pen(Color.Green);
            blue       = new Pen(Color.Blue);
            black      = new Pen(Color.Black);
            aqua       = new Pen(Color.Aqua, 2);
            darkOrange = new Pen(Color.DarkOrange, 2);

            this.changeL = changeL;

            this.p4d       = p4d;
            p4dTrans       = new Point4D[p4d.Length];
            p2d            = new Point2D[p4d.Length];
            this.p4dT      = p4dT;
            this.section4d = section4d;
            sectionTrans   = new Section4D();
            section2d      = new Section2D();


            transformMatrix = new MatrixTransform();
            operations      = new Operations3D();
            Rz = new Matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
            Rx = new Matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
            Mx = new Matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
            Pz = new Matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
            T  = new Matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);

            Ao = new Matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
            Cz = new Matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
            Ac = new Matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);

            this.Lx         = p4d[5].X;
            this.Ly         = p4d[5].Y;
            this.Lz         = p4d[5].Z;
            this.eps        = eps;
            this.lengthAxis = lengthAxis;
            this.indent     = indent;
        }
        public Section4D pointsTIntersection(Point4D M, Point4D N, Point4D A, Point4D B, Point4D C, double eps)
        {
            if (checkDegenLine(M, N) == 0 && checkDegenFlat(A, B, C) == 0)
            {
                if (checkLineBelongFlat(M, N, A, B, C) == 1)
                {
                    statusMessage = "Прямая лежит на плоскости";
                    return(new Section4D(M, N));
                }
            }


            //if (checkDegenLine(M, N) == 0 && checkDegenFlat(A, B, C) == 1)
            //    if (checkSameLines(M, N, A, B, eps) == 1 || checkSameLines(M, N, A, C, eps) == 1 || checkSameLines(M, N, B, C, eps) == 1)
            //    {
            //        statusMessage = "Прямая лежит на прямой";
            //        return new Section4D(M, N);
            //    }

            if (checkDegenLine(M, N) == 0 && checkDegenFlat(A, B, C) == 1)
            {
                if (checkSameLines(M, N, A, B, eps) == 1 && !A.Equals(B))
                {
                    statusMessage = "Прямая лежит на прямой";
                    return(new Section4D(M, N));
                }
                if (checkSameLines(M, N, A, C, eps) == 1 && !A.Equals(C))
                {
                    statusMessage = "Прямая лежит на прямой";
                    return(new Section4D(M, N));
                }
                if (checkSameLines(M, N, B, C, eps) == 1 && !B.Equals(C))
                {
                    statusMessage = "Прямая лежит на прямой";
                    return(new Section4D(M, N));
                }
            }
            return(null);
        }
Пример #11
0
        void transformTforCentral()
        {
            if (p4dT != null)
            {
                p4dT = p4dT * Ac;
                p4dT = new Point4D
                       (
                    p4dT.X / p4dT.W,
                    p4dT.Y / p4dT.W,
                    p4dT.Z / p4dT.W,
                    p4dT.W / p4dT.W
                       );
                p2dT = transformPoint(p4dT);
            }
            else if (section4d != null)
            {
                sectionTrans.Start = section4d.Start * Ac;
                sectionTrans.End   = section4d.End * Ac;

                sectionTrans.Start = new Point4D
                                     (
                    sectionTrans.Start.X / sectionTrans.Start.W,
                    sectionTrans.Start.Y / sectionTrans.Start.W,
                    sectionTrans.Start.Z / sectionTrans.Start.W,
                    sectionTrans.Start.W / sectionTrans.Start.W
                                     );

                sectionTrans.End = new Point4D
                                   (
                    sectionTrans.End.X / sectionTrans.End.W,
                    sectionTrans.End.Y / sectionTrans.End.W,
                    sectionTrans.End.Z / sectionTrans.End.W,
                    sectionTrans.End.W / sectionTrans.End.W
                                   );
                section2d.Start = transformPoint(sectionTrans.Start);
                section2d.End   = transformPoint(sectionTrans.End);
            }
        }
Пример #12
0
 void transformPointsForCentral()
 {
     for (int i = 0; i < p4d.Length; i++)
     {
         if (p4d[i].name == "X" || p4d[i].name == "Y" || p4d[i].name == "Z")
         {
             p4dTrans[i] = p4d[i] * Ao;
         }
         else
         {
             p4dTrans[i] = p4d[i] * Ac;
             p4dTrans[i] = new Point4D
                           (
                 p4dTrans[i].X / p4dTrans[i].W,
                 p4dTrans[i].Y / p4dTrans[i].W,
                 p4dTrans[i].Z / p4dTrans[i].W,
                 p4dTrans[i].W / p4dTrans[i].W,
                 p4dTrans[i].name, p4dTrans[i].color
                           );
         }
         p2d[i] = transformPoint(p4dTrans[i]);
     }
 }
 //вырожденность плоскости в точку (проверка)
 bool checkFlatAtPoint(Point4D A, Point4D B, Point4D C)
 {
     return(A.Equals(B) && B.Equals(C));
 }
Пример #14
0
 Point2D transformPoint(Point4D p4d)
 {
     return(new Point2D(p4d.X, p4d.Y, p4d.name, p4d.color));
 }
Пример #15
0
 public Section4D(double x1, double y1, double z1, double x2, double y2, double z2)
 {
     Start = new Point4D(x1, y1, z1, 1);
     End   = new Point4D(x2, y2, z2, 1);
 }
Пример #16
0
 public Section4D(Point4D Start, Point4D End)
 {
     this.Start = Start;
     this.End   = End;
 }
Пример #17
0
 public Section4D()
 {
     Start = new Point4D(0, 0, 0, 1);
     End   = new Point4D(0, 0, 0, 1);
 }
 public bool Equals(Point4D point)
 {
     return(X == point.X && Y == point.Y && Z == point.Z);
 }
 public static Point4D MatrixToPoint(Matrix A, Point4D point)
 {
     //
     return(new Point4D(A.matrix[0][0], A.matrix[0][1], A.matrix[0][2], A.matrix[0][3], point.name, point.color));
 }
 public Matrix PointToMatrix(Point4D point)
 {
     //
     return(new Matrix(point.X, point.Y, point.Z, point.W));
 }
        Section4D sectionVisibleLine(Point4D M, Point4D N, Point4D A, Point4D B, Point4D C, Point4D L, Point4D T, double eps)
        {
            double[] coefficient = methodNewell(A, B, C);
            double   a           = coefficient[0],
                     b           = coefficient[1],
                     c           = coefficient[2],
                     d           = coefficient[3];

            if (checkDegenFlat(A, B, C) > 0)
            {
                return(new Section4D(M, N));
            }

            if (checkLookAtObserved(a, b, c, d, L, eps) == 0)
            {
                a = -1 * a;
                b = -1 * b;
                c = -1 * c;
                d = -1 * d;
            }

            if (checkPositionFlat(a, b, c, d, L, eps) == 0)
            {
                return(new Section4D(M, N));
            }

            if (calculateCosVectors(a, b, c, d, M.X, M.Y, M.Z, N.W) >= 0)
            {
                if (calculateCosVectors(a, b, c, d, N.X, N.Y, N.Z, N.W) >= 0)
                {
                    return(new Section4D(M, N));
                }
                else
                {
                    return(new Section4D(M, T));
                }
            }
            else
            {
                if (calculateCosVectors(a, b, c, d, N.X, N.Y, N.Z, N.W) > 0)
                {
                    return(new Section4D(T, N));
                }
                else
                {
                    return(null);
                }
            }
        }
        /////////////////////////////////////////////////////////////////////////////////////////////////////

        public Point4D pointTIntersection(Point4D M, Point4D N, Point4D A, Point4D B, Point4D C, double eps, ref Label mesABC, ref Label mesMN)
        {
            Point4D T = null;

            if (checkDegenLine(M, N) == 0 && checkDegenFlat(A, B, C) == 0)
            {
                mesABC.Text = "Плоскость ABC"; mesMN.Text = "Прямая MN";
                T           = intersectionFlatLine(M, N, A, B, C, eps);
                if (T != null)
                {
                    statusMessage = "Пересечение прямой с плоскостью";
                }
                else
                {
                    if (checkLineParallelFlat(M, N, A, B, C, eps) == 1)
                    {
                        statusMessage = "Прямая и плоскость параллельны";
                    }
                    else
                    {
                        statusMessage = "Прямая и плоскость не пересекаются";
                    }
                }

                return(T);
            }

            if (checkDegenLine(M, N) == 0 && checkDegenFlat(A, B, C) == 1)
            {
                if (A.Equals(B))
                {
                    mesABC.Text = "Прямая AC(BC)";
                }
                if (A.Equals(C))
                {
                    mesABC.Text = "Прямая AB(BC)";
                }
                if (B.Equals(C))
                {
                    mesABC.Text = "Прямая AB(AC)";
                }

                mesMN.Text = "Прямая MN";


                if (intersectionLines(M, N, A, B, eps) != null)
                {
                    statusMessage = "Прямые MN и AB пересекаютcя";
                    return(intersectionLines(M, N, A, B, eps));
                }
                else
                {
                    statusMessage = "Прямые MN и AB не пересекаются";
                }

                if (intersectionLines(M, N, B, C, eps) != null)
                {
                    statusMessage = "Прямые MN и BC пересекаютcя";
                    return(intersectionLines(M, N, B, C, eps));
                }
                else
                {
                    statusMessage = "Прямые MN и BC не пересекаются";
                }

                if (intersectionLines(M, N, A, C, eps) != null)
                {
                    statusMessage = "Прямые MN и AC пересекаютcя";
                    return(intersectionLines(M, N, A, C, eps));
                }
                else
                {
                    statusMessage = "Прямые MN и AC не пересекаются";
                }

                if (checkParallelLines(M, N, A, B, eps) == 1 && !A.Equals(B))
                {
                    statusMessage = "Прямые MN и AB параллельны";
                }
                if (checkParallelLines(M, N, A, C, eps) == 1 && !A.Equals(C))
                {
                    statusMessage = "Прямые MN и AC параллельны";
                }
                if (checkParallelLines(M, N, B, C, eps) == 1 && !B.Equals(C))
                {
                    statusMessage = "Прямые MN и BC параллельны";
                }

                if (checkСrossLines(M, N, A, B) == 1)
                {
                    statusMessage = "Прямые MN и AB скрещиваются";
                }
                if (checkСrossLines(M, N, A, C) == 1)
                {
                    statusMessage = "Прямые MN и AC скрещиваются";
                }
                if (checkСrossLines(M, N, B, C) == 1)
                {
                    statusMessage = "Прямые MN и BC скрещиваются";
                }
            }

            if (checkDegenLine(M, N) == 0 && checkDegenFlat(A, B, C) == 2)
            {
                mesABC.Text = "Точка A(B, C)"; mesMN.Text = "Прямая MN";
                T           = intersectionPointLine2(M, N, A, eps);
                if (T != null)
                {
                    statusMessage = "Пересечение прямой с точкой";
                }
                else
                {
                    statusMessage = "Прямая и точка не пересекаются";
                }
                return(T);
            }

            if (checkDegenLine(M, N) == 1 && checkDegenFlat(A, B, C) == 0)
            {
                mesABC.Text = "Плоскость ABC"; mesMN.Text = "Точка M(N)";

                T = intersectionPointFlat(M, A, B, C);
                if (T != null)
                {
                    statusMessage = "Пересечение точки с плоскостью";
                }
                else
                {
                    statusMessage = "Точка и плоскость не пересекаются";
                }
                return(T);
            }

            if (checkDegenLine(M, N) == 1 && checkDegenFlat(A, B, C) == 1)
            {
                if (A.Equals(B))
                {
                    mesABC.Text = "Прямая AC(BC)";
                }
                if (A.Equals(C))
                {
                    mesABC.Text = "Прямая AB(BC)";
                }
                if (B.Equals(C))
                {
                    mesABC.Text = "Прямая AB(AC)";
                }

                mesMN.Text = "Точка M(N)";

                if (intersectionPointLine(A, B, M, eps) != null)
                {
                    T = intersectionPointLine(A, B, M, eps);
                }
                if (intersectionPointLine(B, C, M, eps) != null)
                {
                    T = intersectionPointLine(B, C, M, eps);
                }
                if (intersectionPointLine(A, C, N, eps) != null)
                {
                    T = intersectionPointLine(A, C, N, eps);
                }

                if (T != null)
                {
                    statusMessage = "Пересечение прямой с точкой";
                }
                else
                {
                    statusMessage = "Прямая и точка не пересекаются";
                }
                return(T);
            }

            if (checkDegenLine(M, N) == 1 && checkDegenFlat(A, B, C) == 2)
            {
                mesABC.Text = "Точка A(B, C)"; mesMN.Text = "Точка M(N)";

                T = intersectionPoints(M, A);

                if (T != null)
                {
                    statusMessage = "Пересечение двух точек";
                }
                else
                {
                    statusMessage = "Две точки не пересекаются";
                }
                return(T);
            }
            //statusMessage = "";
            return(null);
        }