/// <summary> /// Create Edge (Line) from Rhino LineCurve. /// </summary> public static Geometry.Edge FromRhinoLineCurve(this Rhino.Geometry.LineCurve obj) { FdPoint3d startPoint = obj.PointAtStart.FromRhino(); FdPoint3d endPoint = obj.PointAtEnd.FromRhino(); // lcs FdCoordinateSystem cs = obj.FromRhinoCurve(); // return return(new Geometry.Edge(startPoint, endPoint, cs)); }
/// <summary> /// Intersects a curve and an infinite line. /// </summary> /// <param name="curve">Curve to intersect.</param> /// <param name="line">Infinite line to intesect.</param> /// <param name="tolerance">If the distance from a point on curve to line /// is <= tolerance, then the point will be part of an intersection /// event. If the tolerance <= 0.0, then 0.001 is used.</param> /// <param name="overlapTolerance">If t1 and t2 are parameters of curve's /// intersection events and the distance from curve(t) to line is <= /// overlapTolerance for every t1 <= t <= t2, then the event will /// be returened as an overlap event. If overlapTolerance <= 0.0, /// then tolerance * 2.0 is used.</param> /// <returns>A collection of intersection events.</returns> public static Rhino.Geometry.Intersect.CurveIntersections IntersectCurveLine( Rhino.Geometry.Curve curve, Rhino.Geometry.Line line, double tolerance, double overlapTolerance ) { if (!curve.IsValid || !line.IsValid || line.Length < Rhino.RhinoMath.SqrtEpsilon) { return(null); } // Extend the line through the curve's bounding box var bbox = curve.GetBoundingBox(false); if (!bbox.IsValid) { return(null); } var dir = line.Direction; dir.Unitize(); var points = bbox.GetCorners(); var plane = new Rhino.Geometry.Plane(line.From, dir); double max_dist; var min_dist = max_dist = plane.DistanceTo(points[0]); for (var i = 1; i < points.Length; i++) { var dist = plane.DistanceTo(points[i]); if (dist < min_dist) { min_dist = dist; } if (dist > max_dist) { max_dist = dist; } } // +- 1.0 makes the line a little bigger than the bounding box line.From = line.From + dir * (min_dist - 1.0); line.To = line.From + dir * (max_dist + 1.0); // Calculate curve-curve intersection var line_curve = new Rhino.Geometry.LineCurve(line); return(Rhino.Geometry.Intersect.Intersection.CurveCurve(curve, line_curve, tolerance, overlapTolerance)); }
private static Rhino.Geometry.NurbsCurve GetSpirial1() { var railStart = new Rhino.Geometry.Point3d(0, 0, 0); var railEnd = new Rhino.Geometry.Point3d(0, 0, 10); var railCurve = new Rhino.Geometry.LineCurve(railStart, railEnd); double t0 = railCurve.Domain.Min; double t1 = railCurve.Domain.Max; var radiusPoint = new Rhino.Geometry.Point3d(1, 0, 0); return(Rhino.Geometry.NurbsCurve.CreateSpiral(railCurve, t0, t1, radiusPoint, 1, 10, 1.0, 1.0, 12)); }
/// <summary> /// Create Edge (Line or Arc2) from Rhino LineCurve or open ArcCurve. /// Used for bar definition. /// </summary> public static Geometry.Edge FromRhinoLineOrArc2(this Rhino.Geometry.Curve obj) { // check length if (obj.GetLength() < FemDesign.Tolerance.Point3d) { throw new System.ArgumentException("Curve has no length."); } // if ArcCurve if (obj.GetType() == typeof(Rhino.Geometry.ArcCurve)) { Rhino.Geometry.ArcCurve arcCurve = (Rhino.Geometry.ArcCurve)obj; // if Arc if (!obj.IsClosed) { return(arcCurve.FromRhinoArc2()); } else { throw new System.ArgumentException($"Curve type: {obj.GetType()}, is not Line or Arc."); } } // if LineCurve else if (obj.GetType() == typeof(Rhino.Geometry.LineCurve)) { return(((Rhino.Geometry.LineCurve)obj).FromRhinoLineCurve()); } // if PolylineCurve else if (obj.GetType() == typeof(Rhino.Geometry.PolylineCurve)) { if (obj.SpanCount == 1) { Rhino.Geometry.LineCurve lnCrv = new Rhino.Geometry.LineCurve(obj.PointAtStart, obj.PointAtEnd); return(lnCrv.FromRhinoLineCurve()); } else { throw new System.ArgumentException($"PolylineCurve with SpanCount: {obj.SpanCount}, is not supported for conversion to an Edge."); } } else { throw new System.ArgumentException($"Curve type: {obj.GetType()}, is not Line or Arc."); } }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { Rhino.Geometry.Line line; Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetLine(out line); if (rc == Rhino.Commands.Result.Success) { Rhino.Geometry.LineCurve crv = new Rhino.Geometry.LineCurve(line); SampleCsCustomLineObject obj = new SampleCsCustomLineObject(); doc.Objects.AddRhinoObject(obj, crv); doc.Views.Redraw(); } return(Rhino.Commands.Result.Success); }
public static Line FromRhino(Rhino.Geometry.LineCurve rhinoLine) { if (rhinoLine == null) { throw new ArgumentNullException(); } var line = new Line { StartPoint = PointInterop.FromRhino(rhinoLine.PointAtStart), EndPoint = PointInterop.FromRhino(rhinoLine.PointAtEnd) }; return(line); }
private void ExtractGeometry(Grasshopper.Kernel.Types.IGH_Goo iGoo, ref List <Rhino.Geometry.GeometryBase> resGeom) { if (iGoo is Grasshopper.Kernel.Types.GH_GeometryGroup group) { foreach (var geomGoo in group.Objects) { ExtractGeometry(geomGoo, ref resGeom); } return; } Rhino.Geometry.GeometryBase geometryBase = null; try { switch (iGoo.ScriptVariable()) { case Rhino.Geometry.Point3d point: geometryBase = new Rhino.Geometry.Point(point); break; case Rhino.Geometry.Line line: geometryBase = new Rhino.Geometry.LineCurve(line); break; case Rhino.Geometry.Rectangle3d rect: geometryBase = rect.ToNurbsCurve(); break; case Rhino.Geometry.Arc arc: geometryBase = new Rhino.Geometry.ArcCurve(arc); break; case Rhino.Geometry.Circle circle: geometryBase = new Rhino.Geometry.ArcCurve(circle); break; case Rhino.Geometry.Ellipse ellipse: geometryBase = ellipse.ToNurbsCurve(); break; case Rhino.Geometry.Curve curve: geometryBase = curve; break; case Rhino.Geometry.Box box: geometryBase = Rhino.Geometry.Mesh.CreateFromBox(box, 1, 1, 1); break; case Rhino.Geometry.Mesh mesh: geometryBase = mesh; break; case Rhino.Geometry.Brep brep: { if (!CompoundDrawable.IsRenderMode) { foreach (var crv in brep.GetWireframe(-1)) { resGeom.Add(crv); } } else { var previewMesh = new Rhino.Geometry.Mesh(); previewMesh.Append(Rhino.Geometry.Mesh.CreateFromBrep(brep, MeshParameters)); geometryBase = previewMesh; } break; } case Rhino.Geometry.Plane plane: { double len = 4.0; var x = new Rhino.Geometry.Interval(-len, len); var y = new Rhino.Geometry.Interval(-len, len); geometryBase = Rhino.Geometry.Mesh.CreateFromPlane(plane, x, y, 5, 5); break; } default: { System.Diagnostics.Debug.Fail("Not supported GH type", iGoo.GetType().ToString()); break; } } } catch (Exception e) { System.Diagnostics.Debug.Fail(e.Source, e.Message); } if (geometryBase != null) { resGeom.Add(geometryBase); } }
public SampleCsCustomLineObject(Rhino.Geometry.LineCurve crv) : base(crv) { }