/// <summary> /// Divide <c>ParabolicArcSegment2D</c> on straight lines polygon. /// </summary> /// <param name="start">The start point of segment.</param> /// <param name="source">The segment to discretization.</param> /// <param name="target">The <c>Region2D</c> as target of discretization.</param> public void Discretize(Point start, ISegment2D source, IPolygon2D target) { var segment = source as ParabolicArcSegment2D; // The angle in degrees double totalAngle = segment.GetAngle(ref start); if (angle < Math.Abs(totalAngle) || this.numberOfTiles > 1) { int numberOfTiles = Math.Max((int)Math.Ceiling(Math.Abs(totalAngle) / angle), this.numberOfTiles); double deltaAngle = totalAngle / numberOfTiles; var mat = new Matrix(); mat.Rotate(deltaAngle); var t = segment.GetTangentOnSegment(ref start, 0); for (int i = 1; i < numberOfTiles; ++i) { t = mat.Transform(t); if (segment.CoordinatesFromTangent(ref start, t, out Point p)) { target.Add(p); } } } target.Add(segment.EndPoint); }
/// <summary> /// Divide <c>LineSegment2D</c> on straight lines polygon. /// </summary> /// <param name="start">The start point of segment.</param> /// <param name="source">The segment to discretization.</param> /// <param name="target">The <c>Polygon2D</c> as target of discretization.</param> public void Discretize(Point start, ISegment2D source, IPolygon2D target) { double length = source.GetLength(ref start); if (numberOfTiles > 1 || length > lengthOfTile) { int tiles = Math.Max(numberOfTiles, (int)Math.Ceiling(length / lengthOfTile)); LineSegment2D segment = source as LineSegment2D; Vector u = Point.Subtract(segment.EndPoint, start) / tiles; Point pt = start; for (int i = 1; i < tiles; ++i) { pt = Point.Add(pt, u); target.Add(pt); } } target.Add(source.EndPoint); }
/// <summary> /// Divide <c>CircularArcSegment2D</c> on straight lines polygon. /// </summary> /// <param name="start">The start point of segment.</param> /// <param name="source">The segment to discretization.</param> /// <param name="target">The <c>Region2D</c> as target of discretization.</param> public void Discretize(Point start, ISegment2D source, IPolygon2D target) { CircularArcSegment2D segment = source as CircularArcSegment2D; // The angle in degrees double totalAngle = Math.Abs(segment.GetAngle(ref start)); if (angle < totalAngle || this.numberOfTiles > 1) { int numberOfTiles = Math.Max((int)Math.Ceiling(totalAngle / angle), this.numberOfTiles); double deltaAngle = totalAngle / numberOfTiles * segment.IsCounterClockwise(ref start); Matrix mat = new Matrix(); Point centre = segment.GetCentre(ref start); for (int i = 1; i < numberOfTiles; ++i) { mat.RotateAt(deltaAngle, centre.X, centre.Y); target.Add(mat.Transform(start)); } } target.Add(segment.EndPoint); }
/// <summary> /// Discretize of <c>PolyLine2D</c> to <c>Polygon2D</c>. /// </summary> /// <param name="source">The <c>PolyLine2D</c> to discretization.</param> /// <param name="target">The <c>Polygon2D</c> as destination.</param> /// <param name="targetInxs">The <c>IList</c> as destination.</param> public void Discretize(IPolyLine2D source, ref IPolygon2D target, IList <int> targetInxs) { if (source == null) { return; } Point start = source.StartPoint; target.Add(start); int i = 0; int lastInx = 0; foreach (var segment in source.Segments) { SelectSegment2DDiscretizator(segment.GetType()).Discretize(start, segment, target); start = segment.EndPoint; if (targetInxs != null) { for (int j = lastInx; j < target.Count; j++) { targetInxs.Add(i); } lastInx = target.Count; } i++; } if (targetInxs != null) { if (source.IsClosed && (targetInxs.Count > 0)) { targetInxs[0] = targetInxs[targetInxs.Count - 1]; } } }