/// <summary> /// Create Brep /// </summary> protected Brep CreateBrep(List <Point3d> points, double height, double tolerance) { if (points.Count < 4 || height <= 0.0) { return(null); } // Create the profile curve var profile = new PolylineCurve(points); if (!profile.IsClosed || !profile.IsPlanar(tolerance)) { return(null); } // Create a surface by extruding the profile curve var surface = Surface.CreateExtrusion(profile, new Vector3d(0.0, 0.0, height)); if (null == surface) { return(null); } // Create a Brep from the surface var brep = surface.ToBrep(); // The profile curve is a degree=1 curve. Thus, the extruded surface will // have kinks. Because kinked surface can cause problems down stream, Rhino // always splits kinked surfaces when adding Breps to the document. Since // we are not adding this Brep to the document, lets split the kinked // surfaces ourself. brep.Faces.SplitKinkyFaces(RhinoMath.DefaultAngleTolerance, true); // Cap any planar holes var capped_brep = brep.CapPlanarHoles(tolerance); if (null == capped_brep) { return(null); } // The profile curve, created by the input points, is oriented clockwise. // Thus when the profile is extruded, the resulting surface will have its // normals pointed inwards. So lets check the orientation and, if inwards, // flip the face normals. if (BrepSolidOrientation.Inward == capped_brep.SolidOrientation) { capped_brep.Flip(); } string log; if (!capped_brep.IsValidWithLog(out log)) { RhinoApp.WriteLine(log); return(null); } return(capped_brep); }
/// <summary> /// Verifies a PolylineCurve is a rectangle /// </summary> public static bool IsRectangle(PolylineCurve curve) { // Curve should be a valid, closed, planar polyline curve with 5 points if (curve == null || !curve.IsValid || !curve.IsClosed || !curve.IsPlanar() || curve.PointCount != 5) { return(false); } // Angle between each segment should be 90 degrees const double angle = 90.0 * (Math.PI / 180.0); for (var i = 1; i < curve.PointCount - 1; i++) { var p0 = curve.Point(i - 1); var p1 = curve.Point(i); var p2 = curve.Point(i + 1); var v0 = p1 - p0; v0.Unitize(); var v1 = p1 - p2; v1.Unitize(); var a = Vector3d.VectorAngle(v0, v1); if (Math.Abs(angle - a) >= RhinoMath.DefaultAngleTolerance) { return(false); } } return(true); }