/** * 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)); } }
/** 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); }
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)); // //////////////////////////////////// } }