Ejemplo n.º 1
0
        public static Point3DF PointF(Line line, double Lambda)
        {
            Point3DF vector = Line.Vector(line);
            Point3DF Point  = line.StartLine + vector * Lambda;

            return(Point);
        }
Ejemplo n.º 2
0
        public static Object operator -(Object obj, Double[] Mas)
        {
            if (Mas.Length != 3)
            {
                return(null);
            }
            Object RezultObject = new Object();

            for (int i = 0; i < obj.Poligons.Count; i++)
            {
                Poligon ChangePoligon = obj.Poligons[i] - Mas;
                RezultObject.Poligons.Add(ChangePoligon);
            }
            for (int i = 0; i < obj.Lines.Count; i++)
            {
                if (obj.Lines[i].OnlyLine)
                {
                    Line ChangeLine = obj.Lines[i] - Mas;
                    RezultObject.Lines.Add(ChangeLine);
                }
            }
            for (int i = 0; i < obj.Points.Count; i++)
            {
                if (obj.Points[i].OnlyPoint)
                {
                    Point3DF ChangePoint = obj.Points[i] - Mas;
                    RezultObject.Points.Add(ChangePoint);
                }
            }
            return(RezultObject);
        }
Ejemplo n.º 3
0
 public Line(Point3DF StartLine, Point3DF EndLine, bool OnlyLine, bool Visible)
 {
     this.StartLine = StartLine;
     this.EndLine   = EndLine;
     this.OnlyLine  = OnlyLine;
     this.Visible   = Visible;
 }
Ejemplo n.º 4
0
        internal void RefreshPictureBox(Point3DF LocationCam, Point3DF VzgladCam, List <Object> Wolrd)
        {
            List <Object>       WorldCam         = new List <Object>();
            List <Object>       WorldHide        = new List <Object>();
            List <List <Line> > WorldConvertTo2D = new List <List <Line> >();

            g.Clear(Color.White);
            //List<Object> Corworld = ConvertCoordinate.CorectObj(World);
            for (int i = 0; i < Wolrd.Count; i++)
            {
                WorldCam.Add(ConvertCoordinate.ConvertWorldtoCam(VzgladCam, LocationCam, World[i]));
            }
            //List<Object> CorworldCam = ConvertCoordinate.CorectObj(WorldCam);
            List <Line> lines   = HideLineCusk.CuskLineHide(WorldCam);
            List <Line> lines2D = ConvertCoordinate.Camto2D(lines, 5);

            drawing(lines2D, mash);/*
                                    * for (int i = 0; i < Wolrd.Count; i++)
                                    * WorldHide.Add(ConvertCoordinate.ObjectHideLine(WorldCam[i], WorldCam));
                                    * for (int i = 0; i < Wolrd.Count; i++)
                                    * WorldConvertTo2D.Add(ConvertCoordinate.Camto2D(WorldHide[i], 5));
                                    * for (int i = 0; i < Wolrd.Count; i++)
                                    * drawing(WorldConvertTo2D[i], mash);*/
            pictureBox1.Image = DrawArea;
        }
Ejemplo n.º 5
0
        public static Object operator *(Double[,] Mas, Object obj)
        {
            Object RezultObject = new Object();

            for (int i = 0; i < obj.Poligons.Count; i++)
            {
                Poligon ChangePoligon = Mas * obj.Poligons[i];
                RezultObject.Poligons.Add(ChangePoligon);
            }
            for (int i = 0; i < obj.Lines.Count; i++)
            {
                if (obj.Lines[i].OnlyLine)
                {
                    Line ChangeLine = Mas * obj.Lines[i];
                    RezultObject.Lines.Add(ChangeLine);
                }
            }
            for (int i = 0; i < obj.Points.Count; i++)
            {
                if (obj.Points[i].OnlyPoint)
                {
                    Point3DF ChangePoint = Mas * obj.Points[i];
                    RezultObject.Points.Add(ChangePoint);
                }
            }
            return(RezultObject);
        }
Ejemplo n.º 6
0
        static public bool PointHide(Point3DF point, List <Object> World)
        {
            Line LinePoint = new Line(point, new Point3DF(0, 0, 0), true);

            for (int NumObj = 0; NumObj < World.Count; NumObj++)
            {
                for (int NumPoligon = 0; NumPoligon < World[NumObj].Poligons.Count; NumPoligon++)
                {
                    double[] ABCD = Poligon.ABCDFound(World[NumObj].Poligons[NumPoligon], true);
                    double   t    = Line.PeresechPoint(ABCD, LinePoint);
                    if (Math.Round(t, 5) <= 0 || t > 1)
                    {
                        continue;
                    }
                    else
                    {
                        Point3DF PointPeresch = Line.PointF(LinePoint, t);
                        if (Poligon.InArea(World[NumObj].Poligons[NumPoligon], PointPeresch))
                        {
                            return(false);
                        }
                    }
                }
            }
            m1 :;
            return(true);
        }
Ejemplo n.º 7
0
        static public Point3DF Vector(Line line)
        {
            Point3DF Vector = new Point3DF(line.EndLine.X - line.StartLine.X,
                                           line.EndLine.Y - line.StartLine.Y,
                                           line.EndLine.Z - line.StartLine.Z);

            return(Vector);
        }
Ejemplo n.º 8
0
        static public bool EgualPoint(Point3DF P1, Point3DF P2)
        {
            bool rezult = P1.X == P2.X;

            rezult = (P1.Y == P2.Y) && rezult;
            rezult = (P1.Z == P2.Z) && rezult;
            return(rezult);
        }
Ejemplo n.º 9
0
 public TrasirLuch(List <Object> WorldCam, Point3DF Sun, Color ColorSun, double focus, double mashtab, int width, int height)
 {
     World         = WorldCam;
     this.focus    = focus;
     mash          = mashtab;
     this.height   = height;
     this.width    = width;
     this.Sun      = Sun;
     this.ColorSun = ColorSun;
     ImageB        = new byte[3, height, width];
 }
Ejemplo n.º 10
0
 public Point3DF PointFound(Point3DF point)
 {
     for (int i = 0; i < Points.Count; i++)
     {
         if (true == Point3DF.EgualPoint(point, Points[i]))
         {
             return(Points[i]);
         }
     }
     return(null);
 }
Ejemplo n.º 11
0
        public void ObjSet()
        {
            Point3DF p1 = new Point3DF(0, 0, 10);
            Point3DF p2 = new Point3DF(0, 50, 10);
            Point3DF p3 = new Point3DF(50, 50, 10);
            Point3DF p4 = new Point3DF(50, 0, 10);

            Point3DF p5 = new Point3DF(60, 0 - 20, 30);
            Point3DF p6 = new Point3DF(60, 50 - 20, 30);
            Point3DF p7 = new Point3DF(110, 50 - 20, 30);
            Point3DF p8 = new Point3DF(110, 0 - 20, 30);
            double   P1 = 40;
            double   P2 = 45;
            double   P3 = 0;

            p1 = new Point3DF(0 + P1, 0 + P2, 10 + P3);
            p2 = new Point3DF(0 + P1, 50 + P2, 10 + P3);
            p3 = new Point3DF(50 + P1, 50 + P2, 10 + P3);
            p4 = new Point3DF(50 + P1, 0 + P2, 10 + P3);

            p5  = new Point3DF(60 + P1, 0 - 20 + P2, 30 + P3);
            p6  = new Point3DF(60 + P1, 50 - 20 + P2, 30 + P3);
            p7  = new Point3DF(110 + P1, 50 - 20 + P2, 30 + P3);
            p8  = new Point3DF(110 + P1, 0 - 20 + P2, 30 + P3);
            Pol = new Object();
            //Pol.Poligons.OnAdd += new EventHandler(Object);
            Pol.PloskAdd(p1, p2, p3, p4, Color.Gray, 0, 1);
            Pol.PloskAdd(p5, p6, p7, p8, Color.Gray, 0, 1);

            Pol.PloskAdd(p2, p3, p7, p6, Color.Gray, 0, 1);
            Pol.PloskAdd(p3, p4, p8, p7, Color.Gray, 0, 1);
            Pol.PloskAdd(p4, p1, p5, p8, Color.Gray, 0, 1);
            Pol.PloskAdd(p1, p2, p6, p5, Color.Gray, 0, 1);

            OsCoord = new Object();
            OsCoord.Lines.Add(new Line(new Point3DF(0, 0, 0), new Point3DF(100, 0, 0), Color.Red));
            OsCoord.Lines.Add(new Line(new Point3DF(0, 0, 0), new Point3DF(0, 100, 0), Color.Green));
            OsCoord.Lines.Add(new Line(new Point3DF(0, 0, 0), new Point3DF(0, 0, 100), Color.Blue));
            OsCoord.PloskAdd(new Point3DF(0, 0, 0),
                             new Point3DF(200, 0, 0),
                             new Point3DF(200, 200, 0),
                             new Point3DF(0, 200, 0), Color.Red, 0, 1);
            OsCoord.PloskAdd(new Point3DF(0, 0, 0),
                             new Point3DF(200, 0, 0),
                             new Point3DF(200, 0, 200),
                             new Point3DF(0, 0, 200), Color.Green, 0, 1);
            OsCoord.PloskAdd(new Point3DF(0, 0, 0),
                             new Point3DF(0, 200, 0),
                             new Point3DF(0, 200, 200),
                             new Point3DF(0, 0, 200), Color.Blue, 0, 1);
            World.Add(OsCoord);
            World.Add(Pol);
            //World.Add(Pol2);
        }
Ejemplo n.º 12
0
        static public double AngleFound(Line line1, Line line2)
        {
            Point3DF vect1 = Line.Vector(line1);
            Point3DF vect2 = Line.Vector(line2);

            double acosVal = (vect1.X * vect2.X + vect1.Y * vect2.Y + vect1.Z * vect2.Z)
                             / Math.Sqrt((Math.Pow(vect1.X, 2) + Math.Pow(vect1.Y, 2) + Math.Pow(vect1.Z, 2)) *
                                         (Math.Pow(vect2.X, 2) + Math.Pow(vect2.Y, 2) + Math.Pow(vect2.Z, 2)));
            double angle = Math.Acos(acosVal);

            return(angle);
        }
Ejemplo n.º 13
0
        public Poligon(Point3DF P1, Point3DF P2, Point3DF P3, bool B1, bool B2, bool B3, Color colorPoligon, double Rozseiv, double ForseOtbit)
        {
            this.P1 = P1;
            Points.Add(P1);
            this.P2 = P2;
            Points.Add(P2);
            this.P3 = P3;
            Points.Add(P3);

            this.B1         = B1;
            this.B2         = B2;
            this.B3         = B3;
            ColorPoligon    = colorPoligon;
            this.Rozseiv    = Rozseiv;
            this.ForseOtbit = ForseOtbit;
        }
Ejemplo n.º 14
0
        public static Point3DF VectorPerpend2Vector(Point3DF A, Point3DF B, bool Right)
        {
            Point3DF rez = new Point3DF(0, 0, 0);

            rez.X = A.Y * B.Z - A.Z * B.Y;
            rez.Y = A.Z * B.X - A.X * B.Z;
            rez.Z = A.X * B.Y - A.Y * B.X;
            if (!Right)
            {
                rez    = rez * (-1);
                rez.X *= -1;
                rez.Y *= -1;
                rez.Z *= -1;
            }
            return(rez);
        }
Ejemplo n.º 15
0
        static public Object ConvertWorldtoCam(Point3DF VectorVzgl, Point3DF Location, Object obj)
        {
            Object ConvertedObj = new Object();

            double[] Mas = new double[3] {
                Location.X, Location.Y, Location.Z
            };
            double AngleRotateZ = Line.AngleFound(new Line(new Point3DF(0, 0, 0), new Point3DF(10, 0, 0), false),
                                                  new Line(new Point3DF(0, 0, 0), new Point3DF(VectorVzgl.X, VectorVzgl.Y, 0), false));

            if (VectorVzgl.Y > 0)
            {
                AngleRotateZ *= -1;
            }
            double AngleRotateY = Line.AngleFound(
                new Line(new Point3DF(0, 0, 0), new Point3DF(VectorVzgl.X, VectorVzgl.Y, VectorVzgl.Z), false),
                new Line(new Point3DF(0, 0, 0), new Point3DF(VectorVzgl.X, VectorVzgl.Y, 0), false));

            if (VectorVzgl.Z > 0)
            {
                AngleRotateY *= -1;
            }
            double[,] InversY = new double[3, 3]
            {
                { 1, 0, 0 },
                { 0, -1, 0 },
                { 0, 0, 1 }
            };
            double[,] RotateZ = new double[3, 3]
            {
                { Math.Cos(AngleRotateZ), Math.Sin(-AngleRotateZ), 0 },
                { Math.Sin(AngleRotateZ), Math.Cos(AngleRotateZ), 0 },
                { 0, 0, 1 }
            };
            double[,] RotateY = new double[3, 3]
            {
                { Math.Cos(AngleRotateY), 0, Math.Sin(-AngleRotateY) },
                { 0, 1, 0 },
                { Math.Sin(AngleRotateY), 0, Math.Cos(AngleRotateY) }
            };
            ConvertedObj = obj - Mas;
            ConvertedObj = RotateZ * ConvertedObj;
            ConvertedObj = InversY * ConvertedObj;
            ConvertedObj = RotateY * ConvertedObj;
            return(ConvertedObj);
        }
Ejemplo n.º 16
0
        public static bool InArea(Poligon pol, Point3DF point)
        {
            bool rez = true;

            Line[]   Perpend = new Line[pol.Lines.Count];
            double[] D       = new double[pol.Lines.Count];
            for (int i = 0; i < pol.Lines.Count; i++)
            {
                Perpend[i] = (PerpendicFound(pol.Lines[i], pol.Points[i]));
                Point3DF vector = Line.Vector(Perpend[i]);
                D[i] = -(vector.X * Perpend[i].StartLine.X +
                         vector.Y * Perpend[i].StartLine.Y +
                         vector.Z * Perpend[i].StartLine.Z);
                rez = rez && (vector.X * point.X + vector.Y * point.Y + vector.Z * point.Z + D[i] >= 0);
            }

            return(rez);
        }
Ejemplo n.º 17
0
        public static Line LinePeresechPlosk(double[] ABCD1, double[] ABCD2)
        {
            Point3DF A         = new Point3DF(ABCD1[0], ABCD1[1], ABCD1[2]);
            Point3DF B         = new Point3DF(ABCD2[0], ABCD2[1], ABCD2[2]);
            double   j         = A.X * B.X + A.Y * B.Y + A.Z * B.Z;
            Point3DF C         = VectorPerpend2Vector(A, B, true);
            Point3DF startline = new Point3DF(0, 0, 0);

            startline.Z = 0;
            if (0 == ABCD1[0])
            {
                startline.Y = -(ABCD1[3] / ABCD1[1]);
                if (0 == ABCD1[0] && 0 == ABCD2[0])
                {
                    startline.X = 0;
                }
                else
                {
                    startline.X = -(ABCD2[1] / ABCD2[0]) * startline.Y - (ABCD2[3] / ABCD2[0]);
                }
            }
            else if (0 == ABCD2[0])
            {
                startline.Y = -(ABCD2[3] / ABCD2[1]);
                if (0 == ABCD1[0] && 0 == ABCD2[0])
                {
                    startline.X = 0;
                }
                else
                {
                    startline.X = -(ABCD1[1] / ABCD1[0]) * startline.Y - (ABCD1[3] / ABCD1[0]);
                }
            }
            else
            {
                startline.Y = ((ABCD2[3] * ABCD1[0]) - (ABCD1[3] * ABCD2[0]))
                              / ((ABCD1[1] * ABCD2[0]) - (ABCD2[1] * ABCD1[0]));
                startline.X = -(ABCD1[1] / ABCD1[0]) * startline.Y - (ABCD1[3] / ABCD1[0]);
            }
            Line line = new Line(startline, startline + C, true);

            return(line);
        }
Ejemplo n.º 18
0
        public static double[] ABCDFound(Poligon pol, bool Right)
        {
            double[] ABCD = new double[4];
            Point3DF A    = Line.Vector(new Line(pol.P1, pol.P2, true));
            Point3DF B    = Line.Vector(new Line(pol.P2, pol.P3, true));
            //Point3DF L3 = Line.Vector(new Line(pol.P1, pol.P3, true));
            Point3DF vectPer = Line.VectorPerpend2Vector(A, B, Right);

            ABCD[0] = vectPer.X;
            ABCD[1] = vectPer.Y;
            ABCD[2] = vectPer.Z;
            if (!Right)
            {
                ABCD[0] *= -1;
                ABCD[1] *= -1;
                ABCD[2] *= -1;
            }
            ABCD[3] = -(ABCD[0] * pol.P1.X + ABCD[1] * pol.P1.Y + ABCD[2] * pol.P1.Z);
            return(ABCD);
        }
Ejemplo n.º 19
0
        static public bool LineHide(Line line, List <Object> World)
        {
            Point3DF p1 = Line.PointF(line, 0.02);
            Point3DF p2 = Line.PointF(line, 0.98);
            bool     b1 = PointHide(p1, World);
            bool     b2 = PointHide(p2, World);

            if (!b1 && !b2)
            {
                return(false);
            }
            if (b1 && b2)
            {
                return(true);
            }
            else
            {
                return(true);
            }
        }
Ejemplo n.º 20
0
        public static double PeresechPoint(double[] ABCD, Line line)
        {
            Point3DF Vector = Line.Vector(line);
            double   Znam   = (ABCD[0] * Vector.X
                               + ABCD[1] * Vector.Y
                               + ABCD[2] * Vector.Z);
            double Lambda;

            if (Znam != 0)
            {
                Lambda = -(ABCD[0] * line.StartLine.X
                           + ABCD[1] * line.StartLine.Y
                           + ABCD[2] * line.StartLine.Z + ABCD[3])
                         / Znam;
            }
            else
            {
                Lambda = double.NaN;
            }
            return(Lambda);
        }
Ejemplo n.º 21
0
 private void pictureBox1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
 {
     if (Keys.W == e.KeyData)
     {
         LocationCam += VzgladCam * Step;
         VzgladCam    = Point3DF.NormirVector(new Point3DF(-LocationCam.X, -LocationCam.Y, -LocationCam.Z));
         RefreshPictureBox(LocationCam, VzgladCam, World);
     }
     else if (Keys.S == e.KeyData)
     {
         LocationCam += VzgladCam * (-Step);
         VzgladCam    = Point3DF.NormirVector(new Point3DF(-LocationCam.X, -LocationCam.Y, -LocationCam.Z));
         RefreshPictureBox(LocationCam, VzgladCam, World);
     }
     else if (Keys.A == e.KeyData)
     {
         LocationCam += new Point3DF(-VzgladCam.Y, VzgladCam.X, 0, true) * (Step);
         VzgladCam    = Point3DF.NormirVector(new Point3DF(-LocationCam.X, -LocationCam.Y, -LocationCam.Z));
         RefreshPictureBox(LocationCam, VzgladCam, World);
     }
     else if (Keys.D == e.KeyData)
     {
         LocationCam += new Point3DF(VzgladCam.Y, -VzgladCam.X, 0, true) * (Step);
         VzgladCam    = Point3DF.NormirVector(new Point3DF(-LocationCam.X, -LocationCam.Y, -LocationCam.Z));
         RefreshPictureBox(LocationCam, VzgladCam, World);
     }
     else if ((Keys.ShiftKey | Keys.Shift) == e.KeyData)
     {
         LocationCam += new Point3DF(0, 0, Step);
         VzgladCam    = Point3DF.NormirVector(new Point3DF(-LocationCam.X, -LocationCam.Y, -LocationCam.Z));
         RefreshPictureBox(LocationCam, VzgladCam, World);
     }
     else if ((Keys.ControlKey | Keys.Control) == e.KeyData)
     {
         LocationCam += new Point3DF(0, 0, -Step);
         VzgladCam    = Point3DF.NormirVector(new Point3DF(-LocationCam.X, -LocationCam.Y, -LocationCam.Z));
         RefreshPictureBox(LocationCam, VzgladCam, World);
     }
 }
Ejemplo n.º 22
0
        public static Line PerpendicFound(Line line, Point3DF C)
        {
            Point3DF a = Line.Vector(line);
            Point3DF A = line.StartLine;
            Line     CD = new Line(new Point3DF(0, 0, 0), C, true);
            double   D1, D2;

            if (a.X != 0)
            {
                D1 = a.X * C.X + a.Y * C.Y + a.Z * C.Z +
                     ((Math.Pow(a.Y, 2) / a.X) + (Math.Pow(a.Z, 2) / a.X)) * A.X
                     - a.Y * A.Y - a.Z * A.Z;
                D2             = a.X + (Math.Pow(a.Y, 2) / a.X) + (Math.Pow(a.Z, 2) / a.X);
                CD.StartLine.X = (float)(D1 / D2);
                CD.StartLine.Y = (a.Y * (CD.StartLine.X - A.X) / a.X) + A.Y;
                CD.StartLine.Z = (a.Z * (CD.StartLine.X - A.X) / a.X) + A.Z;
            }
            else if (a.Y != 0)
            {
                D1 = a.X * C.X + a.Y * C.Y + a.Z * C.Z +
                     ((Math.Pow(a.X, 2) / a.Y) + (Math.Pow(a.Z, 2) / a.Y)) * A.Y
                     - a.X * A.X - a.Z * A.Z;
                D2             = a.Y + (Math.Pow(a.X, 2) / a.Y) + (Math.Pow(a.Z, 2) / a.Y);
                CD.StartLine.Y = (float)(D1 / D2);
                CD.StartLine.Z = (a.Z * (CD.StartLine.Y - A.Y) / a.Y) + A.Z;
                CD.StartLine.X = (a.X * (CD.StartLine.Y - A.Y) / a.Y) + A.X;
            }
            else if (a.Z != 0)
            {
                D1 = a.X * C.X + a.Y * C.Y + a.Z * C.Z +
                     ((Math.Pow(a.X, 2) / a.Z) + (Math.Pow(a.Y, 2) / a.Z)) * A.Z
                     - a.X * A.X - a.Y * A.Y;
                D2             = a.Z + (Math.Pow(a.X, 2) / a.Z) + (Math.Pow(a.Y, 2) / a.Z);
                CD.StartLine.Z = (float)(D1 / D2);
                CD.StartLine.Y = (a.Y * (CD.StartLine.Z - A.Z) / a.Z) + A.Y;
                CD.StartLine.X = (a.X * (CD.StartLine.Z - A.Z) / a.Z) + A.X;
            }
            return(CD);
        }
Ejemplo n.º 23
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            double Z = 100;

            /*if (Angle > 4 * Math.PI)
             * {
             *  Angle = 0;
             *  timer1.Stop();
             * }
             * else*/
            {
                Angle += Math.PI / 500;
                Point3DF vectVision   = new Point3DF(-Z * Math.Cos(Angle), -Z * Math.Sin(Angle), 30);
                Point3DF vectLocation = new Point3DF(50 + Z * Math.Cos(Angle), 25 + Z * Math.Sin(Angle), -30);

                RefreshPictureBox(vectLocation, vectVision, World);/*
                                                                    * Object obj = ConvertCoordinate.ConvertWorldtoCam(vectVision, vectLocation, Pol);
                                                                    * Object objOs = ConvertCoordinate.ConvertWorldtoCam(vectVision, vectLocation, OsCoord);
                                                                    * g.Clear(Color.White);
                                                                    * drawing(ConvertCoordinate.Camto2D(obj,5), mash);
                                                                    * drawing(ConvertCoordinate.Camto2D(objOs,5), mash);
                                                                    * pictureBox1.Image = DrawArea;*/
            }
        }
Ejemplo n.º 24
0
 public static double LenVecor(Point3DF vector)
 {
     return(Math.Sqrt(Math.Pow(vector.X, 2) + Math.Pow(vector.Y, 2) + Math.Pow(vector.Z, 2)));
 }
Ejemplo n.º 25
0
        public static Point3DF NormirVector(Point3DF vector)
        {
            double Len = Point3DF.LenVecor(vector);

            return(vector / Len);
        }
Ejemplo n.º 26
0
 public void PloskAdd(Point3DF P1, Point3DF P2, Point3DF P3, Point3DF P4, Color ColorPoligon, double Rozseiv, double ForseOtbit)
 {
     Poligons.Add(new Poligon(P1, P2, P3, true, true, false, ColorPoligon, Rozseiv, ForseOtbit));
     Poligons.Add(new Poligon(P3, P1, P4, false, true, true, ColorPoligon, Rozseiv, ForseOtbit));
 }
Ejemplo n.º 27
0
 public Line(Point3DF StartLine, Point3DF EndLine, Color ColLine)
 {
     this.StartLine = StartLine;
     this.EndLine   = EndLine;
     this.ColLine   = ColLine;
 }
Ejemplo n.º 28
0
 public Poligon(Point3DF P1, Point3DF P2, Point3DF P3)
 {
     this.P1 = P1;
     this.P2 = P2;
     this.P3 = P3;
 }
Ejemplo n.º 29
0
        public Color Luch(int wid, int heig)
        {
            Color  rez   = new Color();
            double wid1  = (wid - width / 2) / mash;
            double heig1 = -(heig - height / 2) / mash;
            Line   luch  = new Line(new Point3DF(0, 0, 0), new Point3DF(focus, wid1, heig1), true);

            object[] re     = LuchPointF(luch, World);
            double   Lambda = (double)re[0];
            int      numobj = (int)re[1];
            int      numpol = (int)re[2];

            if (Lambda < 0)
            {
                return(Color.White);
            }
            else
            {
                Line luch2 = new Line(Line.PointF(luch, Lambda - 0.01), Sun, true);
                luch = new Line(new Point3DF(0, 0, 0), Line.PointF(luch, Lambda), true);
                if (!((double)LuchPointF(luch2, World)[0] < 0))
                {
                    return(Color.Black);
                }
                else
                {
                    double  len2    = Line.Len(luch2);
                    double  len     = Line.Len(luch);
                    Color   colsunr = RozseivSrast(ColorSun, len);
                    Poligon pol     = World[numobj].Poligons[numpol];


                    double[] ABCD   = Poligon.ABCDFound(pol, true);
                    Point3DF Normal = Point3DF.NormirVector(new Point3DF(ABCD[0], ABCD[1], ABCD[2]));
                    Point3DF InSun  = Point3DF.NormirVector(Line.Vector(luch2));
                    if (InSun.X * Normal.X + InSun.Y * Normal.Y + InSun.Z * Normal.Z < 0)
                    {
                        Normal = new Point3DF(-Normal.X, -Normal.Y, -Normal.Z);
                    }
                    Point3DF InCam = Point3DF.NormirVector(Line.Vector(Line.LineObr(luch)));

                    Point3DF Perpend = Line.VectorPerpend2Vector(InSun, Normal, true);
                    Point3DF p1      = new Point3DF(Perpend.X, Perpend.Y, 0);
                    if (!(p1.X == 0 && p1.Y == 0))
                    {
                        double AngleZ = Line.AngleFound(
                            new Line(new Point3DF(0, 0, 0), new Point3DF(1, 0, 0), true),
                            new Line(new Point3DF(0, 0, 0), p1, true));

                        double[,] RotateZ = new double[3, 3]
                        {
                            { Math.Cos(AngleZ), Math.Sin(-AngleZ), 0 },
                            { Math.Sin(AngleZ), Math.Cos(AngleZ), 0 },
                            { 0, 0, 1 }
                        };
                        Point3DF test = RotateZ * p1;
                        if (!(Math.Round(test.Y, 5) == 0 && test.X > 0))
                        {
                            AngleZ *= -1;
                        }
                        RotateZ = new double[3, 3]
                        {
                            { Math.Cos(AngleZ), Math.Sin(-AngleZ), 0 },
                            { Math.Sin(AngleZ), Math.Cos(AngleZ), 0 },
                            { 0, 0, 1 }
                        };
                        test    = RotateZ * p1;
                        Normal  = RotateZ * Normal;
                        InSun   = RotateZ * InSun;
                        InCam   = RotateZ * InCam;
                        Perpend = RotateZ * Perpend;
                    }
                    double AngleY = Line.AngleFound(
                        new Line(new Point3DF(0, 0, 0), new Point3DF(10, 0, 0), true),
                        new Line(new Point3DF(0, 0, 0), Perpend, true));
                    double[,] RotateY = new double[3, 3]
                    {
                        { Math.Cos(AngleY), 0, Math.Sin(-AngleY) },
                        { 0, 1, 0 },
                        { Math.Sin(AngleY), 0, Math.Cos(AngleY) }
                    };
                    Point3DF p = RotateY * Perpend;
                    if (!(Math.Round(p.Z, 4) == 0 && p.X > 0))
                    {
                        AngleY *= -1;
                    }
                    RotateY = new double[3, 3]
                    {
                        { Math.Cos(AngleY), 0, Math.Sin(-AngleY) },
                        { 0, 1, 0 },
                        { Math.Sin(AngleY), 0, Math.Cos(AngleY) }
                    };
                    p = RotateY * Perpend;

                    Normal  = RotateY * Normal;
                    InSun   = RotateY * InSun;
                    InCam   = RotateY * InCam;
                    Perpend = RotateY * Perpend;

                    double AngleNS = -(InSun.X * Normal.X + InSun.Y * Normal.Y + InSun.Z * Normal.Z);
                    double[,] RotateX = new double[3, 3]
                    {
                        { 1, 0, 0 },
                        { 0, AngleNS, -Math.Sqrt(1 - Math.Pow(AngleNS, 2)) },
                        { 0, Math.Sqrt(1 - Math.Pow(AngleNS, 2)), AngleNS }
                    };
                    Point3DF OtragL      = RotateX * Normal;//new Point3DF(InSun.X, InSun.Y, InSun.Z);
                    double   CosAngleNS2 = InSun.X * OtragL.X + InSun.Y * OtragL.Y + InSun.Z * OtragL.Z;
                    if (Math.Abs(Math.Round(CosAngleNS2, 4)) == 1)
                    {
                        RotateX = new double[3, 3]
                        {
                            { 1, 0, 0 },
                            { 0, AngleNS, Math.Sqrt(1 - Math.Pow(AngleNS, 2)) },
                            { 0, -Math.Sqrt(1 - Math.Pow(AngleNS, 2)), AngleNS }
                        };
                        OtragL = RotateX * Normal;
                    }
                    double CosAngleNS = Math.Abs(InSun.X * Normal.X + InSun.Y * Normal.Y + InSun.Z * Normal.Z);
                    CosAngleNS2 = InSun.X * OtragL.X + InSun.Y * OtragL.Y + InSun.Z * OtragL.Z;
                    double CosAngleOC = Math.Max(0, -InCam.X * OtragL.X - InCam.Y * OtragL.Y - InCam.Z * OtragL.Z);

                    /*if (AngleOC < 0)
                     *  return Color.Black;*/
                    double[] K = new double[3] {
                        (double)pol.ColorPoligon.R / 255, (double)pol.ColorPoligon.G / 255, (double)pol.ColorPoligon.B / 255
                    };

                    double[] Ks = new double[3] {
                        (double)((255 - pol.ColorPoligon.R) * 1 + pol.ColorPoligon.R) / 255,
                        (double)((255 - pol.ColorPoligon.G) * 1 + pol.ColorPoligon.G) / 255,
                        (double)((255 - pol.ColorPoligon.B) * 1 + pol.ColorPoligon.B) / 255
                    };

                    double[] Ia = new double[3] {
                        K[0] * colsunr.R, K[1] * colsunr.G, K[2] * colsunr.B
                    };
                    double[] Id = new double[3] {
                        K[0] * CosAngleNS * colsunr.R, K[1] * CosAngleNS * colsunr.G, K[2] * CosAngleNS * colsunr.B
                    };
                    double[] Is = new double[3] {
                        Ks[0] * Math.Pow(CosAngleOC, 5) * colsunr.R,
                        Ks[1] * Math.Pow(CosAngleOC, 5) * colsunr.G,
                        Ks[2] * Math.Pow(CosAngleOC, 5) * colsunr.B
                    };
                    return(RozseivSrast(Color.FromArgb(
                                            (int)((Ia[0] + Id[0] + Is[0])) / (3),
                                            (int)((Ia[1] + Id[1] + Is[1])) / (3),
                                            (int)((Ia[2] + Id[2] + Is[2])) / (3))
                                        , len2));
                }
            }
            return(rez);
        }
Ejemplo n.º 30
0
 static public double PointCheck(double[] ABCD, Point3DF point)
 {
     return(ABCD[0] * point.X + ABCD[1] * point.Y + ABCD[2] * point.Z + ABCD[3]);
 }