Beispiel #1
0
        /**
         * Add the intersections of triangle t with the section to the list of
         * intersection (set)
         */
        void cut(Triangle_dt t)
        {
            if (t.isHalfplane())
            {
                return;
            }
            Point_dt p1 = t.p1(), p2 = t.p2(), p3 = t.p3();
            int      f1 = p1.pointLineTest(_p1, _p2);
            int      f2 = p2.pointLineTest(_p1, _p2);
            int      f3 = p3.pointLineTest(_p1, _p2);

            if ((f1 == Point_dt.LEFT | f1 == Point_dt.RIGHT) &&
                (f1 == f2 && f1 == f3))
            {
                return;
            }
            if (f1 != f2 && _p1.pointLineTest(p1, p2) != _p2.pointLineTest(p1, p2))
            {
                Add(intersection(p1, p2));
            }
            if (f2 != f3 && _p1.pointLineTest(p2, p3) != _p2.pointLineTest(p2, p3))
            {
                Add(intersection(p2, p3));
            }
            if (f3 != f1 && _p1.pointLineTest(p3, p1) != _p2.pointLineTest(p3, p1))
            {
                Add(intersection(p3, p1));
            }
        }
Beispiel #2
0
        /** return true iff the segment _p1,_p2 is cutting t */
        bool cut(Point_dt pp1, Point_dt pp2, Triangle_dt t)
        {
            bool ans = false;

            if (t.isHalfplane())
            {
                return(false);
            }
            Point_dt p1 = t.p1(), p2 = t.p2(), p3 = t.p3();
            int      f1 = p1.pointLineTest(pp1, pp2);
            int      f2 = p2.pointLineTest(pp1, pp2);
            int      f3 = p3.pointLineTest(pp1, pp2);

            if ((f1 == Point_dt.LEFT | f1 == Point_dt.RIGHT) &&
                (f1 == f2 && f1 == f3))
            {
                return(false);
            }

            if (f1 != f2 && pp1.pointLineTest(p1, p2) != pp2.pointLineTest(p1, p2))
            {
                return(true);
            }
            if (f2 != f3 && pp1.pointLineTest(p2, p3) != pp2.pointLineTest(p2, p3))
            {
                return(true);
            }
            if (f3 != f1 && pp1.pointLineTest(p3, p1) != pp2.pointLineTest(p3, p1))
            {
                return(true);
            }

            return(ans);
        }
Beispiel #3
0
        public void drawTriangle(Graphics g, Triangle_dt t, Color cl)
        {
            if (_view_flag == VIEW1 || t.isHalfplane())
            {
                if (t.isHalfplane())
                {
                    if (cl == Color.Empty)
                    {
                        drawLine(g, t.p1(), t.p2(), Color.Blue);
                    }
                    else
                    {
                        drawLine(g, t.p1(), t.p2(), cl);
                    }
                }
                else
                {
                    if (cl == Color.Empty)
                    {
                        drawLine(g, t.p1(), t.p2(), Color.Black);
                        drawLine(g, t.p2(), t.p3(), Color.Black);
                        drawLine(g, t.p3(), t.p1(), Color.Black);
                    }

                    {
                        drawLine(g, t.p1(), t.p2(), cl);
                        drawLine(g, t.p2(), t.p3(), cl);
                        drawLine(g, t.p3(), t.p1(), cl);
                    }
                }
            }
            else
            {
                // //////////////////////////////////////////////////////////////////
                double maxZ = _ajd.maxBoundingBox().z;
                double minZ = _ajd.minBoundingBox().z;
                double z    = (t.p1().z + t.p2().z + t.p3().z) / 3.0;
                double dz   = maxZ - minZ;
                if (dz == 0)
                {
                    dz = 1;
                }
                int co = 30 + (int)(220 * ((z - minZ) / dz));
                if (cl == Color.Empty)
                {
                    cl = Color.FromArgb(co, co, co);
                }

                int[] xx = new int[3], yy = new int[3];
                // double f = 0;
                // double dx_map = _dx_map.y- _dx_map.x;
                // double dy_map = _dy_map.y- _dy_map.x;

                // f = (t.p1().x -_dx_map.x)/dx_map;
                Point_dt p1 = world2screen(t.p1());
                xx[0] = (int)p1.x;
                yy[0] = (int)p1.y;
                Point_dt p2 = world2screen(t.p2());
                xx[1] = (int)p2.x;
                yy[1] = (int)p2.y;
                Point_dt p3 = world2screen(t.p3());
                xx[2] = (int)p3.x;
                yy[2] = (int)p3.y;

                Brush b = new SolidBrush(cl);
                g.FillPolygon(b, ToPoints(xx, yy));
                // ////////////////////////////////////
            }
        }
Beispiel #4
0
        void drawTriangleTopoLines(Graphics g, Triangle_dt t, double dz, Color cl)
        {
            if (t.p1().z < 0 | t.p2().z < 0 | t.p3().z < 0)
            {
                return;
            }

            Point_dt[] p12 = computePoints(t.p1(), t.p2(), dz);
            Point_dt[] p23 = computePoints(t.p2(), t.p3(), dz);
            Point_dt[] p31 = computePoints(t.p3(), t.p1(), dz);

            int  i12 = 0, i23 = 0, i31 = 0;
            bool cont = true;

            while (cont)
            {
                cont = false;

                if (i12 < p12.Length && i23 < p23.Length && p12[i12].z == p23[i23].z)
                {
                    if (p12[i12].z % 200 > 100)
                    {
                        drawLine(g, p12[i12], p23[i23], Color.Red);
                    }
                    else
                    {
                        drawLine(g, p12[i12], p23[i23], Color.Yellow);
                    }
                    i12++;
                    i23++;
                    cont = true;
                }
                if (i23 < p23.Length && i31 < p31.Length && p23[i23].z == p31[i31].z)
                {
                    if (p23[i23].z % 200 > 100)
                    {
                        drawLine(g, p23[i23], p31[i31], Color.Red);
                    }
                    else
                    {
                        drawLine(g, p23[i23], p31[i31], Color.Yellow);
                    }

                    i23++;
                    i31++;
                    cont = true;
                }
                if (i12 < p12.Length && i31 < p31.Length && p12[i12].z == p31[i31].z)
                {
                    if (p12[i12].z % 200 > 100)
                    {
                        drawLine(g, p12[i12], p31[i31], Color.Red);
                    }
                    else
                    {
                        drawLine(g, p12[i12], p31[i31], Color.Yellow);
                    }

                    i12++;
                    i31++;
                    cont = true;
                }
            }
        }