using Rhino.Geometry; using System; using System.Collections.Generic; public class PolylinePopulate { private double maxY, minY; private double maxX, minX; private Curve _tempBoundry; public PolylinePopulate(Polyline polyLine) { _tempBoundry = polyLine.ToNurbsCurve(); maxX = minX = polyLine[0].X; maxY = minY = polyLine[0].Y; foreach(Point3d point in polyLine) { if (point.X < minX) minX = point.X; if (point.X > maxX) maxX = point.X; if (point.Y < minY) minY = point.Y; if (point.Y > maxY) maxY = point.Y; } } public PolylinePopulate(Curve closedCurve) { _tempBoundry = closedCurve; Polyline polyLine = closedCurve.ToPolyline(0.01f, 0, 1, 5).ToPolyline(); maxX = minX = polyLine[0].X; maxY = minY = polyLine[0].Y; foreach(Point3d point in polyLine) { if (point.X < minX) minX = point.X; if (point.X > maxX) maxX = point.X; if (point.Y < minY) minY = point.Y; if (point.Y > maxY) maxY = point.Y; } } public List populatePoints(int pointCount) { List resultPoint3DList = new List(); List tempPoint3DList = new List(); double width,height; width = -1 * (minX - maxX); height = -1 * (minY - maxY); if (width < 0) width *= width * -1; if (height < 0) height *= height * -1; for(double x = minX; x < maxX; x += width/pointCount/2) { for (double y = minY; y < maxY; y += height / pointCount / 2) { if (_tempBoundry.Contains(new Point3d(x, y, 0)) == PointContainment.Inside) { tempPoint3DList.Add(new Point3d(x, y, 0)); } } } for(int i = 0; i < pointCount; i++) { int randomPointNumber = new Random().Next(0, tempPoint3DList.Count); resultPoint3DList.Add(tempPoint3DList[randomPointNumber]); tempPoint3DList.RemoveAt(randomPointNumber); } return resultPoint3DList; } private double Math(double v) { throw new NotImplementedException(); } }