public void GetLengthCircle() { // circle var center = new FdPoint3d(0, 0, 0); var radius = 1; var cs = FdCoordinateSystem.Global(); var circle = new Edge(radius, center, cs); Assert.IsTrue(Math.Abs(circle.Length - 2 * Math.PI) <= Tolerance.LengthComparison); }
/// <summary> /// Create Edge (Line) from Rhino linear NurbsCurve. /// </summary> public static Geometry.Edge FromRhinoLinearNurbsCurve(this Rhino.Geometry.NurbsCurve 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> /// Create Edge (Circle) from Rhino closed ArcCurve. /// </summary> public static Geometry.Edge FromRhinoCircle(this Rhino.Geometry.ArcCurve obj) { double radius = obj.Radius; FdPoint3d centerPoint = obj.Arc.Center.FromRhino(); // lcs FdCoordinateSystem cs = obj.FromRhinoCurve(); // return return(new Geometry.Edge(radius, centerPoint, cs)); }
/// <summary> /// Create Edge (Arc2) from Rhino open ArcCurve. /// </summary> public static Geometry.Edge FromRhinoArc2(this Rhino.Geometry.ArcCurve obj) { FdPoint3d startPoint = obj.Arc.StartPoint.FromRhino(); FdPoint3d midPoint = obj.Arc.MidPoint.FromRhino(); FdPoint3d endPoint = obj.Arc.EndPoint.FromRhino(); // lcs FdCoordinateSystem cs = obj.FromRhinoCurve(); // return return(new Geometry.Edge(startPoint, midPoint, endPoint, cs)); }
public void GetLengthArc3Point() { // arc by three points var start = new FdPoint3d(-1, 0, 0); var mid = new FdPoint3d(0, 1, 0); var end = new FdPoint3d(1, 0, 0); var cs = FdCoordinateSystem.Global(); var arc2 = new Edge(start, mid, end, cs); //Assert.ThrowsException<ArgumentException>(() => arc2.Length, "Should throw exception stating that method to calculate sweep angle is not implemented yet."); Assert.IsTrue(Math.Abs(arc2.Length - Math.PI) <= Tolerance.LengthComparison); // test should fail here }
public void GetLengthArc() { // arc by var center = new FdPoint3d(0, 0, 0); var radius = 1; var startAngle = 0; var endAngle = Math.PI; var xAxis = new FdVector3d(1, 0, 0); var cs = FdCoordinateSystem.Global(); var arc1 = new Edge(radius, startAngle, endAngle, center, xAxis, cs); Assert.IsTrue(Math.Abs(arc1.Length - Math.PI) <= Tolerance.LengthComparison); }
/// <summary> /// Create Edge (Arc1) from Rhino open ArcCurve. /// </summary> public static Geometry.Edge FromRhinoArc1(this Rhino.Geometry.ArcCurve obj) { double radius = obj.Arc.Radius; double startAngle = 0; double endAngle = obj.Arc.EndAngle - obj.Arc.StartAngle; FdPoint3d centerPoint = obj.Arc.Center.FromRhino(); FdVector3d xAxis = new FdVector3d(centerPoint, obj.Arc.StartPoint.FromRhino()); // lcs FdCoordinateSystem cs = obj.FromRhinoCurve(); // return return(new Geometry.Edge(radius, startAngle, endAngle, centerPoint, xAxis, cs)); }
/// <summary> /// Create Region from Rhino brep. /// </summary> public static Geometry.Region FromRhino(this Rhino.Geometry.Brep obj) { // check if brep contains more than 1 surface if (obj.Surfaces.Count != 1) { throw new System.ArgumentException("Brep contains more than 1 surface."); } // check if brep surface is planar if (!obj.Surfaces[0].IsPlanar()) { throw new System.ArgumentException("Brep surface is not planar. This problem might occur due to tolerance error - if your model space is in millimeters try to change to meters."); } // get outline curves var container = new List <List <Rhino.Geometry.Curve> >(); var loopCurves = new List <Rhino.Geometry.Curve>(); foreach (Rhino.Geometry.BrepLoop loop in obj.Loops) { foreach (Rhino.Geometry.BrepTrim trim in loop.Trims) { loopCurves.Add(trim.Edge.EdgeCurve); } container.Add(new List <Rhino.Geometry.Curve>(loopCurves)); loopCurves.Clear(); } // Change direction of EdgeCurves if necessary. // Circular Edge in Contour (id est the only Edge in that Contour) should have a normal in the opposite direction from any other type of Contour in Region (id est the direction of the Contour should be opposite). // EndPoint of EdgeCurve[idx] should be equal to StartPoint of EdgeCurve[idx + 1] in a Contour. foreach (List <Rhino.Geometry.Curve> items in container) { // if Contour consists of one curve if (items.Count == 1) { // check if curve is a Circle Rhino.Geometry.Curve curve = items[0]; if (curve.IsArc() && curve.IsClosed) { // check if Circle is planar if (curve.IsPlanar()) { curve.TryGetPlane(out Rhino.Geometry.Plane plane); // compare Contour and Surface normals if (obj.Surfaces[0].NormalAt(0, 0).IsParallelTo(plane.Normal, Tolerance.Point3d) == 1) { // reverse direction of Circle curve.Reverse(); } } else { throw new System.ArgumentException("Curve is not planar"); } } // if curve for some reason is not a Circle else { // if the curve can not be represented by a circle then direction is irrelevant. // pass } } // if Contour consists of more than one curve (i.e. is not a Circle) else { Rhino.Geometry.Point3d pA0, pA1, pB0, pB1; for (int idx = 0; idx < items.Count - 1; idx++) { // curve a = items[idx] // curve b = items[idx + 1] pA0 = items[idx].PointAtStart; pA1 = items[idx].PointAtEnd; pB0 = items[idx + 1].PointAtStart; pB1 = items[idx + 1].PointAtEnd; if (pA0.EpsilonEquals(pB0, Tolerance.Point3d)) { if (idx == 0) { items[idx].Reverse(); } else { throw new System.ArgumentException("pA0 == pB0 even though idx != 0. Bad outline."); } } else if (pA0.EpsilonEquals(pB1, Tolerance.Point3d)) { if (idx == 0) { items[idx].Reverse(); items[idx + 1].Reverse(); } else { throw new System.ArgumentException("pA0 == pB1 even though idx != 0. Bad outline."); } } else if (pA1.EpsilonEquals(pB0, Tolerance.Point3d)) { // pass } else if (pA1.EpsilonEquals(pB1, Tolerance.Point3d)) { items[idx + 1].Reverse(); } else { throw new System.ArgumentException("Can't close outline. Bad outline."); } } // check if outline is closed. pA1 = items[items.Count - 1].PointAtEnd; pB0 = items[0].PointAtStart; if (pA1.EpsilonEquals(pB0, Tolerance.Point3d)) { } else { throw new System.ArgumentException("Can't close outline. Bad outline."); } } } // Create contours List <Geometry.Edge> edges = new List <Geometry.Edge>(); List <Geometry.Contour> contours = new List <Geometry.Contour>(); foreach (List <Rhino.Geometry.Curve> items in container) { foreach (Rhino.Geometry.Curve curve in items) { foreach (Geometry.Edge edge in curve.FromRhinoBrep()) { edges.Add(edge); } } contours.Add(new Geometry.Contour(new List <Edge>(edges))); edges.Clear(); } // Get LCS FdCoordinateSystem cs = obj.Surfaces[0].FromRhinoSurface(); // return return(new Geometry.Region(contours, cs)); }