2016-09-26 1 views
0

Ich möchte Abbildung mit Loch zeichnen.(Behoben) Poly2tri - Dreieck IsInterior-Eigenschaft - richtig konfigurieren

result I wanna

Um dies zu tun, ich habe Figur Dreiecke schneiden und sie eins nach dem anderen zu ziehen.

triangulated picture

Hier habe ich acht Außendreiecke und zwei Innen. Ich dachte, dass ich Äußere nur nehmen werde und sie wie

const int y = 100; 
const int x = 100; 
const int offset = 20; 

IList<PolygonPoint> bounds = new List<PolygonPoint> 
{ 
    new PolygonPoint(0,0), 
    new PolygonPoint(0, y), 
    new PolygonPoint(x, y), 
    new PolygonPoint(x, 0), 
}; 

IList<PolygonPoint> hole = new List<PolygonPoint> 
{ 
    new PolygonPoint(offset, offset), 
    new PolygonPoint(x - offset, offset), 
    new PolygonPoint(offset, y - offset), 
    new PolygonPoint(x - offset, y - offset), 
}; 

Polygon polygon = new Polygon(bounds); // here polygon contains four dots 
polygon.AddHole(new Polygon(hole)); // and here - eight 

P2T.Triangulate(polygon); // here I get ten triangles 

foreach (var triangle in polygon.Triangles.Where(tr => tr.IsInterior)) // <-- problem 
{ 
    // draw 
} 

ziehen aber jedes Dreieck im Polygon hat IsInterior == true. Was mache ich falsch?

P.S. Und für PointSet ist diese Eigenschaft im selben Fall immer falsch.

+0

Jedes Dreieck ist innerhalb des Rechtecks ​​ABCD, so dass sie alle innen sind. Sie wollen nur Dreiecke innerhalb/außerhalb des Loches. – jdweng

+0

@ Jdweng, es ist ein Problem, wenn ja. Ich habe keinen Zugang zu Löchern: Sie sind privat. – homk

+0

Nehmen Sie folgende Änderung vor: polygon.AddHole (neues Polygon (Loch)); An: Polygonloch = neues Polygon (Loch); polygon.AddHole (Loch); – jdweng

Antwort

2

Verdammt, es war einfacher, dass ich dachte.

Ich hatte falsche Punkt Reihenfolge.

Es haben außer diesem Teil

IList<PolygonPoint> hole = new List<PolygonPoint> 
{ 
    new PolygonPoint(offset, offset), 
    new PolygonPoint(offset, y - offset), 
    new PolygonPoint(x - offset, y - offset), 
    new PolygonPoint(x - offset, offset), 
}; 

All sein funktioniert ziemlich gut, und das Ergebnis sieht wie folgt aus:

correct triangles

Dank für alle hier!

Verwandte Themen