/// <summary> /// Gets the intersection of a plane at the specified height as a list of contours (i.e a list of 2D polygons). /// </summary> /// <param name="elevation">The elevation.</param> /// <returns>List<BarrierPolygons>.</returns> public List <BarrierPolygon> GetIntersection(double elevation) { var edges = new List <UVLine>(); foreach (var item in this._faces) { if (item.Intersects(elevation)) { var edge = item.GetIntersection(elevation); UV p1 = new UV(edge.Start.X, edge.Start.Y); UV p2 = new UV(edge.End.X, edge.End.Y); edges.Add(new UVLine(p1, p2)); } } var plines = PLine.ExtractPLines(edges); List <BarrierPolygon> boundary = new List <BarrierPolygon>(); foreach (PLine item in plines) { var oneBoundary = item.Simplify(0.001d, 0.0001d); if (oneBoundary != null) { var polygon = new BarrierPolygon(oneBoundary.ToArray()) { IsClosed = item.Closed }; boundary.Add(polygon); } } return(boundary); }
public PLine AddPLine() { var pline = new PLine { Id = PLines.Count + 1 }; PLines.Add(pline); return(pline); }
static void Main(string[] args) { PSystem system = new PSystem() { new FixedObject(new Vector2(5, 0), 1e+6f), new FixedObject(new Vector2(-5, 0), 1e+6f) }; var f = PLine.ElectricFieldLine(system, new Vector2(5, 6), 6 * (int)6e3 + 1).ToArray(); for (int i = 0; i <= 100; ++i) { Console.WriteLine(f[i * 50]); } }
/// <summary> /// Gets the field boundary polygons. /// </summary> /// <param name="cellularFloor">The cellular floor.</param> /// <returns>List<BarrierPolygons>.</returns> public static List <BarrierPolygon> GetFieldBoundary(CellularFloor cellularFloor) { Dictionary <UVLine, int> guid = new Dictionary <UVLine, int>(); foreach (var item in cellularFloor.Cells) { if (item.FieldOverlapState == OverlapState.Inside) { var lines = cellularFloor.CellToLines(item); foreach (var line in lines) { if (guid.ContainsKey(line)) { guid[line]++; } else { guid.Add(line, 1); } } } } List <UVLine> boundaryLines = new List <UVLine>(); foreach (KeyValuePair <UVLine, int> item in guid) { if (item.Value == 1) { boundaryLines.Add(item.Key); } } guid.Clear(); guid = null; var pLines = PLine.ExtractPLines(boundaryLines); List <BarrierPolygon> boundary = new List <BarrierPolygon>(); foreach (PLine item in pLines) { var oneBoundary = item.Simplify(cellularFloor.CellSize / 10); if (oneBoundary != null) { boundary.Add(new BarrierPolygon(oneBoundary.ToArray())); } } boundaryLines.Clear(); boundaryLines = null; return(boundary); }
/// <summary> /// Gets the boundary polygons of a collection of cells. /// </summary> /// <param name="cellIDs">The visible cells.</param> /// <param name="cellularFloor">The cellular floor.</param> /// <returns>List<BarrierPolygons>.</returns> public static List <BarrierPolygon> GetBoundary(ICollection <int> cellIDs, CellularFloorBaseGeometry cellularFloor) { Dictionary <UVLine, int> guid = new Dictionary <UVLine, int>(); foreach (var item in cellIDs) { var lines = cellularFloor.CellToLines(cellularFloor.FindCell(item)); foreach (var line in lines) { if (guid.ContainsKey(line)) { guid[line]++; } else { guid.Add(line, 1); } } } List <UVLine> boundaryLines = new List <UVLine>(); foreach (KeyValuePair <UVLine, int> item in guid) { if (item.Value == 1) { boundaryLines.Add(item.Key); } } guid.Clear(); guid = null; var plines = PLine.ExtractPLines(boundaryLines); List <BarrierPolygon> boundary = new List <BarrierPolygon>(); foreach (PLine item in plines) { var oneBoundary = item.Simplify(cellularFloor.CellSize / 10); if (oneBoundary != null) { boundary.Add(new BarrierPolygon(oneBoundary.ToArray())); } } boundaryLines.Clear(); boundaryLines = null; return(boundary); }
public void addContour(List <PLine> plines, double elevation) { for (int i = 0; i < plines.Count; i++) { CContour cc = new CContour(); cc.elevation = elevation; PLine pl = plines[i]; cc.isClosed = pl.IsClosed; cc.pline = pl; if (!cc.isClosed) { cc.StartP = MyConvert.toCPoint(pl.GetVertices()[0]); cc.StartP.elevation = elevation; cc.endP = MyConvert.toCPoint(pl.GetVertices()[pl.GetVertices().Count - 1]); cc.endP.elevation = elevation; } ccontours.Add(cc); } }
private async void DrawElectricLines(bool quick) { if (!_pObjs.Any((p) => p.PObject.Charge != 0f)) { _lines.Clear(); return; } _renderCount += 1; int currentRender = _renderCount; var tasklist = new List <Task <List <System.Numerics.Vector2> > >(); var extracted = _pObjs.Extracted(); foreach (var obj in _pObjs) { int units = (int)Math.Round(obj.PObject.Charge / UnitCharge); for (int i = 0; i < units * LinePerUnitCharge; ++i) { double angle = 2 * i * Math.PI / (units * LinePerUnitCharge); // relative displacement with respect to the position of the charge System.Numerics.Vector2 delta = new System.Numerics.Vector2( (float)Math.Cos(angle), (float)Math.Sin(angle)) * RPhysicalObject.Radius / Scale; // create new task that calculates an electric field line from the specified starting point Task <List <System.Numerics.Vector2> > task = null; if (quick) { task = PLine.ElectricFieldLineFastAsync( system: extracted, // list of physical objects initPos: obj.PObject.Position + delta, // starting point of the line endFunc: (t, v) // ending function (calculation stops if true) => t > MaxT || !(-Window.Width / Scale < v.X && v.X < Window.Width / Scale && -Window.Height / Scale < v.Y && v.Y < Window.Height / Scale), startFromNegative: false, // is starting from negative charge delta: 1e-3f); } else { task = PLine.ElectricFieldLineAsync( system: extracted, // list of physical objects initPos: obj.PObject.Position + delta, // starting point of the line endFunc: (t, v) // ending function (calculation stops if true) => t > MaxT || !(-Window.Width / Scale < v.X && v.X < Window.Width / Scale && -Window.Height / Scale < v.Y && v.Y < Window.Height / Scale), startFromNegative: false, // is starting from negative charge delta: 1e-3f); } tasklist.Add(task); } } // wait for all tasks to complete var newL = new List <List <System.Numerics.Vector2> >(); await Task.WhenAll(tasklist); foreach (var task in tasklist) { var res = await task; newL.Add(res); } // if another render has started, then stash current results if (_renderCount != currentRender) { return; } // wait for OnRender finished and then replace while (_rendering) { } _lines = newL; }
/// <summary> /// Get Grevit Curve Component /// </summary> /// <param name="curve"></param> /// <param name="referenceID"></param> /// <returns></returns> public static Component ToGrevitCurve(this Rhino.Geometry.Curve curve, string referenceID = "") { if (curve.IsArc(Rhino.RhinoMath.ZeroTolerance)) { Rhino.Geometry.Arc a; if (curve.TryGetArc(out a)) { Curve3Points arc = new Curve3Points(); arc.a = curve.PointAtStart.ToGrevitPoint(); arc.b = curve.PointAt(0.5).ToGrevitPoint(); arc.c = curve.PointAtEnd.ToGrevitPoint(); arc.GID = referenceID; return(arc); } } else if (curve.IsPolyline()) { Rhino.Geometry.Polyline pline; if (curve.TryGetPolyline(out pline)) { PLine arc = new PLine(); arc.points = new List <Grevit.Types.Point>(); foreach (Rhino.Geometry.Point3d pkt in pline) { arc.points.Add(pkt.ToGrevitPoint()); } arc.closed = pline.IsClosed; arc.GID = referenceID; return(arc); } } else if (curve.IsEllipse()) { Curve3Points arc = new Curve3Points(); arc.a = curve.PointAtStart.ToGrevitPoint(); arc.b = curve.PointAt(0.5).ToGrevitPoint(); arc.c = curve.PointAtEnd.ToGrevitPoint(); arc.GID = referenceID; return(arc); } else if (curve.GetType() == typeof(Rhino.Geometry.NurbsCurve)) { Rhino.Geometry.NurbsCurve nc = (Rhino.Geometry.NurbsCurve)curve; Grevit.Types.Spline spline = new Grevit.Types.Spline(); spline.controlPoints = new List <Grevit.Types.Point>(); spline.weights = new List <double>(); foreach (Rhino.Geometry.ControlPoint p in nc.Points) { spline.controlPoints.Add(p.Location.ToGrevitPoint()); spline.weights.Add(p.Weight); } spline.degree = nc.Degree; spline.isClosed = nc.IsClosed; spline.isRational = nc.IsRational; spline.isPeriodic = nc.IsPeriodic; spline.GID = referenceID; spline.knots = new List <double>(); foreach (double dbl in nc.Knots) { spline.knots.Add(dbl); } return(spline); } else { Line arc = new Line(); arc.from = curve.PointAtStart.ToGrevitPoint(); arc.to = curve.PointAtEnd.ToGrevitPoint(); arc.GID = referenceID; return(arc); } return(null); }
/// <summary> /// Simplifies the polygon. /// </summary> /// <param name="uvs">A list of uv points.</param> /// <param name="proportionOfMinimumLengthOfLine">The proportion of minimum length of line parameter by default set to 3.</param> /// <param name="angle">The angle by default set to zero.</param> /// <returns>List<UV>.</returns> public List <UV> SimplifyPolygon(List <UV> uvs, UInt16 proportionOfMinimumLengthOfLine = 3, double angle = 0.0d) { SpatialAnalysis.Geometry.PLine pln = new PLine(uvs, true); return(pln.Simplify(this.MinimumLengthOfLine / proportionOfMinimumLengthOfLine)); }
public LineGeometry() { baseGeometry = new PLine(); }
public StrictRuler(PLine v) { vija = v; }