Example #1
0
        private void createConsoleDrawing1()
        {
            Curve curve = createOutline();
            Brep  brep  = Extrusion.CreateExtrusion(curve,
                                                    new Vector3d(0, 0, convertToDouble(textBox_b.Text))).ToBrep()
                          .CapPlanarHoles(RhinoDoc.ActiveDoc.ModelAbsoluteTolerance);

            RhinoDoc.ActiveDoc.Objects.AddBrep(brep);


            _corbelConduit.reinforcements.Clear();
            _corbelConduit.corbel = brep;
            Brep   reinf    = createMainReinforcement();
            double width    = convertToDouble(textBox_b.Text);
            double distance = (width - convertToDouble(textBox_cc.Text) * 2 - 2 * 32) / (convertToDouble(textBox_n.Text) - 1);

            Brep first = (Brep)reinf.DuplicateShallow();

            first.Translate(new Vector3d(0, 0, convertToDouble(textBox_cc.Text) + 32));

            _corbelConduit.reinforcements.Add(first);

            for (int i = 0; i < convertToDouble(textBox_n.Text); i++)
            {
                Brep copy = (Brep)first.DuplicateShallow();
                copy.Translate(new Vector3d(0, 0, i * distance));
                _corbelConduit.reinforcements.Add(copy);
            }

            RhinoDoc.ActiveDoc.Views.Redraw();
        }
Example #2
0
        public static List <Brep> OrthogonalEgress(List <Curve> coreCurves, List <Curve> egressAxis)
        {
            List <Brep> egressExemptionRegions = new List <Brep>();

            for (int i = 0; i < egressAxis.Count; i++)
            {
                Point3d coreCurveMidpoint = Utils.GetCurveMidPoint(coreCurves[i]);
                egressAxis[i].ClosestPoint(coreCurveMidpoint, out double circulationParameter);
                Point3d circulationPoint = egressAxis[i].PointAt(circulationParameter);

                Vector3d connectionVector     = new Vector3d(circulationPoint - coreCurveMidpoint);
                bool     proportionIsVertical = Confirm.VectorProportionIsVertical(connectionVector);

                Vector3d egressVector = (proportionIsVertical == true) ? new Vector3d(0, connectionVector.Y, 0) : new Vector3d(connectionVector.X, 0, 0);

                Curve egressRegionProfile = Curves.RebuildPerpendicularTo(coreCurves[i], egressVector);

                //MessageBox.Show(connectionVector.ToString() + " => " + egressVector.ToString());

                Brep egressRegion = Brep.CreateFromSurface(Extrusion.CreateExtrusion(egressRegionProfile, egressVector));

                egressExemptionRegions.Add(egressRegion);
            }

            return(egressExemptionRegions);
        }
Example #3
0
        public static List <Brep> SplitByCurve(Brep brepToSplit, Curve splitter)
        {
            if (splitter == null)
            {
                List <Brep> unmodified = new List <Brep>();
                unmodified.Add(brepToSplit);
                return(unmodified);
            }

            Brep splitterBrep = Extrusion.CreateExtrusion(splitter, Vector3d.ZAxis).ToBrep();

            Brep[] splitBreps = brepToSplit.Split(splitterBrep, 0.1);

            List <Brep> result = new List <Brep>(splitBreps);

            //MessageBox.Show(result.Count.ToString());

            return(result);
        }
Example #4
0
        private Brep ExtrudeCurveBothSide(Curve Crv, Vector3d Direction, bool BothSide, bool IsCape)
        {
            double Tolerance = Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance;

            if (Direction.Length == 0)
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "拉伸向量的长度不能为0");
                return(null);
            }
            if (BothSide)
            {
                Crv.Transform(Transform.Translation(Direction));
                Direction.Reverse();
                Direction = Direction * 2;
            }
            if (Crv.IsPlanar())
            {
                try
                {
                    Brep Temp = Extrusion.CreateExtrusion(Crv, Direction).ToBrep();
                    if (IsCape)
                    {
                        return(Temp.CapPlanarHoles(Tolerance));
                    }
                    else
                    {
                        return(Temp);
                    }
                }
                catch (Exception e)
                {
                    this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, string.Format("内部错误:{0}", e.Message));
                    return(null);
                }
            }
            else
            {
                this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "输入的几何体不符合条件");
                return(null);
            }
        }
Example #5
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            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.");
            }

            Brep brep = null;

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

            bool male = false;

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

            bool flip = false;

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

            double angle = 0;

            DA.GetData("Angle", ref angle);

            double depth = 0;

            DA.GetData("Depth", ref depth);
            double hdepth = depth / 2;

            double hangle = angle / 360 * Math.PI;

            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;
            }

            Curve[] outline_list = Curve.JoinCurves(intersections);
            if (outline_list.Length < 1)
            {
                return;
            }
            Curve outline = outline_list[0];

            List <Point3d> toolpath_start_points = new List <Point3d>();
            BoundingBox    bb = intersections[0].GetBoundingBox(Workplane);

            double max_x = 0;
            double max_y = 0;

            for (int i = 0; i < 2; ++i)
            {
                for (int j = 0; j < 2; ++j)
                {
                    for (int k = 0; k < 2; ++k)
                    {
                        max_x = Math.Max(Math.Abs(bb.Corner((i == 1), (j == 1), (k == 1)).X), max_x);
                        max_y = Math.Max(Math.Abs(bb.Corner((i == 1), (j == 1), (k == 1)).Y), max_y);
                    }
                }
            }

            List <Point3d> pts  = new List <Point3d>();
            double         step = Math.Tan(hangle) * depth;

            Curve[] offsets = outline.Offset(Workplane, step * 2, 0.1, CurveOffsetCornerStyle.Sharp);
            outline = offsets[0];

            int num_grooves = (int)(max_x / step) + 5;

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

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

            #region Toolpath
            int flipper = flip ? 1 : 0;

            for (int i = flipper; i < pts.Count; i += 2)
            {
                toolpath_start_points.Add(new Point3d(pts[i].X, pts[i].Y, 0.0));
            }

            flipper = flip ? 1 : -1;

            List <GH_PPolyline> paths = new List <GH_PPolyline>();

            List <Point3d> path_points = new List <Point3d>();
            List <Tuple <Point3d, Point3d> > path_pairs = new List <Tuple <Point3d, Point3d> >();

            for (int i = 0; i < toolpath_start_points.Count; ++i)
            {
                Point3d  p1   = toolpath_start_points[i];
                Point3d  p2   = toolpath_start_points[i] + Vector3d.YAxis * max_y * 4;
                Polyline temp = new Polyline(new Point3d[] { p1, p2 });
                temp.Transform(Transform.PlaneToPlane(Plane.WorldXY, Workplane));
                Rhino.Geometry.Intersect.CurveIntersections ci = Rhino.Geometry.Intersect.Intersection.CurveCurve(outline, temp.ToNurbsCurve(), 0.1, 0.01);
                if (ci.Count == 2)
                {
                    path_pairs.Add(new Tuple <Point3d, Point3d>(ci[0].PointA + Workplane.ZAxis * hdepth * flipper, ci[1].PointB + Workplane.ZAxis * hdepth * flipper));
                }
            }

            path_points.Add(path_pairs[0].Item1);
            path_points.Add(path_pairs[0].Item2);

            double d1, d2;
            int    index = 1;
            for (int i = 1; i < path_pairs.Count; ++i)
            {
                d1 = path_pairs[i].Item1.DistanceTo(path_points[index]);
                d2 = path_pairs[i].Item2.DistanceTo(path_points[index]);
                if (d1 > d2)
                {
                    path_points.Add(path_pairs[i].Item2);
                    path_points.Add(path_pairs[i].Item1);
                }
                else
                {
                    path_points.Add(path_pairs[i].Item1);
                    path_points.Add(path_pairs[i].Item2);
                }
                index += 2;
            }

            paths.Add(new GH_PPolyline(new PPolyline(path_points, Workplane)));

            #endregion


            Polyline poly = new Polyline(pts);

            Brep grooves = Extrusion.CreateExtrusion(poly.ToNurbsCurve(), Vector3d.YAxis * max_y * 4).ToBrep();
            grooves.Transform(Transform.PlaneToPlane(Plane.WorldXY, Workplane));

            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);
            DA.SetDataList("Paths", paths);
        }
Example #6
0
        static public List <Brep> CreateSectionSweeps(WR_Elem3dRcp er)
        {
            List <Curve> crvs;
            List <Brep>  eSBreps = new List <Brep>();

            // Start and end caps
            List <Curve> sCap = new List <Curve>();
            List <Curve> eCap = new List <Curve>();

            if (CrossSectionCasts.GetSectionPropertyCrvs(er.GetSectionString(), out crvs))
            {
                // Get x vector
                Point3d  sPos     = er.GetStartPos().ConvertToRhinoPoint();
                Point3d  ePos     = er.GetEndPos().ConvertToRhinoPoint();
                Vector3d elX      = new Vector3d(ePos.X - sPos.X, ePos.Y - sPos.Y, ePos.Z - sPos.Z);
                double   elLength = elX.Length;
                elX.Unitize();
                Vector3d move = elX * elLength;

                // Get normal (z vector)
                WR_Vector elWrZ = er.GetElementNormal();
                Vector3d  elZ   = new Vector3d(elWrZ.X, elWrZ.Y, elWrZ.Z);

                // Get y vector
                Vector3d elY = Vector3d.CrossProduct(elZ, elX);

                // Rotation to local coordinates
                Transform rotTrans = Transform.Rotation(Vector3d.XAxis, Vector3d.YAxis, Vector3d.ZAxis, elX, elY, elZ);

                // Add start and end point to a list
                List <Point3d> endPts = new List <Point3d> {
                    sPos, ePos
                };

                foreach (Curve crv in crvs)
                {
                    // Rotate to local coordinates
                    crv.Transform(rotTrans);
                    crv.Translate((Vector3d)sPos);

                    // Create and add extrusion
                    Brep extrusion = Extrusion.CreateExtrusion(crv, move).ToBrep();
                    eSBreps.Add(extrusion);

                    // Add curve to cap list
                    sCap.Add(crv);

                    // Move to end and add
                    Curve eCrv = (Curve)crv.Duplicate();
                    eCrv.Translate(move);
                    eCap.Add(eCrv);
                }

                // Cap sections
                eSBreps.Add(CapSections(sCap));
                eSBreps.Add(CapSections(eCap));
            }


            return(eSBreps);
        }