/// <summary> /// Update neighbor pointers /// </summary> /// <param name="p1">Point 1 of the shared edge</param> /// <param name="p2">Point 2 of the shared edge</param> /// <param name="t">This triangle's new neighbor</param> private void MarkNeighbor(PolygonPoint p1, PolygonPoint p2, DelaunayTriangle t) { int i = EdgeIndex(p1, p2); if (i == -1) { throw new Exception("Error marking neighbors -- t doesn't contain edge p1-p2!"); } Neighbors[i] = t; }
public int IndexOf(PolygonPoint p) { int i = Points.IndexOf(p); if (i == -1) { throw new Exception("Calling index with a point that doesn't exist in triangle"); } return(i); }
private static void EdgeEvent(DTSweepContext tcx, PolygonPoint ep, PolygonPoint eq, DelaunayTriangle triangle, PolygonPoint point) { PolygonPoint p1, p2; if (IsEdgeSideOfTriangle(triangle, ep, eq)) { return; } p1 = triangle.PointCCWFrom(point); Orientation o1 = TriangulationUtil.Orient2D(eq, p1, ep); if (o1 == Orientation.Collinear) { // TODO: Split edge in two //// splitEdge( ep, eq, p1 ); // edgeEvent( tcx, p1, eq, triangle, point ); // edgeEvent( tcx, ep, p1, triangle, p1 ); // return; throw new PointOnEdgeException("EdgeEvent - Point on constrained edge not supported yet", eq, p1, ep); } p2 = triangle.PointCWFrom(point); Orientation o2 = TriangulationUtil.Orient2D(eq, p2, ep); if (o2 == Orientation.Collinear) { // TODO: Split edge in two // edgeEvent( tcx, p2, eq, triangle, point ); // edgeEvent( tcx, ep, p2, triangle, p2 ); // return; throw new PointOnEdgeException("EdgeEvent - Point on constrained edge not supported yet", eq, p2, ep); } if (o1 == o2) { // Need to decide if we are rotating CW or CCW to get to a triangle // that will cross edge if (o1 == Orientation.CW) { triangle = triangle.NeighborCCWFrom(point); } else { triangle = triangle.NeighborCWFrom(point); } EdgeEvent(tcx, ep, eq, triangle, point); } else { // This triangle crosses constraint so lets flippin start! FlipEdgeEvent(tcx, ep, eq, triangle, point); } }
void UpdateLatLonFromPoints(Region region) { int numPoints = region.points.Length; PolygonPoint[] latlons = new PolygonPoint[numPoints]; for (int k = 0; k < numPoints; k++) { latlons[k] = _map.GetLatLonFromSpherePoint(region.points[k]); } region.latlon = latlons; }
private int FindIndex(PolygonPoint[] points, TriangulationPoint toFind) { for (int i = 0; i < points.Length; i++){ PolygonPoint p = points[i]; if (p == toFind) return i; if (p.X != toFind.X) continue; if (p.Y != toFind.Y) continue; return i; } return -1; }
protected override void OnUpdate() { Polygon poly = null; var holes = new List <Polygon>(); Entities.ForEach((ref PolygonOrientationComponent polygonOrientation, DynamicBuffer <PointSampleGlobal> points) => { PolygonPoint[] pointArray = new PolygonPoint[points.Length]; for (var i = 0; i < points.Length; i++) { pointArray[i] = new PolygonPoint(points[i].pose.pos.x, points[i].pose.pos.z); } var polygon = new Polygon(pointArray); if (polygonOrientation.Orientation == PolygonOrientation.Outside) { if (poly != null) { Debug.LogError("Multiple outside polygons detected. " + "Multiple outside polygons indicate a disconnected road network."); } poly = polygon; } else { holes.Add(polygon); } }); if (poly == null) { throw new NullReferenceException($"Polygon is null - will be unable to create mesh for " + $"{Parameters.Parent.name}."); } foreach (var hole in holes) { poly.AddHole(hole); } var mesh = RoadNetworkMesher.PolygonToMesh(poly, Parameters.UVMultiplier); GameObject go = new GameObject("Road mesh"); go.transform.parent = Parameters.Parent; go.transform.localPosition = new Vector3(0, .1f, 0); var meshRenderer = go.AddComponent <MeshRenderer>(); meshRenderer.material = Parameters.Material; var meshFilter = go.AddComponent <MeshFilter>(); meshFilter.mesh = mesh; go.AddComponent <MeshCollider>(); }
private void AddBooksAndPagesScatterSeries(PlotModel newPlot) { ScatterSeries pointsSeries; OxyPlotUtilities.CreateScatterPointSeries(out pointsSeries, ChartAxisKeys.LongitudeKey, ChartAxisKeys.LatitudeKey, "Countries"); foreach (AuthorCountry authorCountry in BooksReadProvider.AuthorCountries) { string name = authorCountry.Country; WorldCountry country = GeographyProvider.WorldCountries.FirstOrDefault(w => w.Country == name); if (country != null) { int pointSize = authorCountry.TotalBooksReadFromCountry; if (pointSize < 5) { pointSize = 5; } PolygonPoint latLong = new PolygonPoint() { Latitude = country.Latitude, Longitude = country.Longitude }; double x, y; latLong.GetCoordinates(out x, out y); ScatterPoint point = new ScatterPoint(x, y, pointSize, authorCountry.TotalPagesReadFromCountry) { Tag = name }; pointsSeries.Points.Add(point); } } pointsSeries.RenderInLegend = false; pointsSeries.TrackerFormatString = "{Tag}\nLat/Long ( {4:0.###} ,{2:0.###} ) \nTotalPages {6}"; newPlot.Series.Add(pointsSeries); List <OxyColor> colors = new List <OxyColor>(); foreach (OxyColor color in OxyPalettes.Jet(200).Colors) { OxyColor faintColor = OxyColor.FromArgb(128, color.R, color.G, color.B); colors.Add(faintColor); } OxyPalette faintPalette = new OxyPalette(colors); newPlot.Axes.Add(new LinearColorAxis { Position = AxisPosition.Right, Palette = faintPalette, Title = "Total Pages" }); }
/// <summary> /// Constructor /// </summary> public PolygonPointViewModel(PolygonPoint point, ShapeViewModel parent) { // Store off the model PolygonPoint = point; // Default the points to black Color = Colors.DodgerBlue; DeselectedColor = Colors.DodgerBlue; // Store off a reference to the parent view model Parent = parent; }
/// <summary> /// Constructor /// </summary> public MorphPolygon() { HeadLength = 4; HeadDuration = 20; Acceleration = 0; HeadColor = new ColorGradient(System.Drawing.Color.White); TailColor = new ColorGradient(System.Drawing.Color.Red); FillColor = new ColorGradient(System.Drawing.Color.Red); int width = 10; int height = 10; // If the display element size is available then... if (BufferWidth != 0 && BufferHeight != 0) { // Default to the polygon being 1/4 the display element width = BufferWidth / 4; height = BufferHeight / 4; } // Create the default polygon Polygon = new Polygon(); PolygonPoint ptTopLeft = new PolygonPoint(); ptTopLeft.X = 0; ptTopLeft.Y = 0; PolygonPoint ptTopRight = new PolygonPoint(); ptTopRight.X = width - 1; ptTopRight.Y = 0; PolygonPoint ptBottomRight = new PolygonPoint(); ptBottomRight.X = width - 1; ptBottomRight.Y = height - 1; PolygonPoint ptBottomLeft = new PolygonPoint(); ptBottomLeft.X = 0; ptBottomLeft.Y = height - 1; // Add the points to the polygon Polygon.Points.Add(ptTopLeft); Polygon.Points.Add(ptTopRight); Polygon.Points.Add(ptBottomRight); Polygon.Points.Add(ptBottomLeft); FillType = PolygonFillType.Wipe; // Default the brightness to 100% TailBrightness = new Curve(CurveType.Flat100); HeadBrightness = new Curve(CurveType.Flat100); FillBrightness = new Curve(CurveType.Flat100); }
static List <PolygonPoint> ConvertPoints(List <Vector3> points) { int count = points.Count; List <PolygonPoint> result = new List <PolygonPoint>(count); for (int i = 0; i < count; i++) { Vector3 p = points[i]; PolygonPoint pp = new PolygonPoint(p.x, p.y); result.Add(pp); } return(result); }
void ReplacePointsFromPolygon(Region region, WPM.Geom.Polygon polygon) { List <Point> points = polygon.contours[0].points; int numPoints = points.Count; PolygonPoint[] latlons = new PolygonPoint[numPoints]; for (int k = 0; k < numPoints; k++) { latlons[k] = new PolygonPoint(points[k].x, points[k].y); } region.latlon = latlons; UpdatePointsFromLatLon(region); }
/// <summary> /// Triangulates the point cloud. /// </summary> /// <param name="points">The point cloud.</param> /// <returns>A triangulated polygon.</returns> private static Polygon Triangulate(List <Vector2> points) { PolygonPoint[] tempPoints = new PolygonPoint[points.Count]; for (int i = 0; i < points.Count; i++) { tempPoints[i] = new PolygonPoint(points[i].X, points[i].Y); } Polygon polygon = new Polygon(tempPoints); P2T.Triangulate(polygon); return(polygon); }
/// <summary> /// In the case of a pointset with some constraint edges. If a triangle side is collinear /// with a part of the constraint we split the constraint into two constraints. This could /// happen when the given constraint migth intersect a point in the set.<br> /// This can never happen in the case when we are working with a polygon. /// /// Think of two triangles that have non shared sides that are collinear and the constraint /// is set from a point in triangle A to a point in triangle B so that the constraint is /// the union of both those sides. We then have to split the constraint into two so we get /// one constraint for each triangle. /// </summary> /// <param name="ep"></param> /// <param name="eq"></param> /// <param name="p">point on the edge between ep->eq</param> private static void SplitEdge(PolygonPoint ep, PolygonPoint eq, PolygonPoint p) { DTSweepConstraint edge = eq.Edges.First(e => e.Q == ep || e.P == ep); edge.P = p; CreateSweepConstraint(ep, p);// Et tu, Brute? --MM //new DTSweepConstraint(ep, p); // // Redo this edge now that we have split the constraint // newEdgeEvent( tcx, edge, triangle, point ); // // Continue with new edge // newEdgeEvent( tcx, edge, triangle, p2 ); }
private static void FlipEdgeEvent(DTSweepContext tcx, PolygonPoint ep, PolygonPoint eq, DelaunayTriangle t, PolygonPoint p) { DelaunayTriangle ot = t.NeighborAcrossFrom(p); PolygonPoint op = ot.OppositePoint(t, p); if (ot == null) { // If we want to integrate the fillEdgeEvent do it here // With current implementation we should never get here throw new InvalidOperationException("[BUG:FIXME] FLIP failed due to missing triangle"); } bool inScanArea = TriangulationUtil.InScanArea(p, t.PointCCWFrom(p), t.PointCWFrom(p), op); if (inScanArea) { // Lets rotate shared edge one vertex CW RotateTrianglePair(t, p, ot, op); tcx.MapTriangleToNodes(t); tcx.MapTriangleToNodes(ot); if (p == eq && op == ep) { if (eq == tcx.EdgeEvent.ConstrainedEdge.Q && ep == tcx.EdgeEvent.ConstrainedEdge.P) { t.MarkConstrainedEdge(ep, eq); ot.MarkConstrainedEdge(ep, eq); Legalize(tcx, t); Legalize(tcx, ot); } else { // XXX: I think one of the triangles should be legalized here? } } else { Orientation o = TriangulationUtil.Orient2D(eq, op, ep); t = NextFlipTriangle(tcx, o, t, ot, p, op); FlipEdgeEvent(tcx, ep, eq, t, p); } } else { PolygonPoint newP = NextFlipPoint(ep, eq, ot, op); FlipScanEdgeEvent(tcx, ep, eq, t, ot, newP); EdgeEvent(tcx, ep, eq, t, p); } }
private static void FinalizationPolygon(DTSweepContext tcx) { // Get an Internal triangle to start with DelaunayTriangle t = tcx.Front.Head.Next.Triangle; PolygonPoint p = tcx.Front.Head.Next.Point; while (!t.GetConstrainedEdgeCW(p)) { t = t.NeighborCCWFrom(p); } // Collect interior triangles constrained by edges tcx.MeshClean(t); }
public static List <PolygonPoint> AdaptativePolygonReduce( List <PolygonPoint> points, Int32 maxSize) { int attempts = 0; if (points.Count < maxSize) { return(points); } List <PolygonPoint> reducedPoints = new List <PolygonPoint>(); reducedPoints.AddRange(points); // check that first and last points are different & if not remove the last point PolygonPoint first = points.First(); PolygonPoint last = points.Last(); bool lastRemoved = false; if (Math.Abs(first.Latitude - last.Latitude) < LatLongTolerance && Math.Abs(first.Longitude - last.Longitude) < LatLongTolerance) { lastRemoved = true; reducedPoints.RemoveAt(points.Count - 1); } double tolerance = InitialPolygonTolerance; while (attempts < MaxIterations) { reducedPoints = DouglasPeuckerReduction(reducedPoints, tolerance); if (reducedPoints.Count <= maxSize) { break; } else { attempts++; tolerance *= 2; } } if (lastRemoved) { reducedPoints.Add(last); } return(reducedPoints); }
private TextVisual3D GetNationText(Nation country, int count, string label, double height) { double latitude = country.Latitude; double longitude = country.Longitude; PolygonPoint latLong = new PolygonPoint() { Latitude = latitude, Longitude = longitude }; double x, y; latLong.GetCoordinates(out x, out y); var labelPoint = new Point3D(x, y + 1, height + 1); Brush background = Brushes.LightYellow; if (country.ImageUri != null) { try { System.Windows.Media.Imaging.BitmapImage im = new System.Windows.Media.Imaging.BitmapImage(country.DisplayImage); background = new ImageBrush(im); background.Opacity = 0.5; } catch (Exception e) { _log.Debug(e); } } TextVisual3D text3D = new TextVisual3D() { Foreground = Brushes.DarkBlue, Background = background, BorderBrush = Brushes.PapayaWhip, Height = 2, FontWeight = System.Windows.FontWeights.Bold, IsDoubleSided = true, Position = labelPoint, UpDirection = new Vector3D(0, 0.7, 1), TextDirection = new Vector3D(1, 0, 0), HorizontalAlignment = System.Windows.HorizontalAlignment.Left, VerticalAlignment = System.Windows.VerticalAlignment.Bottom, Text = label }; return(text3D); }
private void AttachLines(PolygonPoint head, List <LineSegment> lines) { var tail = this.FindTail(head); while (lines.Count > 1) { LineSegment removeLine = null; foreach (var l in lines) { if (tail.Equals(l.P1)) { tail.Next = new PolygonPoint(l.P2.X, l.P2.Y); } else if (tail.Equals(l.P2)) { tail.Next = new PolygonPoint(l.P1.X, l.P1.Y); } if (tail.Next == null) { continue; } tail = tail.Next; removeLine = l; break; } if (removeLine == null) { throw new Exception("Shape is not polygon"); } lines.Remove(removeLine); } var line = lines[0]; if (!((head.Equals(line.P1) && tail.Equals(line.P2)) || (head.Equals(line.P2) && tail.Equals(line.P1)))) { throw new Exception("Shape is not connecting"); } lines.RemoveAt(0); }
PolygonPoint[] InsertLatLon(PolygonPoint[] pointArray, int index, PolygonPoint latlonToInsert) { List <PolygonPoint> temp = new List <PolygonPoint>(pointArray.Length + 1); for (int k = 0; k < pointArray.Length; k++) { if (k == index) { temp.Add(latlonToInsert); } pointArray[k].Reset(); temp.Add(pointArray[k]); } return(temp.ToArray()); }
private static void AddIntersectionPoint(Dictionary <PolygonPoint, List <PolygonPoint> > dictSecPointsA, PolygonPoint pointA1, PolygonPoint intersectionPointA) { if (dictSecPointsA.ContainsKey(pointA1)) { dictSecPointsA.Add(pointA1, new List <PolygonPoint>() { intersectionPointA }); } else { dictSecPointsA[pointA1].Add(intersectionPointA); } }
/// <summary> /// This implementation will use simple node traversal algorithm to find a point on the front /// </summary> public AdvancingFrontNode LocatePoint(PolygonPoint point) { double px = point.X; AdvancingFrontNode node = FindSearchNode(); double nx = node.Point.X; if (px == nx) { if (point != node.Point) { // We might have two nodes with same x value for a short time if (point == node.Prev.Point) { node = node.Prev; } else if (point == node.Next.Point) { node = node.Next; } else { throw new Exception("Failed to find Node for given afront point"); } } } else if (px < nx) { while ((node = node.Prev) != null) { if (point == node.Point) { break; } } } else { while ((node = node.Next) != null) { if (point == node.Point) { break; } } } Search = node; return(node); }
/// <summary> /// For a Point, last used Edge and possible Edges, retrieve the best next Edge /// </summary> /// <param name="point">The current Point</param> /// <param name="lastEdge">The last used Edge</param> /// <param name="possibleEdges">The possible next Edges</param> /// <returns>Best next Edge</returns> internal static PolygonEdge BestEdge(PolygonPoint point, PolygonEdge lastEdge, List <PolygonEdge> possibleEdges) { // If just Starting, return the first possible Edge of the Point // If only one possibility, return that if ((lastEdge.PointOne == null && lastEdge.PointTwo == null) || possibleEdges.Count == 1) { return(possibleEdges[0]); } // Variables needed to determine the next Edge var bestEdge = possibleEdges[0]; var bestAngle = (float)Math.PI * 2; // Vector from last Point to current Point var lastVector = (lastEdge.PointTwo.Point - lastEdge.PointOne.Point); lastVector.Normalize(); // Using CCW Point Order, so the left Vector always points towards the Polygon Center var insideVector = new Point(-lastVector.Y, lastVector.X); // Check all possible Edges foreach (var possibleEdge in possibleEdges) { // Next Edge Vector var edgeVector = (possibleEdge.PointTwo.Point - possibleEdge.PointOne.Point); edgeVector.Normalize(); // Dot determines if the Vector also points towards the Polygon Center or not (> 0, yes, < 0, no) var dot = insideVector.X * edgeVector.X + insideVector.Y * edgeVector.Y; // Cos represents the Angle between the last Edge and the next Edge var cos = lastVector.X * edgeVector.X + lastVector.Y * edgeVector.Y; var angle = 0f; // Depending on the Dot-Value, calculate the actual "inner" Angle if ((insideVector.X * edgeVector.X + insideVector.Y * edgeVector.Y) > 0) { angle = (float)Math.PI - (float)Math.Acos(cos); } else { angle = (float)Math.PI + (float)Math.Acos(cos); } // Replace the old Values if a better Edge was found if (angle < bestAngle) { bestAngle = angle; bestEdge = possibleEdge; } } return(bestEdge); }
/// Forumla to calculate signed area /// Positive if CCW /// Negative if CW /// 0 if collinear /// A[P1,P2,P3] = (x1*y2 - y1*x2) + (x2*y3 - y2*x3) + (x3*y1 - y3*x1) /// = (x1-x3)*(y2-y3) - (y1-y3)*(x2-x3) public static Orientation Orient2D(PolygonPoint pa, PolygonPoint pb, PolygonPoint pc) { double detleft = (pa.X - pc.X) * (pb.Y - pc.Y); double detright = (pa.Y - pc.Y) * (pb.X - pc.X); double val = detleft - detright; if (val > -Epsilon && val < Epsilon) { return(Orientation.Collinear); } else if (val > 0) { return(Orientation.CCW); } return(Orientation.CW); }
/// <summary> /// Helper method to convert a set of 3D points into the 2D polygon points /// needed by the Poly2Tri code. /// </summary> /// <returns>List of 2D PolygonPoints.</returns> /// <param name="points">3D points.</param> /// <param name="rotation">Rotation needed to convert 3D points into the XY plane.</param> /// <param name="name="codeToPosition">Map (which we'll update) of PolygonPoint vertex codes to original 3D position.</param> static List <PolygonPoint> ConvertPoints(List <Vector3> points, Quaternion rotation, Dictionary <uint, Vector3> codeToPosition) { int count = points.Count; List <PolygonPoint> result = new List <PolygonPoint>(count); for (int i = 0; i < count; i++) { Vector3 originalPos = points[i]; Vector3 p = rotation * originalPos; PolygonPoint pp = new PolygonPoint(p.x, p.y); // Debug.Log("Rotated " + originalPos.ToString("F4") + " to " + p.ToString("F4")); codeToPosition[pp.VertexCode] = originalPos; result.Add(pp); } return(result); }
private PolygonPoint FindTail(PolygonPoint head) { var tail = head; while (tail.Next != null) { tail = tail.Next; if (object.ReferenceEquals(tail, head)) { return(null); } } return(tail); }
void Parse(Stream s) { BinaryReader r = new BinaryReader(s); this.name = r.ReadUInt32(); this.priority = r.ReadByte(); this.areaTypeFlags = (AreaType)r.ReadUInt32(); this.closedPolygon = new PolygonPointList(handler, s); this.allowIntersectionFlags = (AllowIntersection)r.ReadUInt32(); this.surfaceTypeFlags = (SurfaceType)r.ReadUInt32(); this.surfaceAttributeFlags = (SurfaceAttribute)r.ReadUInt32(); this.levelOffset = r.ReadByte(); this.elevationOffset = ParentVersion >= 0x00000007 ? r.ReadSingle() : 0; this.lower = new PolygonPoint(requestedApiVersion, handler, s); this.upper = new PolygonPoint(requestedApiVersion, handler, s); }
static List <PolygonPoint> ConvertPoints(List <Vector2> points, Dictionary <uint, Vector2> codeToPosition) { int count = points.Count; List <PolygonPoint> result = new List <PolygonPoint>(count); Vector2 pos = Vector2.zero; PolygonPoint pp = null; for (int i = 0; i < count; i++) { pos = points[i]; pp = new PolygonPoint(pos.x, -pos.y); codeToPosition[pp.VertexCode] = pos; result.Add(pp); } return(result); }
private static bool IsEdgeSideOfTriangle(DelaunayTriangle triangle, PolygonPoint ep, PolygonPoint eq) { int index = triangle.EdgeIndex(ep, eq); if (index == -1) { return(false); } triangle.MarkConstrainedEdge(index); triangle = triangle.Neighbors[index]; if (triangle != null) { triangle.MarkConstrainedEdge(ep, eq); } return(true); }
private void InitMap() { foreach (Transform child in obstacles.transform) { if (child.gameObject.GetComponent <WildObstacle>() != null) { Obstacles.Add(child.gameObject.GetComponent <WildObstacle>()); } } polygons = new List <Polygon>(); PolyPoints.Clear(); int pIdx = 0; for (int i = 0; i < Obstacles.Count; i++) { List <Vector2> expandedPoints = Obstacles[i].GetExpandedOuterInWorld(ColDis); Polygon polygon = new Polygon(); polygon.Num = expandedPoints.Count; polygon.Points = new PolygonPoint[polygon.Num]; for (int j = 0; j < expandedPoints.Count; j++) { Vector2 p = transform.InverseTransformPoint(expandedPoints[j]); PolygonPoint pp = new PolygonPoint(polygon, pIdx++, p); polygon.Points[j] = pp; PolyPoints.Add(pp); } polygons.Add(polygon); } dis = new float[pIdx, pIdx]; for (int i = 0; i < pIdx; i++) { for (int j = 0; j < pIdx; j++) { dis[i, j] = float.MaxValue; } } //Dictionary<PolygonPoint, PolygonPoint> map = new Dictionary<PolygonPoint, PolygonPoint>(); for (int i = 0; i < polygons.Count; i++) { for (int j = i; j < polygons.Count; j++) { calculateRoutes(polygons[i], polygons[j], i == j); } } }
/// <summary> /// [Clipper] Converts IntPoints to PolygonPoints to feed the constructor for this class. /// </summary> /// <returns>The polygon points.</returns> /// <param name="p">Point.</param> public static IList <PolygonPoint> toPolygonPoints(IList <IntPoint> p) { IList <PolygonPoint> pts = new List <PolygonPoint>(p.Count); PolygonPoint curr; for (int i = 0; i < p.Count; i++) { curr = new PolygonPoint(p[i].X, p[i].Y); if (pts.Count != 0) { pts[pts.Count - 1].Next = curr; curr.Previous = pts[pts.Count - 1]; } pts.Add(curr); } return(pts); }
private double GetPolygonArea(List <PolygonPoint> ptArrayList) { PolygonPoint pt1 = ptArrayList[0]; PolygonPoint firstPt = pt1; var lastPt = default(PolygonPoint); double area = 0.0; for (int i = 1; i < ptArrayList.Count; ++i) { var pt2 = ptArrayList[i]; area += (((pt2.X - pt1.X) * (pt2.Y + pt1.Y)) / 2); pt1 = pt2; lastPt = pt1; } area += (((firstPt.X - lastPt.X) * (firstPt.Y + lastPt.Y)) / 2); return(area); }
public int[] Triangulate(UnityEngine.Vector2[] verts) { PolygonPoint[] points = new PolygonPoint[verts.Length]; for (int i = 0; i < verts.Length; i++) points[i] = new PolygonPoint(verts[i].x, verts[i].y); Polygon polygon = new Polygon(points); DTSweepContext tcx = new DTSweepContext(); tcx.PrepareTriangulation(polygon); DTSweep.Triangulate(tcx); int[] resultPoints = new int[polygon.Triangles.Count * 3]; int idx = 0; foreach (DelaunayTriangle triangle in polygon.Triangles) { resultPoints[idx++] = FindIndex(points, triangle.Points._0); resultPoints[idx++] = FindIndex(points, triangle.Points._1); resultPoints[idx++] = FindIndex(points, triangle.Points._2); } return resultPoints; }
private static PolygonSet FromTess(Tess tess) { var output = new PolygonSet(); for (int i = 0; i < tess.ElementCount; i++) { var poly = new Polygon(); for (int j = 0; j < 3; j++) { int index = tess.Elements[i * 3 + j]; if (index == -1) continue; var v = new PolygonPoint { X = tess.Vertices[index].Position.X, Y = tess.Vertices[index].Position.Y }; poly.Add(v); } output.Add(poly); } return output; }
private void RefreshAsset(string name) { var asset = _data.GetAsset(name); _sw.Reset(); foreach (var poly in asset.Polygons) { var v = new ContourVertex[poly.Count]; for (int i = 0; i < poly.Count; i++) { v[i].Position = new Vec3 { X = poly[i].X, Y = poly[i].Y }; v[i].Data = poly[i].Color; } _sw.Start(); _tess.AddContour(v, poly.Orientation); _sw.Stop(); } _sw.Start(); _tess.Tessellate(_windingRule, ElementType.Polygons, _polySize, VertexCombine); _sw.Stop(); var output = new PolygonSet(); for (int i = 0; i < _tess.ElementCount; i++) { var poly = new Polygon(); for (int j = 0; j < _polySize; j++) { int index = _tess.Elements[i * _polySize + j]; if (index == -1) continue; var v = new PolygonPoint { X = _tess.Vertices[index].Position.X, Y = _tess.Vertices[index].Position.Y, Color = (Color)_tess.Vertices[index].Data }; poly.Add(v); } output.Add(poly); } statusMain.Text = string.Format("{0:F3} ms - {1} polygons (of {2} vertices) {3}", _sw.Elapsed.TotalMilliseconds, _tess.ElementCount, _polySize, _polySize == 3 ? "... triangles" : ""); _canvas.Input = asset.Polygons; _canvas.Output = output; _canvas.Invalidate(); }
public static TriangulationPoint ToTriangulationPoint(PolygonPoint p) { return (TriangulationPoint)p; }
public static Point2D ToBasePoint(PolygonPoint p) { return (Point2D)p; }
private static PolygonSet FromTess(Tess tess) { var output = new PolygonSet(); for (int i = 0; i < tess.Elements.Count / 3; i++) { var poly = new Polygon(); for (int j = 0; j < 3; j++) { int index = tess.Elements[i * 3 + j]; if (index == -1) continue; var v = new PolygonPoint { X = tess.Vertices[index].X, Y = tess.Vertices[index].Y, //Color = _tess.Vertices[index].Data != null ? (Color)_tess.Vertices[index].Data : Color.White }; poly.Add(v); } output.Add(poly); } return output; }