Beispiel #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Polygon pol = new Polygon(points);
            //drawPolygon(pol, Color.Black);
            double phi_a  = double.Parse(textBoxPhi.Text);
            double psi_a  = double.Parse(textBoxPsi.Text);
            double view_x = double.Parse(textBoxViewVectorX.Text);
            double view_y = double.Parse(textBoxViewVectorY.Text);
            double view_z = double.Parse(textBoxViewVectorZ.Text);

            ClearPic1();
            ClearPic3(phi_a, psi_a);

            string ax  = comboBoxBuildAxis.SelectedItem.ToString();
            int    cnt = Int32.Parse(textBoxBuildCount.Text);


            PointPol rotate_around = new PointPol(0, 0, 0);

            buildPolsRotate(ax, cnt, ref rotate_around);
            drawPols(pols_rotate, phi_a, psi_a, new PointPol(view_x, view_y, view_z));

            buildFig(rotate_around);
            buildFig(rotate_around);
            //drawPols(fig);
            fig_drawed = false;
        }
Beispiel #2
0
        private void drawPolygon(Polygon pol, Color c,
                                 double phi_a, double psi_a, PointPol view_vector)
        {
            List <Tuple <Point, Point> > l = pol.to2d();

            foreach (var p in l)
            {
                //g.DrawLine(new Pen(c), p.Item1, p.Item2);
            }
            Point[] ps = new Point[pol.points.Count()];
            int     i  = 0;

            foreach (var item in pol.points)
            {
                ps[i] = item.To2D(phi_a, psi_a);
                ++i;
            }
            g.DrawPolygon(new Pen(c), ps);

            if (pol.points.Count() > 2)
            {
                if (isVisible(pol, view_vector))
                {
                    List <Tuple <Point, Point> > l2 = pol.to2d(phi_a, psi_a);
                    foreach (var p in l2)
                    {
                        //g3.DrawLine(new Pen(c), p.Item1, p.Item2);
                    }
                    g3.FillPolygon(new SolidBrush(c), ps);
                }
            }
        }
Beispiel #3
0
        public double pitch, yaw, roll; //Тангаж, рысканье и крен
        //public PointPol view;

        public Camera(double x, double y, double z, double p, double ya, double r)
        {
            position = new PointPol(x, y, z);
            pitch    = p * Math.PI / 180;
            yaw      = ya * Math.PI / 180;
            roll     = r * Math.PI / 180;
        }
Beispiel #4
0
        public void write_axes1()
        {
            PointPol p0 = new PointPol(0, 0, 0);
            PointPol p1 = new PointPol(pictureBox1.Width / 2, 0, 0);
            PointPol p2 = new PointPol(0, pictureBox1.Width / 2, 0);
            PointPol p3 = new PointPol(0, 0, pictureBox1.Width / 2);

            Point o = p0.To2D();
            Point x = p1.To2D();
            Point y = p2.To2D();
            Point z = p3.To2D();

            Font       font  = new Font("Arial", 8);
            SolidBrush brush = new SolidBrush(Color.Black);

            g.DrawString("X", font, brush, x);
            g.DrawString("Y", font, brush, y);
            g.DrawString("Z", font, brush, z);

            Pen my_pen = new Pen(Color.Blue);

            g.DrawLine(my_pen, o, x);
            my_pen.Color = Color.Red;
            g.DrawLine(my_pen, o, y);
            my_pen.Color = Color.Green;
            g.DrawLine(my_pen, o, z);

            pictureBox1.Image = pictureBox1.Image;
        }
Beispiel #5
0
 private void make_curve(ref List <PointPol> l, double x, double y0, double y1, double step)
 {
     for (double y = y0; y <= y1; y += step)
     {
         PointPol p = new PointPol(x, y, f(x, y));
         l.Add(p);
     }
 }
Beispiel #6
0
        private void buildPolsRotate(string axis, int cnt, ref PointPol rotate_around)
        {
            pols_rotate.Clear();
            List <PointPol> l1 = new List <PointPol>(points);
            double          a = 0, b = 0, c = 0;

            Polygon pol = new Polygon(l1);

            //pol.find_center(ref a, ref b, ref c);
            pol.closest_to_zero(axis, ref a, ref b, ref c);

            Vector dir = new Vector(new PointPol(0, 0, 0), new PointPol(1, 0, 0));

            if (axis == "X")
            {
                dir = new Vector(new PointPol(0, 0, 0), new PointPol(1, 0, 0));
                for (int i = 0; i < l1.Count(); ++i)
                {
                    l1[i] = l1[i].shift(0, -b, 0);
                }
                rotate_around.X = a; rotate_around.Y = 0; rotate_around.Z = c;
            }
            if (axis == "Y")
            {
                dir = new Vector(new PointPol(0, 0, 0), new PointPol(0, 1, 0));
                for (int i = 0; i < l1.Count(); ++i)
                {
                    l1[i] = l1[i].shift(-a, 0, 0);
                }
                rotate_around.X = 0; rotate_around.Y = b; rotate_around.Z = c;
            }
            if (axis == "Z")
            {
                dir = new Vector(new PointPol(0, 0, 0), new PointPol(0, 0, 1));
                for (int i = 0; i < l1.Count(); ++i)
                {
                    l1[i] = l1[i].shift(0, -b, 0);
                }
                rotate_around.X = a; rotate_around.Y = 0; rotate_around.Z = c;
            }

            double angle = 360.0 / cnt;

            for (int i = 0; i < cnt; ++i)
            {
                List <PointPol> l2 = new List <PointPol>(l1);

                for (int j = 0; j < l2.Count(); ++j)
                {
                    l2[j] = l2[j].rotate(dir, angle, 0, 0, 0);
                }

                pols_rotate.Add(new Polygon(l1));

                l1 = l2;
            }
        }
Beispiel #7
0
        public point3 ViewPortTranform(PointPol p)
        {
            int h = pictureBox2.Image.Height;
            int w = pictureBox2.Image.Width;

            return(new point3((int)((1 + p.X) * w / 2),
                              (int)((1 + p.Y) * h / 2),
                              (int)(p.Z * 100000000), p));
        }
Beispiel #8
0
        private bool isVisible(Polygon pol, PointPol view_vector)
        {
            PointPol vecNorm = normVecOfPlane(pol.points[0], pol.points[1], pol.points[2]);

            if (comboBoxBuildAxis.SelectedItem.ToString() == "X")
            {
                return(scalarProduct(vecNorm, view_vector) < 0);
            }
            return(scalarProduct(vecNorm, view_vector) > 0);
        }
Beispiel #9
0
 private void buildFig(PointPol rotate_around)
 {
     fig.Clear();
     if (pols_rotate.Count() > 1)
     {
         for (int i = 1; i < pols_rotate.Count(); ++i)
         {
             buildPartOfFig(pols_rotate[i - 1], pols_rotate[i]);
         }
         buildPartOfFig(pols_rotate.Last(), pols_rotate.First());
     }
 }
Beispiel #10
0
        private void drawPols(List <Polygon> pols, double phi_a, double psi_a, PointPol view_vector)
        {
            int    i = 1;
            Random r = new Random();

            foreach (var item in pols)
            {
                drawPolygon(item, item.color, phi_a, psi_a, view_vector);
                i += 10;
            }
            pictureBox1.Image = pictureBox1.Image;
            pictureBox3.Image = pictureBox3.Image;
        }
Beispiel #11
0
 private void addPoints(ref List <int> points, ref int cnt, PointPol p)
 {
     if (d.ContainsKey(p))
     {
         points.Add(d[p]);
     }
     else
     {
         d.Add(p, cnt);
         points.Add(cnt);
         cnt++;
     }
 }
Beispiel #12
0
        /*private void buttonPlus_Click(object sender, EventArgs e)
         * {
         * double curr_ind = 1.2;
         * ind *= curr_ind;
         * double phi_a = hScrollBar1.Value;
         * double psi_a = hScrollBar2.Value;
         * double view_x = double.Parse(textBoxViewVectorX.Text);
         * double view_y = double.Parse(textBoxViewVectorY.Text);
         * double view_z = double.Parse(textBoxViewVectorZ.Text);
         *
         * scalePols(pols_rotate, curr_ind);
         * scalePols(fig, curr_ind);
         *
         * reDrawPols(phi_a, psi_a, new PointPol(view_x, view_y, view_z));
         * }
         *
         * private void buttonMinus_Click(object sender, EventArgs e)
         * {
         * double curr_ind = 0.83333;
         * ind *= curr_ind;
         * double phi_a = hScrollBar1.Value;
         * double psi_a = hScrollBar2.Value;
         * double view_x = double.Parse(textBoxViewVectorX.Text);
         * double view_y = double.Parse(textBoxViewVectorY.Text);
         * double view_z = double.Parse(textBoxViewVectorZ.Text);
         *
         * scalePols(pols_rotate, curr_ind);
         * scalePols(fig, curr_ind);
         *
         * reDrawPols(phi_a, psi_a, new PointPol(view_x, view_y, view_z));
         * }*/

        private PointPol normVecOfPlane(PointPol p1, PointPol p2, PointPol p3)
        {
            double kx, ky, kz, d;
            double xa = p1.X, ya = p1.Y, za = p1.Z;
            double a21 = p2.X - xa, a22 = p2.Y - ya, a23 = p2.Z - za;
            double a31 = p3.X - xa, a32 = p3.Y - ya, a33 = p3.Z - za;

            kx = a22 * a33 - a23 * a32;
            ky = -(a21 * a33 - a23 * a31);
            kz = a21 * a32 - a22 * a31;
            d  = (kx * -xa) + (ky * -ya) + (kz * -za);

            return(new PointPol(kx, ky, kz));
        }
Beispiel #13
0
 private void reDrawPols(double phi_a, double psi_a, PointPol view_vector)
 {
     if (fig_drawed)
     {
         ClearPic1();
         ClearPic3(phi_a, psi_a);
         drawPols(fig, phi_a, psi_a, view_vector);
     }
     else
     {
         ClearPic1();
         ClearPic3(phi_a, psi_a);
         drawPols(pols_rotate, phi_a, psi_a, view_vector);
     }
 }
Beispiel #14
0
        private void rotatePols(List <Polygon> pols, int x1, int y1, int z1,
                                int x2, int y2, int z2, double angle)
        {
            PointPol p1 = new PointPol(x1, y1, z1);
            PointPol p2 = new PointPol(x2, y2, z2);
            Vector   ed = new Vector(p1, p2);

            double a = 0, b = 0, c = 0;

            find_center(pols, ref a, ref b, ref c);
            foreach (var item in pols)
            {
                item.rotate(ed, angle, a, b, c);
            }
        }
Beispiel #15
0
        public void AddPolygon(string line)
        {
            var        prs     = line.Split(' ').Select(x => x.Split(';').Select(z => Convert.ToDouble(z)).ToArray());
            List <int> numbers = new List <int>();

            foreach (var y in prs)
            {
                PointPol t = new PointPol(y[0], y[1], y[2]);
                if (!vertices.Values.Any(f => f.X == y[0] && f.Y == y[1] && f.Z == y[2]))
                {
                    vertices.Add(vertices.Count, t);
                }
                numbers.Add(find_index(t));
            }
            polygons.Add(new Polygon(numbers));
        }
Beispiel #16
0
        private void buttonBuild2_Click(object sender, EventArgs e)
        {
            ClearPic1();

            string ax  = comboBoxBuildAxis.SelectedItem.ToString();
            int    cnt = Int32.Parse(textBoxBuildCount.Text);

            PointPol rotate_around = new PointPol(0, 0, 0);

            buildPolsRotate(ax, cnt, ref rotate_around);
            //drawPols(pols_rotate);

            buildFig(rotate_around);
            buildFig(rotate_around);
            drawPols(fig);
            fig_drawed = true;
        }
Beispiel #17
0
        private void button6_Click(object sender, EventArgs e)
        {
            ClearWithout();
            write_axes();

            double x1 = Double.Parse(textBoxX1.Text.ToString());
            double y1 = Double.Parse(textBoxY1.Text.ToString());
            double z1 = Double.Parse(textBoxZ1.Text.ToString());
            double x2 = Double.Parse(textBoxX2.Text.ToString());
            double y2 = Double.Parse(textBoxY2.Text.ToString());
            double z2 = Double.Parse(textBoxZ2.Text.ToString());

            double angle = Double.Parse(textBoxAngle.Text.ToString());

            PointPol p1 = new PointPol(x1, y1, z1);
            PointPol p2 = new PointPol(x2, y2, z2);

            figure.rotate(Tuple.Create(p1, p2), angle);
            print_figure();
        }
Beispiel #18
0
        /*public Polygon(List<Edge> edg)
         * {
         *  foreach (var el in edg)
         *  {
         *      edges.Add(el);
         *      //points.Add(el.P1);
         *      //points.Add(el.P2);
         *  }
         * }*/
        //грани
        public Polygon(List <PointPol> ps)
        {
            for (int i = 0; i < ps.Count(); ++i)
            {
                PointPol p   = ps[i];
                int      ind = points.FindIndex(pinl => pointsEqual(p, pinl));
                if (ind == -1)
                {
                    points.Add(p);
                }
            }

            if (points.Count() > 1)
            {
                PointPol p2, p1 = ps.First();
                int      indp, ind2, ind1 = points.FindIndex(pinl => pointsEqual(p1, pinl));
                for (int i = 1; i < ps.Count(); ++i)
                {
                    p2   = ps[i];
                    ind2 = points.FindIndex(pinl => pointsEqual(p2, pinl));
                    indp = edges.FindIndex(pair =>
                                           (pair.Item1 == ind2) && (pair.Item2 == ind1));
                    if ((ind1 != ind2) && (indp == -1))
                    {
                        edges.Add(Tuple.Create(ind1, ind2));
                    }
                    ind1 = ind2;
                }

                p2   = ps.First();
                ind2 = points.FindIndex(pinl => pointsEqual(p2, pinl));
                indp = edges.FindIndex(pair =>
                                       (pair.Item1 == ind2) && (pair.Item2 == ind1));
                if ((ind1 != ind2) && (indp == -1))
                {
                    edges.Add(Tuple.Create(ind1, ind2));
                }
            }

            deleteDuplicates();
        }
Beispiel #19
0
        private void Create_point_fors_Hor()
        {
            double x0 = Double.Parse(textBox1.Text);
            double x1 = Double.Parse(textBox2.Text);
            double y0 = Double.Parse(textBox3.Text);
            double y1 = Double.Parse(textBox4.Text);

            step = Int32.Parse(textBox5.Text);

            double dx = (x1 - x0) / step;
            double dy = (y1 - y0) / step;


            points = new PointPol[(step + 1) * (step + 1)];
            for (int i = 0; i < step + 1; ++i)
            {
                for (int j = 0; j < step + 1; ++j)
                {
                    points[i * (step + 1) + j] = new PointPol(x0 + i * dx, y0 + j * dy, f(x0 + i * dx, y0 + j * dy));
                }
            }
        }
Beispiel #20
0
        public PointPol rotate(Vector direction, double angle, double a, double b, double c)
        {
            double   phi = Math.PI / 360 * angle;
            PointPol p   = shift(-a, -b, -c);

            double x1 = direction.P1.X;
            double y1 = direction.P1.Y;
            double z1 = direction.P1.Z;

            double x2 = direction.P2.X;
            double y2 = direction.P2.Y;
            double z2 = direction.P2.Z;

            double vecx = x2 - x1;
            double vecy = y2 - y1;
            double vecz = z2 - z1;

            double len = Math.Sqrt(vecx * vecx + vecy * vecy + vecz * vecz);

            double l = vecx / len;
            double m = vecy / len;
            double n = vecz / len;

            double[,] transfer = new double[4, 4] {
                { l *l + Math.Cos(phi) * (1 - l * l), l *(1 - Math.Cos(phi)) * m + n * Math.Sin(phi), l *(1 - Math.Cos(phi)) * n - m * Math.Sin(phi), 0 },
                { l *(1 - Math.Cos(phi)) * m - n * Math.Sin(phi), m *m + Math.Cos(phi) * (1 - m * m), m *(1 - Math.Cos(phi)) * n + l * Math.Sin(phi), 0 },
                { l *(1 - Math.Cos(phi)) * n + m * Math.Sin(phi), m *(1 - Math.Cos(phi)) * n - l * Math.Sin(phi), n *n + Math.Cos(phi) * (1 - n * n), 0 },
                { 0, 0, 0, 1 }
            };
            var t1 = matrix_multiplication(p.getP(), transfer);

            t1 = matrix_multiplication(t1, transfer);

            PointPol p2 = translatePol(t1);
            PointPol p3 = p2.shift(a, b, c);

            return(p3);
        }
Beispiel #21
0
        public void write_axes3(double phi_a, double psi_a, double ind)
        {
            PointPol p0 = new PointPol(0, 0, 0);
            PointPol p1 = new PointPol(pictureBox3.Width / 2 * ind, 0, 0);
            PointPol p2 = new PointPol(0, pictureBox3.Width / 2 * ind, 0);
            PointPol p3 = new PointPol(0, 0, pictureBox3.Width / 2 * ind);

            Point o = p0.To2D(phi_a, psi_a);
            Point x = p1.To2D(phi_a, psi_a);
            Point y = p2.To2D(phi_a, psi_a);
            Point z = p3.To2D(phi_a, psi_a);

            Font       font  = new Font("Arial", 8);
            SolidBrush brush = new SolidBrush(Color.Black);

            g3.DrawString("X", font, brush, x);
            g3.DrawString("Y", font, brush, y);
            g3.DrawString("Z", font, brush, z);

            Pen my_pen = new Pen(Color.Blue);

            g3.DrawLine(my_pen, o, x);
            my_pen.Color = Color.Red;
            g3.DrawLine(my_pen, o, y);
            my_pen.Color = Color.Green;
            g3.DrawLine(my_pen, o, z);

            PointPol newp = new PointPol(Double.Parse(textBoxViewVectorX.Text) * 50,
                                         Double.Parse(textBoxViewVectorY.Text) * 50,
                                         Double.Parse(textBoxViewVectorZ.Text) * 50);
            Point newpp = newp.To2D(phi_a, psi_a);

            g3.DrawEllipse(new Pen(Color.Red), newpp.X - 1, newpp.Y - 1, 2, 2);

            pictureBox3.Image = pictureBox3.Image;
        }
Beispiel #22
0
        public void write_axes()
        {
            g = Graphics.FromImage(pictureBox1.Image);

            g.ScaleTransform(1, -1);
            g.TranslateTransform(pictureBox1.Width / 2, -pictureBox1.Height / 2);

            PointPol p0 = new PointPol(0, 0, 0);
            PointPol p1 = new PointPol(pictureBox1.Width, 0, 0);
            PointPol p2 = new PointPol(0, pictureBox1.Width, 0);
            PointPol p3 = new PointPol(0, 0, pictureBox1.Width);

            String s      = comboBox3.SelectedItem.ToString();
            Pen    my_pen = new Pen(Color.Blue);

            g.DrawLine(my_pen, p0.To2D(s), p1.To2D(s));
            my_pen.Color = Color.Red;
            g.DrawLine(my_pen, p0.To2D(s), p2.To2D(s));
            my_pen.Color = Color.Green;

            g.DrawLine(my_pen, p0.To2D(s), p3.To2D(s));

            pictureBox1.Image = pictureBox1.Image;
        }
Beispiel #23
0
 public void scale(double ind_scale, double a, double b, double c)
 {
     P1 = P1.scale(ind_scale, a, b, c);
     P2 = P2.scale(ind_scale, a, b, c);
 }
Beispiel #24
0
 public bool equals(PointPol p1)
 {
     return(Math.Abs(p1.X - X) < 0.0001 && Math.Abs(p1.Y - Y) < 0.0001 && Math.Abs(p1.Z - Z) < 0.0001);
 }
Beispiel #25
0
 public Vector(PointPol p1, PointPol p2)
 {
     P1 = p1; P2 = p2;
 }
Beispiel #26
0
 public void rotate(Vector e, double angle, double a, double b, double c)
 {
     P1 = P1.rotate(e, angle, a, b, c);
     P2 = P2.rotate(e, angle, a, b, c);
 }
Beispiel #27
0
        private int find_index(PointPol p)
        {
            int i = vertices.Keys.First(x => vertices[x].Equal(p));

            return(i);
        }
Beispiel #28
0
 private bool pointsEqual(PointPol p1, PointPol p2)
 {
     return((p1.X == p2.X) && (p1.Y == p2.Y) && (p1.Z == p2.Z));
 }
Beispiel #29
0
 private double scalarProduct(PointPol vec1, PointPol vec2)
 {
     return(vec1.X * vec2.X + vec1.Y * vec2.Y + vec1.Z * vec2.Z);
 }
Beispiel #30
0
 public void shift(double a, double b, double c)
 {
     P1 = P1.shift(a, b, c);
     P2 = P2.shift(a, b, c);
 }