示例#1
0
        static RevSurface FromCylindricalSurface(DB.XYZ origin, DB.XYZ xDir, DB.XYZ yDir, DB.XYZ zDir, double radius, DB.BoundingBoxUV bboxUV, double relativeTolerance)
        {
            var atol = relativeTolerance * Revit.AngleTolerance;
            var ctol = relativeTolerance * Revit.ShortCurveTolerance;
            var uu   = new Interval(bboxUV.Min.U - atol, bboxUV.Max.U + atol);
            var vv   = new Interval(bboxUV.Min.V - ctol, bboxUV.Max.V + ctol);

            var plane = new Plane
                        (
                AsPoint3d(origin),
                AsVector3d(xDir),
                AsVector3d(yDir)
                        );
            var axisDir = AsVector3d(zDir);

            var curve = new LineCurve
                        (
                new Line
                (
                    plane.Origin + (radius * plane.XAxis) + (vv.Min * axisDir),
                    plane.Origin + (radius * plane.XAxis) + (vv.Max * axisDir)
                ),
                vv.Min,
                vv.Max
                        );

            var axis = new Line(plane.Origin, plane.Normal);

            return(RevSurface.Create(curve, axis, uu.Min, uu.Max));
        }
示例#2
0
        static RevSurface FromConicalSurface(DB.XYZ origin, DB.XYZ xDir, DB.XYZ yDir, DB.XYZ zDir, double halfAngle, DB.BoundingBoxUV bboxUV)
        {
            var ctol = Revit.ShortCurveTolerance;
            var atol = Revit.AngleTolerance * 10.0;
            var uu   = new Interval(bboxUV.Min.U - atol, bboxUV.Max.U + atol);
            var vv   = new Interval(bboxUV.Min.V - ctol, bboxUV.Max.V + ctol);

            var o = origin.ToRhino();
            var x = (Vector3d)xDir.Normalize().ToRhino();
            var z = (Vector3d)zDir.Normalize().ToRhino();

            var axis = new Line(o, o + z);

            var dir = z + x * Math.Tan(halfAngle);

            dir.Unitize();

            var curve = new LineCurve
                        (
                new Line
                (
                    o + (dir * vv.Min),
                    o + (dir * vv.Max)
                ),
                vv.Min,
                vv.Max
                        );

            return(RevSurface.Create(curve, axis, uu.Min, uu.Max));
        }
示例#3
0
        static RevSurface FromCylindricalSurface(DB.XYZ origin, DB.XYZ xDir, DB.XYZ yDir, DB.XYZ zDir, double radius, DB.BoundingBoxUV bboxUV)
        {
            var ctol = Revit.ShortCurveTolerance;
            var atol = Revit.AngleTolerance;
            var uu   = new Interval(bboxUV.Min.U - atol, bboxUV.Max.U + atol);
            var vv   = new Interval(bboxUV.Min.V - ctol, bboxUV.Max.V + ctol);

            var o = origin.ToRhino();
            var x = (Vector3d)xDir.Normalize().ToRhino();
            var z = (Vector3d)zDir.Normalize().ToRhino();

            var axis  = new Line(o, o + z);
            var curve = new LineCurve
                        (
                new Line
                (
                    o + (x * radius) + (z * vv.Min),
                    o + (x * radius) + (z * vv.Max)
                ),
                vv.Min,
                vv.Max
                        );

            return(RevSurface.Create(curve, axis, uu.Min, uu.Max));
        }
示例#4
0
        public static RevSurface ToRhino(this DB.CylindricalSurface surface, DB.BoundingBoxUV bboxUV)
        {
            var ctol = Revit.ShortCurveTolerance;
            var atol = Revit.AngleTolerance;
            var uu   = new Interval(bboxUV.Min.U - atol, bboxUV.Max.U + atol);
            var vv   = new Interval(bboxUV.Min.V - ctol, bboxUV.Max.V + ctol);

            var origin = surface.Origin.ToRhino();
            var xdir   = (Vector3d)surface.XDir.ToRhino();
            var zdir   = (Vector3d)surface.Axis.ToRhino();

            var axis  = new Line(origin, origin + zdir);
            var curve = new LineCurve
                        (
                new Line
                (
                    origin + (xdir * surface.Radius) + (zdir * vv.Min),
                    origin + (xdir * surface.Radius) + (zdir * vv.Max)
                ),
                vv.Min,
                vv.Max
                        );

            return(RevSurface.Create(curve, axis, uu.Min, uu.Max));
        }
示例#5
0
        public static RevSurface ToRhino(this DB.ConicalSurface surface, DB.BoundingBoxUV bboxUV)
        {
            var ctol = Revit.ShortCurveTolerance;
            var atol = Revit.AngleTolerance * 10.0;
            var uu   = new Interval(bboxUV.Min.U - atol, bboxUV.Max.U + atol);
            var vv   = new Interval(bboxUV.Min.V - ctol, bboxUV.Max.V + ctol);

            var origin = surface.Origin.ToRhino();
            var xdir   = (Vector3d)surface.XDir.ToRhino();
            var zdir   = (Vector3d)surface.Axis.ToRhino();

            var axis = new Line(origin, origin + zdir);

            var dir = zdir + xdir * Math.Tan(surface.HalfAngle);

            dir.Unitize();

            var curve = new LineCurve
                        (
                new Line
                (
                    surface.Origin.ToRhino() + (dir * vv.Min),
                    surface.Origin.ToRhino() + (dir * vv.Max)
                ),
                vv.Min,
                vv.Max
                        );

            return(RevSurface.Create(curve, axis, uu.Min, uu.Max));
        }
示例#6
0
        static RevSurface FromRevolvedSurface(DB.XYZ origin, DB.XYZ xDir, DB.XYZ yDir, DB.XYZ zDir, DB.Curve curve, DB.BoundingBoxUV bboxUV, double relativeTolerance)
        {
            var atol = relativeTolerance * Revit.AngleTolerance;
            var ctol = relativeTolerance * Revit.ShortCurveTolerance;
            var uu   = new Interval(bboxUV.Min.U - atol, bboxUV.Max.U + atol);

            var plane = new Plane
                        (
                AsPoint3d(origin),
                AsVector3d(xDir),
                AsVector3d(yDir)
                        );
            var axisDir = AsVector3d(zDir);

            using (var ECStoWCS = new DB.Transform(DB.Transform.Identity)
            {
                Origin = origin, BasisX = xDir.Normalize(), BasisY = yDir.Normalize(), BasisZ = zDir.Normalize()
            })
            {
                var c = ToRhino(curve.CreateTransformed(ECStoWCS));
                c = ctol == 0.0 ? c : c.Extend(CurveEnd.Both, ctol, CurveExtensionStyle.Smooth);

                var axis = new Line(plane.Origin, plane.Normal);
                return(RevSurface.Create(c, axis, uu.Min, uu.Max));
            }
        }
示例#7
0
        static RevSurface FromConicalSurface(DB.XYZ origin, DB.XYZ xDir, DB.XYZ yDir, DB.XYZ zDir, double halfAngle, DB.BoundingBoxUV bboxUV, double relativeTolerance)
        {
            var atol = relativeTolerance * Revit.AngleTolerance * 10.0;
            var ctol = relativeTolerance * Revit.ShortCurveTolerance;
            var uu   = new Interval(bboxUV.Min.U - atol, bboxUV.Max.U + atol);
            var vv   = new Interval(bboxUV.Min.V - ctol, bboxUV.Max.V + ctol);

            var plane = new Plane
                        (
                AsPoint3d(origin),
                AsVector3d(xDir),
                AsVector3d(yDir)
                        );
            var axisDir = AsVector3d(zDir);

            var dir = axisDir + Math.Tan(halfAngle) * plane.XAxis;

            dir.Unitize();

            var curve = new LineCurve
                        (
                new Line
                (
                    plane.Origin + (vv.Min * dir),
                    plane.Origin + (vv.Max * dir)
                ),
                vv.Min,
                vv.Max
                        );

            var axis = new Line(plane.Origin, plane.Normal);

            return(RevSurface.Create(curve, axis, uu.Min, uu.Max));
        }
示例#8
0
        private Topologic.Face BySurface(Rhino.Geometry.Surface ghSurface)
        {
            SumSurface ghSumSurface = ghSurface as SumSurface;

            if (ghSumSurface != null)
            {
                return(BySumSurface(ghSumSurface));
            }

            RevSurface ghRevSurface = ghSurface as RevSurface;

            if (ghRevSurface != null)
            {
                return(ByRevSurface(ghRevSurface));
            }

            PlaneSurface ghPlaneSurface = ghSurface as PlaneSurface;

            if (ghPlaneSurface != null)
            {
                return(ByPlaneSurface(ghPlaneSurface));
            }

            //ClippingPlaneSurface ghClippingPlaneSurface = ghSurface as ClippingPlaneSurface;
            //if (ghClippingPlaneSurface != null)
            //{
            //    return ByClippingPlaneSurface(ghClippingPlaneSurface);
            //}

            Extrusion ghExtrusion = ghSurface as Extrusion;

            if (ghExtrusion != null)
            {
                return(ByExtrusion(ghExtrusion));
            }

            Rhino.Geometry.NurbsSurface ghNurbsSurface = ghSurface as Rhino.Geometry.NurbsSurface;
            if (ghNurbsSurface != null)
            {
                return(ByNurbsSurface(ghNurbsSurface));
            }

            //BrepFace ghBrepFace = ghSurface as BrepFace;
            //if (ghBrepFace != null)
            //{
            //    return ByBrepFace(ghBrepFace);
            //}

            throw new Exception("This type of surface is not yet supported.");
        }
示例#9
0
        public static RevSurface ToRhino(this DB.RevolvedSurface surface, DB.BoundingBoxUV bboxUV)
        {
            var ctol = Revit.ShortCurveTolerance;
            var atol = Revit.AngleTolerance;
            var uu   = new Interval(bboxUV.Min.U - atol, bboxUV.Max.U + atol);

            var axis = new Line
                       (
                surface.Origin.ToRhino(),
                surface.Origin.ToRhino() + (Vector3d)surface.Axis.ToRhino()
                       );

            var curve = surface.GetProfileCurveInWorldCoordinates().ToRhino();

            curve = curve.Extend(CurveEnd.Both, ctol, CurveExtensionStyle.Line);

            return(RevSurface.Create(curve, axis, uu.Min, uu.Max));
        }
示例#10
0
        public static global::Topologic.Face ToTopologic(this global::Rhino.Geometry.Surface surface)
        {
            if (surface == null)
            {
                return(null);
            }

            SumSurface sumSurface = surface as SumSurface;

            if (sumSurface != null)
            {
                return(sumSurface.ToTopologic());
            }

            RevSurface revSurface = surface as RevSurface;

            if (revSurface != null)
            {
                return(revSurface.ToTopologic());
            }

            PlaneSurface planeSurface = surface as PlaneSurface;

            if (planeSurface != null)
            {
                return(planeSurface.ToTopologic());
            }

            Extrusion ghExtrusion = surface as Extrusion;

            if (ghExtrusion != null)
            {
                return(ghExtrusion.ToTopologic());
            }

            global::Rhino.Geometry.NurbsSurface ghNurbsSurface = surface as global::Rhino.Geometry.NurbsSurface;
            if (ghNurbsSurface != null)
            {
                return(ghNurbsSurface.ToTopologic());
            }


            return(null);
        }
示例#11
0
        static RevSurface FromRevolvedSurface(DB.XYZ origin, DB.XYZ xDir, DB.XYZ yDir, DB.XYZ zDir, DB.Curve curve, DB.BoundingBoxUV bboxUV)
        {
            var ctol = Revit.ShortCurveTolerance;
            var atol = Revit.AngleTolerance;
            var uu   = new Interval(bboxUV.Min.U - atol, bboxUV.Max.U + atol);

            var o = origin.ToRhino();
            var z = (Vector3d)zDir.Normalize().ToRhino();

            var axis = new Line(o, o + z);

            using (var ECStoWCS = new DB.Transform(DB.Transform.Identity)
            {
                Origin = origin, BasisX = xDir.Normalize(), BasisY = yDir.Normalize(), BasisZ = zDir.Normalize()
            })
            {
                var c = curve.CreateTransformed(ECStoWCS).ToRhino().Extend(CurveEnd.Both, ctol, CurveExtensionStyle.Smooth);
                return(RevSurface.Create(c, axis, uu.Min, uu.Max));
            }
        }
    public static Rhino.Commands.Result AddTruncatedCone(Rhino.RhinoDoc doc)
    {
        Point3d      bottom_pt     = new Point3d(0, 0, 0);
        const double bottom_radius = 2;
        Circle       bottom_circle = new Circle(bottom_pt, bottom_radius);

        Point3d      top_pt     = new Point3d(0, 0, 10);
        const double top_radius = 6;
        Circle       top_circle = new Circle(top_pt, top_radius);

        LineCurve  shapeCurve = new LineCurve(bottom_circle.PointAt(0), top_circle.PointAt(0));
        Line       axis       = new Line(bottom_circle.Center, top_circle.Center);
        RevSurface revsrf     = RevSurface.Create(shapeCurve, axis);
        Brep       tcone_brep = Brep.CreateFromRevSurface(revsrf, true, true);

        if (doc.Objects.AddBrep(tcone_brep) != Guid.Empty)
        {
            doc.Views.Redraw();
            return(Rhino.Commands.Result.Success);
        }
        return(Rhino.Commands.Result.Failure);
    }
            protected override void PostDrawObjects(DrawEventArgs e)
            {
                try
                {
                    lock (Rhino.RhinoDoc.ActiveDoc.Views.ActiveView)
                    {
                        if (labguide)
                        {
                            e.Display.DrawDot(new Point3d(0, 0, 0), "Center");
                            e.Display.DrawSurface(RevSurface.Create(new ArcCurve(new Arc(new Plane(new Point3d(0, 0, depth), new Vector3d(1, 0, 0)), radius, System.Math.PI / 2)), new Line(new Point3d(0, 0, 0), new Point3d(0, 0, 1)), 0, 2 * System.Math.PI), System.Drawing.Color.Green, 4);
                            e.Display.DrawDot(new Point3d(0, 0, radius + depth), "Source");
                            e.Display.DrawArrow(new Line(new Point3d(0, 0, 1.2 * radius + depth), new Point3d(0, 0, 1 * radius + depth)), System.Drawing.Color.Red);
                            if (hemianechoic)
                            {
                                e.Display.DrawBox(new BoundingBox(new Point3d(-radius, -radius, 0), new Point3d(radius, radius, 1.2 * radius + depth)), System.Drawing.Color.Blue, 2);
                                e.Display.DrawBox(new BoundingBox(new Point3d(-radius - 1, -radius - 1, 0), new Point3d(radius + 1, radius + 1, 1.2 * radius + 1 + depth)), System.Drawing.Color.Black, 2);
                            }
                            else
                            {
                                e.Display.DrawBox(new BoundingBox(new Point3d(-2 * radius, -2 * radius, 0), new Point3d(2 * radius, 2 * radius, 1.2 * radius + depth)), System.Drawing.Color.Blue, 2);
                                e.Display.DrawBox(new BoundingBox(new Point3d(-2 * radius - 1, -2 * radius - 1, -1), new Point3d(2 * radius + 1, 2 * radius + 1, 1.2 * radius + 1 + depth)), System.Drawing.Color.Black, 2);
                            }
                        }

                        for (int i = 0; i < DisplayMesh.Count; i++)
                        {
                            for (int j = 0; j < DirMesh[i].Length; j++)
                            {
                                e.Display.DrawMeshWires(DirMesh[i][j], System.Drawing.Color.Blue);
                            }
                            e.Display.DrawMeshWires(DisplayMesh[i], System.Drawing.Color.Red);
                        }
                    }
                }
                catch { return; }
            }
示例#14
0
 private Topologic.Face ByRevSurface(RevSurface ghRevSurface)
 {
     Rhino.Geometry.NurbsSurface ghNurbsSurface = ghRevSurface.ToNurbsSurface();
     return(ByNurbsSurface(ghNurbsSurface));
 }
示例#15
0
        static RevSurface ToRhinoSphereSurface(NXOpen.Face face)
        {
            var faceData = face.GetData();

            return(RevSurface.CreateFromSphere(new Sphere(faceData.Point.ToRhino(), faceData.Radius)));
        }
        private Result CreateNoseCone(RhinoDoc doc, XmlNode compNd, ref double stackLength)
        {
            Result      result     = Rhino.Commands.Result.Failure;
            XmlElement  compEle    = compNd as XmlElement;
            XmlNodeList subCompNds = compNd.SelectNodes("subcomponents/*");

            double            length               = 0;
            double            thickness            = 0;
            NoseConeShapeType shape                = NoseConeShapeType.Ogive;
            double            shapeParameter       = 0;
            double            aftRadius            = 0;
            double            aftShoulderRadius    = 0;
            double            aftShoulderLength    = 0;
            double            aftShoulderThickness = 0;
            bool aftShoulderCapped = false;

            foreach (XmlNode nd in compEle.ChildNodes)
            {
                if (nd.Name == "length")
                {
                    length = Double.Parse(nd.InnerText);
                }
                else if (nd.Name == "thickness")
                {
                    thickness = Double.Parse(nd.InnerText);
                }
                else if (nd.Name == "shape")
                {
                    shape = (NoseConeShapeType)Enum.Parse(typeof(NoseConeShapeType), nd.InnerText, true);
                }
                else if (nd.Name == "shapeparameter")
                {
                    shapeParameter = Double.Parse(nd.InnerText);
                }
                else if (nd.Name == "aftradius")
                {
                    if (nd.InnerText == "auto")
                    {
                        XmlNode sibNd = compNd.NextSibling;
                        foreach (XmlNode sibChild in sibNd.ChildNodes)
                        {
                            if (sibNd.Name == "bodytube" && sibChild.Name == "radius")
                            {
                                aftRadius = Double.Parse(sibChild.InnerText);
                            }
                        }
                    }
                    else
                    {
                        aftRadius = Double.Parse(nd.InnerText);
                    }
                }
                else if (nd.Name == "aftshoulderradius")
                {
                    aftShoulderRadius = Double.Parse(nd.InnerText);
                }
                else if (nd.Name == "aftshoulderlength")
                {
                    aftShoulderLength = Double.Parse(nd.InnerText);
                }
                else if (nd.Name == "aftshoulderthickness")
                {
                    aftShoulderThickness = Double.Parse(nd.InnerText);
                }
                else if (nd.Name == "aftshouldercapped")
                {
                    aftShoulderCapped = Boolean.Parse(nd.InnerText);
                }
            }

            // generate geometry and create solid.
            int            numberDivisions = 100;
            OgiveCurve     ogive           = new OgiveCurve(aftRadius, length);
            double         xa     = ogive.SphericalCapApex(0);
            double         delta  = (length - xa) / (numberDivisions - 1);
            double         x      = xa;
            double         y      = 0;
            List <Point3d> points = new List <Point3d>();

            for (int i = 0; i < numberDivisions; i++)
            {
                double angle = (double)i * System.Math.PI / (double)numberDivisions;
                y = ogive.Evaluate(x);

                points.Add(new Point3d(x, y, 0));

                x += delta;
            }

            Polyline curve = new Polyline(points);

            NurbsCurve nbCurve = curve.ToNurbsCurve();

            Curve[] offsetsCurves = nbCurve.Offset(new Plane(new Point3d(0, 0, 0), Vector3d.XAxis, Vector3d.YAxis), thickness, 0.0001, CurveOffsetCornerStyle.None);

            Plane plane = new Plane(new Point3d(0, 0, 0), Vector3d.XAxis, Vector3d.ZAxis);

            Curve[] splits = offsetsCurves[0].Split(new PlaneSurface(plane, new Interval(0, 100), new Interval(0, 100)), 0.0001);

            LineCurve line1 = new LineCurve(nbCurve.PointAtStart, splits[1].PointAtStart);
            LineCurve line2 = new LineCurve(nbCurve.PointAtEnd, splits[1].PointAtEnd);

            List <Curve> curves = new List <Curve>()
            {
                nbCurve, splits[1], line1, line2
            };

            Curve[] joined = Curve.JoinCurves(curves);

            RevSurface revsrf = RevSurface.Create(joined[0], new Line(new Point3d(0, 0, 0), new Point3d(length, 0, 0)), 0, 2 * Math.PI);
            Brep       brep   = Brep.CreateFromRevSurface(revsrf, true, true);

            brep.Flip();

            if (aftShoulderLength > 0)
            {
                double innerRadius = aftShoulderRadius - aftShoulderThickness;
                double outerRadius = aftShoulderRadius;
                Plane  planeCyl    = new Plane(new Point3d(0, 0, 0), Vector3d.XAxis);
                Circle innerCir    = new Circle(planeCyl, innerRadius);
                Circle outerCir    = new Circle(planeCyl, outerRadius);

                Cylinder innerCyl = new Cylinder(innerCir, aftShoulderThickness + aftShoulderLength);
                Cylinder outerCyl = new Cylinder(outerCir, aftShoulderThickness + aftShoulderLength);

                Brep brepInner = Brep.CreateFromCylinder(innerCyl, true, true);
                Brep brepOuter = Brep.CreateFromCylinder(outerCyl, true, true);

                Brep[]    tube  = Brep.CreateBooleanDifference(brepOuter, brepInner, 0.0001);
                Transform trans = Transform.Translation(new Vector3d(length - aftShoulderThickness, 0, 0));

                tube[0].Transform(trans);

                Brep[] withShoulder = Brep.CreateBooleanUnion(new List <Brep>()
                {
                    brep, tube[0]
                }, 0.001);
                brep = withShoulder[0];
            }


            if (doc.Objects.AddBrep(brep) != Guid.Empty)
            {
                doc.Views.Redraw();
                result = Rhino.Commands.Result.Success;
            }

            stackLength = length; // cone seems to start a new stack

            foreach (XmlNode subNd in subCompNds)
            {
                if (subNd.Name == "tubecoupler")
                {
                    result = CreateTubeCoupler(doc, subNd, stackLength);
                }
            }

            return(result);
        }
示例#17
0
        static RevSurface ToRhinoRevSurface(NXOpen.Face face, FaceEx.FaceData faceData)
        {
            var bodyFeatures = face.GetBody().GetFeatures();

            var revolveFeature = bodyFeatures.FirstOrDefault(obj => obj is NXOpen.Features.Revolve);

            Curve  faceSectionCurve = default;
            double startRadian      = 0.0;
            double endRadian        = Math.PI * 2;

            if (revolveFeature != null)
            {
                NXOpen.Features.RevolveBuilder revolveBuilder = WorkPart.Features.CreateRevolveBuilder(revolveFeature);
                revolveBuilder.Section.GetOutputCurves(out var sectionCurves);

                startRadian = revolveBuilder.Limits.StartExtend.Value.Value * Math.PI / 180.0;

                endRadian = revolveBuilder.Limits.EndExtend.Value.Value * Math.PI / 180.0;

                revolveBuilder.Destroy();

                for (int i = 0; i < sectionCurves.Length; i++)
                {
                    var baseCurve = sectionCurves[i] as NXOpen.IBaseCurve;

                    var curveMidPt = baseCurve.GetPoint(0.5);
                    if (curveMidPt.DistanceTo(face.Tag).Distance < DistanceTolerance)
                    {
                        faceSectionCurve = baseCurve.ToRhinoCurve();
                        break;
                    }
                }
            }
            else
            {
                var faceBoundingBox = face.GetAlignedBoundingBox(faceData.Direction);

                var point1 = faceData.Point.Move(faceData.Direction, faceBoundingBox.Height * 1.5);

                var faceMidPoint = face.GetPoint();

                // 求与旋转方向垂直,并且位于面上的方向
                var verticalDirection = faceData.Direction.CrossProduct(faceMidPoint.Subtract(faceData.Point)).CrossProduct(faceData.Direction);

                var point2 = point1.Move(verticalDirection, faceBoundingBox.Length * 1.5);

                var point3 = point2.Move(faceData.Direction.Reverse(), faceBoundingBox.Height * 3);

                var point4 = point3.Move(verticalDirection.Reverse(), faceBoundingBox.Length * 1.5);

                NXOpen.Session.UndoMarkId undoMarkId = TheSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Calc Rev Profile");

                NXOpen.Body fourPointSurface = WorkPart.Features.CreateFourPointSurface(point1, point2, point3, point4);

                try
                {
                    NXOpen.Features.IntersectionCurve intersectionCurveFeature = WorkPart.Features.CreateIntersectionCurve(fourPointSurface.GetFaces(), face);

                    faceSectionCurve = (intersectionCurveFeature.GetEntities()[0] as NXOpen.Curve).ToRhino();

                    intersectionCurveFeature.Delete();

                    fourPointSurface.Delete();
                }
                catch (Exception)
                {
                    TheSession.UndoToMark(undoMarkId, "Calc Rev Profile");

                    Console.WriteLine($"无法创建面 {face.Tag} 的交线");

                    return(null);
                }
                finally
                {
                    TheSession.DeleteUndoMark(undoMarkId, "Calc Rev Profile");
                }
            }

            return(RevSurface.Create(faceSectionCurve, new Line(faceData.Point.ToRhino(), faceData.Point.Move(faceData.Direction, 10.0).ToRhino()), startRadian, endRadian));
        }
示例#18
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Brep brep = null;

            DA.GetData("Brep", ref brep);

            if (!DA.GetData("Workplane", ref Workplane))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Workplane missing. Default used (WorldXY).");
            }

            if (!DA.GetData("MachineTool", ref Tool))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "MachineTool missing. Default used.");
            }

            bool male = false;

            DA.GetData("Male", ref male);

            bool flip = false;

            DA.GetData("Flip", ref flip);

            double angle  = 60;
            double hangle = angle / 360 * Math.PI;
            double depth  = 3;

            Curve[]   intersections;
            Point3d[] intersection_points;
            Rhino.Geometry.Intersect.Intersection.BrepPlane(brep, Workplane, Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance, out intersections, out intersection_points);
            if (intersections.Length < 1)
            {
                return;
            }

            BoundingBox bb = intersections[0].GetBoundingBox(Workplane);

            double r = double.MaxValue;

            for (int i = 0; i < 2; ++i)
            {
                for (int j = 0; j < 2; ++j)
                {
                    for (int k = 0; k < 2; ++k)
                    {
                        r = Math.Min(bb.Corner((i == 1), (j == 1), (k == 1)).DistanceTo(Point3d.Origin), r);
                    }
                }
            }

            List <Point3d> pts         = new List <Point3d>();
            double         step        = Math.Tan(hangle) * depth;
            int            num_grooves = (int)(r / step) + 5;

            if (male)
            {
                depth *= -1;
            }

            for (int i = 0; i <= num_grooves; ++i)
            {
                pts.Add(new Point3d(step * i, 0.0, depth * ((Math.Abs(i) % 2) * 2 - 1)));
            }

            Polyline poly = new Polyline(pts);

            Rhino.Geometry.RevSurface rev = RevSurface.Create(poly, new Line(Point3d.Origin, Vector3d.ZAxis));
            rev.Transform(Transform.PlaneToPlane(Plane.WorldXY, Workplane));

            Brep grooves = rev.ToBrep();


            if (flip)
            {
                List <Brep> srfs = new List <Brep>();
                for (int i = 0; i < grooves.Surfaces.Count; ++i)
                {
                    srfs.Add(Brep.CreateFromSurface(grooves.Surfaces[i].Reverse(0)));
                }
                grooves = Brep.MergeBreps(srfs, 0.1);
            }

            Brep[] trims = brep.Trim(grooves, 0.1);
            if (trims.Length < 1)
            {
                throw new Exception("Trim failed!");
            }

            Brep final = trims[0];

            for (int i = 1; i < trims.Length; ++i)
            {
                final.Join(trims[i], 0.1, true);
            }

            trims = grooves.Trim(brep, 0.1);
            for (int i = 0; i < trims.Length; ++i)
            {
                final.Join(trims[i], 0.1, true);
            }

            DA.SetData("Finger Joint", final);
        }
示例#19
0
 public static global::Topologic.Face ToTopologic(this RevSurface revSurface)
 {
     Rhino.Geometry.NurbsSurface ghNurbsSurface = revSurface?.ToNurbsSurface();
     return(ghNurbsSurface?.ToTopologic());
 }