Exemplo n.º 1
0
        public override List <Brep> GetLamellaBreps()
        {
            double Length = Centreline.GetLength();
            double hW     = Data.NumWidth * Data.LamWidth / 2;
            double hH     = Data.NumHeight * Data.LamHeight / 2;
            //double[] DivParams = Centreline.DivideByCount(Data.Samples - 1, true);

            int N = Math.Max(Data.Samples, 6);

            GenerateCrossSectionPlanes(N, out Plane[] frames, out double[] parameters, Data.InterpolationType);

            GetSectionOffset(out double offsetX, out double offsetY);

            Point3d[,,] AllPoints   = new Point3d[Data.NumWidth + 1, Data.NumHeight + 1, parameters.Length];
            Point3d[,] CornerPoints = new Point3d[Data.NumWidth + 1, Data.NumHeight + 1];

            for (int x = 0; x <= Data.NumWidth; ++x)
            {
                for (int y = 0; y <= Data.NumHeight; ++y)
                {
                    CornerPoints[x, y] = new Point3d(
                        -hW + offsetX + x * Data.LamWidth,
                        -hH + offsetY + y * Data.LamHeight,
                        0);
                }
            }



            Transform xform;
            Point3d   temp;

            for (int i = 0; i < frames.Length; ++i)
            {
                xform = Rhino.Geometry.Transform.PlaneToPlane(Plane.WorldXY, frames[i]);

                for (int x = 0; x <= Data.NumWidth; ++x)
                {
                    for (int y = 0; y <= Data.NumHeight; ++y)
                    {
                        temp = new Point3d(CornerPoints[x, y]);
                        temp.Transform(xform);
                        AllPoints[x, y, i] = temp;
                    }
                }
            }

            Curve[,] EdgeCurves = new Curve[Data.NumWidth + 1, Data.NumHeight + 1];
            for (int x = 0; x <= Data.NumWidth; ++x)
            {
                for (int y = 0; y <= Data.NumHeight; ++y)
                {
                    Point3d[] pts = new Point3d[frames.Length];
                    for (int z = 0; z < frames.Length; ++z)
                    {
                        pts[z] = AllPoints[x, y, z];
                    }

                    EdgeCurves[x, y] = Curve.CreateInterpolatedCurve(pts, 3, CurveKnotStyle.Chord, frames.First().ZAxis, frames.Last().ZAxis);
                }
            }

            List <Brep> LamellaBreps = new List <Brep>();

            for (int x = 0; x < Data.NumWidth; ++x)
            {
                for (int y = 0; y < Data.NumHeight; ++y)
                {
                    Curve[] edges = new Curve[8];
                    edges[4] = new Line(AllPoints[x, y, 0], AllPoints[x + 1, y, 0]).ToNurbsCurve();
                    edges[5] = new Line(AllPoints[x, y + 1, 0], AllPoints[x + 1, y + 1, 0]).ToNurbsCurve();

                    edges[6] = new Line(AllPoints[x, y, frames.Length - 1], AllPoints[x + 1, y, frames.Length - 1]).ToNurbsCurve();
                    edges[7] = new Line(AllPoints[x, y + 1, frames.Length - 1], AllPoints[x + 1, y + 1, frames.Length - 1]).ToNurbsCurve();

                    Brep[] sides = new Brep[6];

                    sides[0] = Brep.CreateFromLoft(
                        new Curve[] { EdgeCurves[x, y], EdgeCurves[x + 1, y] },
                        Point3d.Unset, Point3d.Unset, LoftType.Straight, false)[0];
                    sides[1] = Brep.CreateFromLoft(
                        new Curve[] { EdgeCurves[x + 1, y], EdgeCurves[x + 1, y + 1] },
                        Point3d.Unset, Point3d.Unset, LoftType.Straight, false)[0];
                    sides[2] = Brep.CreateFromLoft(
                        new Curve[] { EdgeCurves[x + 1, y + 1], EdgeCurves[x, y + 1] },
                        Point3d.Unset, Point3d.Unset, LoftType.Straight, false)[0];
                    sides[3] = Brep.CreateFromLoft(
                        new Curve[] { EdgeCurves[x, y + 1], EdgeCurves[x, y] },
                        Point3d.Unset, Point3d.Unset, LoftType.Straight, false)[0];

                    sides[4] = Brep.CreateFromLoft(
                        new Curve[] { edges[4], edges[5] },
                        Point3d.Unset, Point3d.Unset, LoftType.Straight, false)[0];

                    sides[5] = Brep.CreateFromLoft(
                        new Curve[] { edges[6], edges[7] },
                        Point3d.Unset, Point3d.Unset, LoftType.Straight, false)[0];

                    Brep brep = Brep.JoinBreps(
                        sides,
                        Tolerance
                        )[0];

                    LamellaBreps.Add(brep);
                }
            }

            return(LamellaBreps);
        }
        public static Curve CreateTweenCurve(Curve curveA, Curve curveB, double curve_parameter, double tol, double ang_tol)
        {
            List <double> t0 = new List <double>();
            List <double> t1 = new List <double>();

            t0.Add(curveA.Domain.T0);
            t0.Add(curveB.Domain.T0);
            t1.Add(curveA.Domain.T0);
            t1.Add(curveB.Domain.T0);

            // Create loft from base curves
            var base_curves = new List <Curve>()
            {
                curveA, curveB
            };
            var loft_curves = new List <Curve>();
            var tol_factor  = 1.0;

            for (int i = 0; i < 2; i++)
            {
                var   segemnts = base_curves[i].DuplicateSegments();
                Curve crv      = null;
                if (segemnts.Length <= 1)
                {
                    crv = ((base_curves[i].Degree != 2) ? base_curves[i] : base_curves[i].Fit(4, tol, ang_tol));
                }
                else
                {
                    Point3d  pointAtStart = base_curves[i].PointAtStart;
                    Interval domain       = base_curves[i].Domain;
                    for (int j = 0; j < segemnts.Length; j++)
                    {
                        if (segemnts[j].Degree == 2)
                        {
                            segemnts[j] = segemnts[j].Fit(4, tol, ang_tol);
                        }
                    }
                    Curve[] segments2 = Curve.JoinCurves(segemnts);
                    segments2[0].ClosestPoint(pointAtStart, out var t);
                    segments2[0].ChangeClosedCurveSeam(t);
                    segments2[0].Domain = domain;
                    crv = segments2[0];
                }
                while (crv.IsClosed)
                {
                    Point3d testPoint  = crv.PointAtLength(tol * (double)tol_factor);
                    Point3d testPoint2 = crv.PointAtLength(crv.GetLength() - tol * (double)tol_factor);
                    crv.ClosestPoint(testPoint, out var t2);
                    crv.ClosestPoint(testPoint2, out var t3);
                    Interval domain2 = new Interval(t2, t3);
                    domain2.MakeIncreasing();
                    crv = crv.Trim(domain2);
                    tol_factor++;
                    if (tol_factor == 1000)
                    {
                        break;
                    }
                }
                loft_curves.Add(crv);
            }
            var loft    = Brep.CreateFromLoft(loft_curves, Point3d.Unset, Point3d.Unset, LoftType.Normal, closed: false);
            var surface = loft[0].Surfaces[0];

            var constantParameter = surface.Domain(0).ParameterAt(curve_parameter);
            var crv2 = surface.IsoCurve(1, constantParameter);

            if (crv2.IsClosable(tol * (double)(tol_factor * 2)))
            {
                crv2.SetEndPoint(crv2.PointAtLength(0.0));
            }
            crv2.Domain = new Interval(t0.Min(), t1.Max());
            return(crv2);
        }
Exemplo n.º 3
0
        private static List <Brep> DrawPiloti(Curve baseCurve, IEnumerable <double> parameter, double pilotiHeight)
        {
            List <Brep> output = new List <Brep>();

            double pilotiWidth = 300;

            double convertedPilotiWidth;

            baseCurve.LengthParameter(pilotiWidth, out convertedPilotiWidth);
            convertedPilotiWidth = convertedPilotiWidth - baseCurve.Domain.T0;

            //첫부분 필로티 생성)

            Curve firstPilotiCurve = new LineCurve(baseCurve.PointAt(parameter.ToList()[0]), baseCurve.PointAt(parameter.ToList()[0] + convertedPilotiWidth));
            Curve firstLoftBase    = firstPilotiCurve.DuplicateCurve();

            firstLoftBase.Transform(Transform.Translation(new Vector3d(0, pilotiHeight, 0)));

            Curve[] firstLoftBaseSet = { firstPilotiCurve, firstLoftBase };

            Brep firstPilotiBrep = Brep.CreateFromLoft(firstLoftBaseSet, Point3d.Unset, Point3d.Unset, LoftType.Normal, false)[0];

            output.Add(firstPilotiBrep);

            //중간부분 필로티 생성)

            for (int i = 1; i < parameter.Count() - 1; i++)
            {
                Curve tempCurve    = new LineCurve(baseCurve.PointAt(parameter.ToList()[i] - convertedPilotiWidth / 2), baseCurve.PointAt(parameter.ToList()[i] + convertedPilotiWidth / 2));
                Curve tempLoftBase = tempCurve.DuplicateCurve();
                tempLoftBase.Transform(Transform.Translation(new Vector3d(0, pilotiHeight, 0)));

                Curve[] tempLoftBaseSet = { tempCurve, tempLoftBase };

                Brep tempPilotiBrep = Brep.CreateFromLoft(tempLoftBaseSet, Point3d.Unset, Point3d.Unset, LoftType.Normal, false)[0];

                output.Add(tempPilotiBrep);

                /*
                 *
                 * Curve tempCurve_2 = new LineCurve(baseCurve.PointAt(parameter.ToList()[i]), baseCurve.PointAt(parameter.ToList()[i] + convertedPilotiWidth / 2));
                 * Curve tempLoftBase_2 = tempCurve_2.DuplicateCurve();
                 * tempLoftBase_2.Transform(Transform.Translation(new Vector3d(0, pilotiHeight, 0)));
                 *
                 * Curve[] tempLoftBaseSet_2 = { tempCurve_2, tempLoftBase_2 };
                 *
                 * Brep tempPilotiBrep_2 = Brep.CreateFromLoft(tempLoftBaseSet_2, Point3d.Unset, Point3d.Unset, LoftType.Normal, false)[0];
                 *
                 * output.Add(tempPilotiBrep_2);
                 */
            }

            //마지막부분 필로티 생성)

            Curve lastPilotiCurve = new LineCurve(baseCurve.PointAt(parameter.ToList()[parameter.Count() - 1] - convertedPilotiWidth), baseCurve.PointAt(parameter.ToList()[parameter.Count() - 1]));
            Curve lastLoftBase    = lastPilotiCurve.DuplicateCurve();

            lastLoftBase.Transform(Transform.Translation(new Vector3d(0, pilotiHeight, 0)));

            Curve[] lastLoftBaseSet = { lastPilotiCurve, lastLoftBase };

            Brep lastPilotiBrep = Brep.CreateFromLoft(lastLoftBaseSet, Point3d.Unset, Point3d.Unset, LoftType.Normal, false)[0];

            output.Add(lastPilotiBrep);

            return(output);
        }
Exemplo n.º 4
0
        public Brep buildHelicalRack(Line L, Circle C, double Teeth, double Angle, double HAngle, double H, double addendum, double dedendum)
        {
            double M     = (2 * C.Radius) / Teeth;
            double Pitch = Math.PI * M;
            int    time  = (int)(L.Length / Pitch);

            Vector3d dir  = L.Direction; dir.Unitize();
            Vector3d dirA = dir;

            dirA.Rotate(toRadian(90.0 - Angle), C.Normal);
            Vector3d dirB = dir;

            dirB.Rotate(toRadian(-90.0 + Angle), C.Normal);

            addendum = addendum * M;
            dedendum = dedendum * M;

            double slope  = (addendum + dedendum) / Math.Cos(toRadian(Angle));
            double tip    = (Pitch * 0.50) - Math.Tan(Angle) * addendum * 2.0;
            double buttom = (Pitch * 0.5) - Math.Tan(Angle) * dedendum;

            List <Curve> profiles = new List <Curve>();

            profiles.Add(new LineCurve(new Line(L.From, dir * buttom * 0.5)));
            profiles.Add(new LineCurve(new Line(profiles[0].PointAtEnd, dirA * slope)));
            profiles.Add(new LineCurve(new Line(profiles[1].PointAtEnd, dir * tip)));
            profiles.Add(new LineCurve(new Line(profiles[2].PointAtEnd, dirB * slope)));
            profiles.Add(new LineCurve(new Line(profiles[3].PointAtEnd, dir * buttom * 0.5)));

            Transform move = Transform.Translation(Vector3d.CrossProduct(dir, C.Normal) * dedendum);
            Curve     rack = Curve.JoinCurves(profiles, 0.01, true)[0];

            rack.Transform(move);

            //Display
            locations.Add(rack.PointAtNormalizedLength(0.5));
            texts.Add(Math.Round(tip, 2).ToString());
            sizes.Add(Pitch * 4);

            //build helical
            //(H / Math.Tan(toRadian(Deg))) / (C.Radius * 2 * Math.PI) / Math.PI *2 * (C.Radius * 2 * Math.PI)
            double    hShift = H / (Math.Tan(toRadian(90.0 - HAngle)) * 2 * Math.PI); //helical shift
            double    hTime  = Math.Ceiling(hShift / Pitch);
            Transform shift  = Transform.Translation(dir * hShift);
            Transform zH     = Transform.Translation(C.Normal * H);

            List <Curve> racks    = new List <Curve>();
            List <Curve> helicals = new List <Curve>();

            if (hTime / Math.Abs(hTime) == 1)
            {
                // base rack
                for (int i = -1; i < time + 1; i++)
                {
                    Transform duplicate = Transform.Translation(dir * Pitch * i);
                    Curve     thisC     = rack.DuplicateCurve();
                    thisC.Transform(duplicate);
                    racks.Add(thisC);
                }
                // helical
                for (int i = -1; i < time + 1; i++)
                {
                    Transform duplicate = Transform.Translation(dir * Pitch * i);
                    Curve     thisC     = rack.DuplicateCurve();
                    thisC.Transform(duplicate);
                    helicals.Add(thisC);
                }
            }
            else
            {
                // base rack
                for (int i = 0; i < time + 2; i++)
                {
                    Transform duplicate = Transform.Translation(dir * Pitch * i);
                    Curve     thisC     = rack.DuplicateCurve();
                    thisC.Transform(duplicate);
                    racks.Add(thisC);
                }
                //helical
                for (int i = 0; i < time + 2; i++)
                {
                    Transform duplicate = Transform.Translation(dir * Pitch * i);
                    Curve     thisC     = rack.DuplicateCurve();
                    thisC.Transform(duplicate);
                    helicals.Add(thisC);
                }
            }
            Curve helical = Curve.JoinCurves(helicals, 1, true)[0];

            //align
            var    ccx     = Rhino.Geometry.Intersect.Intersection.CurveCurve(new LineCurve(L), new ArcCurve(C), 0.1, 0.1);
            double align_d = dedendum * Math.Tan(toRadian(Angle)) + tip + addendum / Math.Tan(toRadian(90 - Angle)) * 2 + buttom * 0.5;

            align_d += Math.Floor(ccx[0].PointA.DistanceTo(L.From + dir * align_d) / Pitch) * Pitch;
            Point3d   closet = L.From + dir * align_d;
            Transform align  = Transform.Translation(ccx[0].PointA - closet);

            rack = Curve.JoinCurves(racks, 1, true)[0];
            rack.Transform(align);
            helical.Transform(align);
            helical.Transform(shift);
            helical.Transform(zH);

            List <Curve> sections = new List <Curve> {
                rack, helical
            };
            Brep profile = Brep.CreateFromLoft(sections, Point3d.Unset, Point3d.Unset, LoftType.Normal, false)[0];

            return(profile);
        }
Exemplo n.º 5
0
        public static Section drawSection(List <Curve> baseCurve, List <List <List <Household> > > households, List <List <Core> > cores, Plot plot)
        {
            double storyHeight   = 2800;
            double floorLow      = 200;
            double wallThickness = 200;

            List <int> index = new List <int>();

            Curve perpCurve = new LineCurve(Point3d.Origin, Point3d.Origin);

            List <Curve>        Boundary = new List <Curve>();
            List <Curve>        Room     = new List <Curve>();
            List <Curve>        Core     = new List <Curve>();
            List <RoomNamecard> roomName = new List <RoomNamecard>();

            List <Curve> JoinedBoundaryCrv = new List <Curve>();
            List <Curve> CoreBase          = new List <Curve>();

            List <double> uniqueParameter = getUniqueParameter(baseCurve, plot, out perpCurve, out index);

            Curve groundCurve = new LineCurve(Point3d.Origin, new Point3d(perpCurve.GetLength(), 0, 0));

            for (int i = 0; i < index.Count(); i++)
            {
                Core tempCoreProperty = cores[index[i]][0];

                Point3d tempCoreStart = tempCoreProperty.Origin;
                Point3d tempCoreEnd   = tempCoreProperty.Origin + tempCoreProperty.YDirection * tempCoreProperty.Depth;

                double tempStartParam; double tempEndParam;

                perpCurve.ClosestPoint(tempCoreStart, out tempStartParam);
                perpCurve.ClosestPoint(tempCoreEnd, out tempEndParam);

                Curve tempCoreBase = new LineCurve(groundCurve.PointAt(tempStartParam), groundCurve.PointAt(tempEndParam));

                CoreBase.Add(offsetOneSide(tempCoreBase, Consts.PilotiHeight + Consts.FloorHeight * (tempCoreProperty.Stories + 1)));
            }


            for (int i = 0; i < uniqueParameter.Count(); i++)
            {
                List <Brep> boundary           = new List <Brep>();
                int         tempIntersectIndex = 0;

                for (int j = 0; j < households[i].Count(); j++)
                {
                    Household tempHousehold    = households[i][j][tempIntersectIndex];
                    double    widthAsParameter = tempHousehold.YLengthA * (groundCurve.Domain.T1 - groundCurve.Domain.T0) / groundCurve.GetLength();

                    Point3d tempStart = groundCurve.PointAt(uniqueParameter[i] - widthAsParameter / 2);
                    Point3d tempEnd   = groundCurve.PointAt(uniqueParameter[i] + widthAsParameter / 2);

                    Curve tempBase = new LineCurve(tempStart, tempEnd);
                    tempBase.Transform(Transform.Translation(new Vector3d(0, tempHousehold.Origin.Z, 0)));

                    Curve tempLoftBase = tempBase.DuplicateCurve();
                    tempLoftBase.Transform(Transform.Translation(new Vector3d(0, storyHeight, 0)));

                    Curve[] tempLoftBaseSet = { tempBase, tempLoftBase };
                    Brep    tempLoftedBrep  = Brep.CreateFromLoft(tempLoftBaseSet, Point3d.Unset, Point3d.Unset, LoftType.Straight, false)[0];
                    boundary.Add(tempLoftedBrep);

                    Curve roomBase = tempBase.DuplicateCurve();
                    roomBase.Transform(Transform.Translation(new Vector3d(0, floorLow, 0)));

                    double tempRoombaseStart; double tempRoombaseEnd;

                    roomBase.LengthParameter(wallThickness, out tempRoombaseStart);
                    roomBase.LengthParameter(roomBase.GetLength() - wallThickness, out tempRoombaseEnd);

                    roomBase = new LineCurve(roomBase.PointAt(tempRoombaseStart), roomBase.PointAt(tempRoombaseEnd));

                    Curve room = offsetOneSide(roomBase, storyHeight - floorLow * 2);

                    RoomNamecard tempNamecard = RoomNamecard.CreateRoomNamecard(roomBase.PointAt(roomBase.Domain.Mid) + new Point3d(0, (storyHeight - floorLow * 2) / 2, 0), tempHousehold.GetArea(), storyHeight - floorLow * 2);

                    Room.Add(room);
                    roomName.Add(tempNamecard);
                }

                Brep[] joinedBoundary = Brep.JoinBreps(boundary, 0.1);

                foreach (Brep j in joinedBoundary)
                {
                    Curve[] tempNakedEdge = j.DuplicateNakedEdgeCurves(true, true);

                    Boundary.AddRange(tempNakedEdge.ToList());

                    JoinedBoundaryCrv.AddRange(Curve.JoinCurves(tempNakedEdge).ToList());
                }
            }

            List <Surroundinginfo> surrounding = checkSurrounding(perpCurve, plot, groundCurve);

            return(new Section(Boundary, Room, Core, surrounding, roomName));
        }
        // dual loop not directly connected to plates
        private void half_dualLoop_type_2(int edgeIndex, int triangleIndex)
        {
            Edge edge = iSpringMesh.Edges[edgeIndex];

            // vertex point
            int vertex1 = edge.FirstVertexIndex;
            int vertex2 = edge.SecondVertexIndex;

            Point3d vertexPt1 = iSpringMesh.Vertices[vertex1].Position;
            Point3d vertexPt2 = iSpringMesh.Vertices[vertex2].Position;

            Point3d vertexPtUp1 = topCps[vertex1];
            Point3d vertexPtUp2 = topCps[vertex2];
            Point3d vertexPtUpM = 0.5 * (vertexPtUp1 + vertexPtUp2);
            Point3d ctPtUp1     = (iTangentScale) * vertexPtUp1 + (1 - iTangentScale) * vertexPtUpM;
            Point3d ctPtUp2     = (iTangentScale) * vertexPtUp2 + (1 - iTangentScale) * vertexPtUpM;

            Point3d vertexPtDown1 = bottomCps[vertex1];
            Point3d vertexPtDown2 = bottomCps[vertex2];
            Point3d vertexPtDownM = 0.5 * (vertexPtDown1 + vertexPtDown2);
            Point3d ctPtDown1     = (iTangentScale) * vertexPtDown1 + (1 - iTangentScale) * vertexPtDownM;
            Point3d ctPtDown2     = (iTangentScale) * vertexPtDown2 + (1 - iTangentScale) * vertexPtDownM;

            Point3d upTPI      = topCenterPts[triangleIndex];
            Point3d downTPI    = bottomCenterPts[triangleIndex];
            Point3d ctUpTPI1   = (iTangentScale) * vertexPtUp1 + (1 - iTangentScale) * upTPI;
            Point3d ctDownTPI1 = (iTangentScale) * vertexPtDown1 + (1 - iTangentScale) * downTPI;
            Point3d ctUpTPI2   = (iTangentScale) * vertexPtUp2 + (1 - iTangentScale) * upTPI;
            Point3d ctDownTPI2 = (iTangentScale) * vertexPtDown2 + (1 - iTangentScale) * downTPI;

            Curve right1 = Curve.CreateControlPointCurve(
                new List <Point3d>()
            {
                upTPI, ctUpTPI1, vertexPt1, ctDownTPI1, downTPI
            });

            Curve left1 = Curve.CreateControlPointCurve(
                new List <Point3d>()
            {
                vertexPtUpM, ctPtUp1, vertexPt1, ctPtDown1, vertexPtDownM
            });

            Curve right2 = Curve.CreateControlPointCurve(
                new List <Point3d>()
            {
                upTPI, ctUpTPI2, vertexPt2, ctDownTPI2, downTPI
            });

            Curve left2 = Curve.CreateControlPointCurve(
                new List <Point3d>()
            {
                vertexPtUpM, ctPtUp2, vertexPt2, ctPtDown2, vertexPtDownM
            });

            // sorting sequence

            Brep[] brep1 = Brep.CreateFromLoft(
                new List <Curve>()
            {
                right1, left1
            },
                Point3d.Unset, Point3d.Unset,
                LoftType.Normal,
                false
                );
            if (brep1.Length > 0)
            {
                //oDualLoop.Add(brep1[0]);
                Brep     brepTestNormal = brep1[0];
                BrepFace brepF          = brepTestNormal.Faces[0];
                if (brepF.NormalAt(0, 0).Z > 0)
                {
                    Brep[] brepN1 = Brep.CreateFromLoft(
                        new List <Curve>()
                    {
                        left1, right1
                    },
                        Point3d.Unset, Point3d.Unset,
                        LoftType.Normal,
                        false
                        );
                    if (brep1.Length > 0)
                    {
                        oDualLoop.Add(brepN1[0]);
                    }
                }
                else
                {
                    oDualLoop.Add(brep1[0]);
                }
            }


            Brep[] brep2 = Brep.CreateFromLoft(
                new List <Curve>()
            {
                right2, left2
            },
                Point3d.Unset, Point3d.Unset,
                LoftType.Normal,
                false
                );
            if (brep2.Length > 0)
            {
                //oDualLoop.Add(brep2[0]);
                Brep     brepTestNormal = brep2[0];
                BrepFace brepF          = brepTestNormal.Faces[0];
                if (brepF.NormalAt(0, 0).Z > 0)
                {
                    Brep[] brepN2 = Brep.CreateFromLoft(
                        new List <Curve>()
                    {
                        left2, right2
                    },
                        Point3d.Unset, Point3d.Unset,
                        LoftType.Normal,
                        false
                        );
                    if (brep2.Length > 0)
                    {
                        oDualLoop.Add(brepN2[0]);
                    }
                }
                else
                {
                    oDualLoop.Add(brep2[0]);
                }
            }
        }
Exemplo n.º 7
0
        public override void SolveInstance(IGH_DataAccess DA, out string msg, out GH_RuntimeMessageLevel level)
        {
            msg   = "";
            level = GH_RuntimeMessageLevel.Blank;

            OnComponentLoaded();

            // Input
            var inGH     = new GH_RFEM();
            var inGH2    = new List <GH_RFEM>();
            var iMember  = new RFMember();
            var iCroSecs = new List <RFCroSec>();

            // Output
            var oExtrussion = new List <Brep>();

            // Register input parameters
            if (!DA.GetData(0, ref inGH))
            {
                return;
            }
            iMember = (RFMember)inGH.Value;
            if (!DA.GetDataList(1, inGH2))
            {
                return;
            }
            foreach (var cs in inGH2)
            {
                iCroSecs.Add((RFCroSec)cs.Value);
            }

            // Check input
            var cs_indeces = iCroSecs.Select(x => x.No);

            if (iMember.EndCrossSectionNo == 0) // In case of tension members, etc.
            {
                iMember.EndCrossSectionNo = iMember.StartCrossSectionNo;
            }
            if (!(cs_indeces.Contains(iMember.StartCrossSectionNo)) || (!(cs_indeces.Contains(iMember.EndCrossSectionNo))))
            {
                level = GH_RuntimeMessageLevel.Warning;
                msg   = $"Provide cross sections for member No {iMember.No}.";
                return;
            }

            // Get base geometry
            var crosecs1 = iCroSecs.Where(x => x.No == iMember.StartCrossSectionNo).ToList()[0].Shape;
            var crosecs2 = iCroSecs.Where(x => x.No == iMember.EndCrossSectionNo).ToList()[0].Shape;
            var baseline = iMember.BaseLine.ToCurve();

            // Check geometry
            if ((crosecs1.Sum(x => x.SpanCount) != crosecs2.Sum(x => x.SpanCount)) || (crosecs1.Count != crosecs2.Count))
            {
                level = GH_RuntimeMessageLevel.Warning;
                msg   = $"Provide similar cross sections for member No {iMember.No}.";
                return;
            }

            // Generate tween curves - still on the origin!
            List <Curve> segments;
            int          nCroSecsInter;

            length_segment = Math.Max(length_segment, 0.05); // Check minimum vlaue
            if (baseline.Degree <= 1)
            {
                nCroSecsInter = 2;
            }
            else
            {
                nCroSecsInter = Math.Max((int)(baseline.GetLength() / length_segment), 2);
            }
            var loft_crvs = Component_ExtrudeMembers.GenerateCroSecs(baseline, crosecs1, crosecs2, nCroSecsInter, 0.001, 0.001, out segments);

            // Orient cross sections
            loft_crvs = Component_ExtrudeMembers.OrientCroSecs(loft_crvs, segments, nCroSecsInter, iMember.Frames[0], crosecs1.Count);

            // Extrude members
            for (int i = 0; i < segments.Count; i++)
            {
                for (int j = 0; j < crosecs1.Count; j++)
                {
                    oExtrussion.AddRange(Brep.CreateFromLoft(loft_crvs[i][j], Point3d.Unset, Point3d.Unset, LoftType.Normal, false));
                }
            }

            // Assign output
            DA.SetDataList(0, oExtrussion);
        }
Exemplo n.º 8
0
        public static IGH_GeometricGoo BldgPartToRoof(BuildingPart bldgPart)
        {
            IGH_GeometricGoo roof = bldgPart.PartGoo;
            PolylineCurve    pL   = bldgPart.PartFootprint; ///Already at min height

            bldgPart.PartOsmGeo.Tags.TryGetValue("roof:shape", out string roofShape);

            bldgPart.PartOsmGeo.Tags.TryGetValue("height", out string heightString);
            double height = GetHeightDimensioned(heightString);

            bldgPart.PartOsmGeo.Tags.TryGetValue("min_height", out string minHeightString);
            double min_height = GetHeightDimensioned(minHeightString);

            bldgPart.PartOsmGeo.Tags.TryGetValue("roof:height", out string roofHeightString);
            double roofHeight = GetHeightDimensioned(roofHeightString);

            double facadeHeight = height - roofHeight;

            ///Make sure there's a minium facade height for SF Transamerica Pyramid case
            if (facadeHeight <= 0)
            {
                facadeHeight = 2 * DocumentTolerance();
            }

            bldgPart.PartOsmGeo.Tags.TryGetValue("roof:orientation", out string roofOrientationString);

            bldgPart.PartOsmGeo.Tags.TryGetValue("roof:direction", out string roofDirectionString);
            double   roofDirection       = System.Convert.ToDouble(roofDirectionString);
            Vector3d roofDirectionVector = Plane.WorldXY.YAxis;

            roofDirectionVector.Rotate(RhinoMath.ToRadians(-roofDirection), Plane.WorldXY.ZAxis);

            Line[]  edges    = pL.ToPolyline().GetSegments();
            Point3d centroid = AreaMassProperties.Compute(pL).Centroid;

            switch (roofShape)
            {
            case "pyramidal":
                centroid.Z = height;
                pL.TryGetPolyline(out Polyline pLPolyline);
                Line[]      pLLines         = pLPolyline.GetSegments();
                List <Brep> pyramidBrepList = Brep.CreatePlanarBreps(pL, DocumentTolerance()).ToList();

                if (!string.IsNullOrEmpty(roofHeightString))
                {
                    Plane facadeHeightPlane = Plane.WorldXY;
                    facadeHeightPlane.Translate(new Vector3d(0, 0, facadeHeight));
                    pLPolyline.Transform(Transform.PlanarProjection(facadeHeightPlane));

                    ///Creating individual faces seems to work better/cleaner than lofting curves
                    for (int i = 0; i < pLLines.Count(); i++)
                    {
                        Line bottomEdge = pLLines[i];
                        Line topEdge    = bottomEdge;
                        topEdge.Transform(Transform.PlanarProjection(facadeHeightPlane));
                        pyramidBrepList.Add(Brep.CreateFromCornerPoints(bottomEdge.PointAt(0), bottomEdge.PointAt(1), topEdge.PointAt(1), topEdge.PointAt(0), DocumentTolerance()));
                    }
                }

                foreach (Line edge in pLPolyline.GetSegments())
                {
                    pyramidBrepList.Add(Brep.CreateFromCornerPoints(edge.PointAt(0), centroid, edge.PointAt(1), DocumentTolerance()));
                }

                Brep[] pyramidBrep = Brep.CreateSolid(pyramidBrepList, DocumentTolerance());
                if (pyramidBrep[0].IsSolid)
                {
                    roof = GH_Convert.ToGeometricGoo(pyramidBrep[0]);
                }
                break;

            case "skillion":
                Line   frontEdge     = new Line();
                Line   backEdge      = new Line();
                double frontAngleMin = RhinoMath.ToRadians(90);
                double backAngleMin  = RhinoMath.ToRadians(90);

                foreach (Line edge in edges)
                {
                    Point3d  closestPt       = edge.ClosestPoint(centroid, true);
                    Vector3d perpVector      = closestPt - centroid;
                    double   angleDifference = Vector3d.VectorAngle(roofDirectionVector, perpVector);
                    if (angleDifference < frontAngleMin)
                    {
                        frontEdge     = edge;
                        frontAngleMin = angleDifference;
                    }
                    if (angleDifference > backAngleMin)
                    {
                        backEdge     = edge;
                        backAngleMin = angleDifference;
                    }
                }

                Point3d backEdgeFrom = backEdge.From;
                backEdgeFrom.Z = height;
                Point3d backEdgeTo = backEdge.To;
                backEdgeTo.Z = height;
                Point3d frontEdgeFrom = frontEdge.From;
                frontEdgeFrom.Z = facadeHeight;
                Point3d frontEdgeTo = frontEdge.To;
                frontEdgeTo.Z = facadeHeight;

                List <Point3d> basePtList = new List <Point3d> {
                    backEdge.From, backEdge.To, frontEdge.From, frontEdge.To, backEdge.From
                };
                Polyline       basePolyline = new Polyline(basePtList);
                List <Point3d> topPtList    = new List <Point3d> {
                    backEdgeFrom, backEdgeTo, frontEdgeFrom, frontEdgeTo, backEdgeFrom
                };
                Polyline topPolyline = new Polyline(topPtList);

                ///Creating individual faces seems to work better/cleaner than lofting curves
                List <Brep> skillionBreps = new List <Brep>();
                Line[]      baseLines     = basePolyline.GetSegments();
                Line[]      topLines      = topPolyline.GetSegments();
                for (int i = 0; i < baseLines.Count(); i++)
                {
                    Line bottomEdge = baseLines[i];
                    Line topEdge    = topLines[i];
                    skillionBreps.Add(Brep.CreateFromCornerPoints(bottomEdge.PointAt(0), bottomEdge.PointAt(1), topEdge.PointAt(1), topEdge.PointAt(0), DocumentTolerance()));
                }
                Brep baseSkillion = Brep.CreateFromCornerPoints(backEdge.From, backEdge.To, frontEdge.From, frontEdge.To, DocumentTolerance());
                Brep topSkillion  = Brep.CreateFromCornerPoints(backEdgeFrom, backEdgeTo, frontEdgeFrom, frontEdgeTo, DocumentTolerance());

                skillionBreps.Add(baseSkillion);
                skillionBreps.Add(topSkillion);
                Brep[] skillion = Brep.CreateSolid(skillionBreps, DocumentTolerance());
                if (skillion.Count() > 0)
                {
                    roof = GH_Convert.ToGeometricGoo(skillion[0]);
                }

                break;

            case "gabled":
                ///TODO: Look into getting oriented bbox using front edge as orientation plane,
                ///extrude gable roof profile from face of bbox, trim roof geo from footprint,
                ///loft between footprint and trimmed roof edges and join everything.

                ///Need to simply polylines with colinear segments. Angle tolerance based on Notre-Dame de Paris case
                //pL.Simplify(CurveSimplifyOptions.All, 0, RhinoMath.ToRadians(2)).TryGetPolyline(out Polyline pLSimplified);
                Polyline pLSimplified = pL.ToPolyline();
                pLSimplified.MergeColinearSegments(DocumentAngleTolerance() * 5, true);

                Line[] edgesSimplified = pLSimplified.GetSegments();
                if (edgesSimplified.Count() != 4)
                {
                    break;
                }
                Line        ridge            = new Line();
                Line        eaveOne          = new Line();
                Line        eaveTwo          = new Line();
                Polyline    topGablePolyline = new Polyline();
                List <Brep> gableBreps       = new List <Brep>();

                if ((edgesSimplified[0].Length > edgesSimplified[1].Length && roofOrientationString != "across") || ((edgesSimplified[0].Length < edgesSimplified[1].Length && roofOrientationString == "across")))
                {
                    ridge         = new Line(edgesSimplified[3].PointAt(0.5), edgesSimplified[1].PointAt(0.5));
                    ridge.FromZ   = height;
                    ridge.ToZ     = height;
                    eaveOne       = edgesSimplified[0];
                    eaveOne.FromZ = facadeHeight;
                    eaveOne.ToZ   = facadeHeight;
                    eaveTwo       = edgesSimplified[2];
                    eaveTwo.Flip();
                    eaveTwo.FromZ    = facadeHeight;
                    eaveTwo.ToZ      = facadeHeight;
                    topGablePolyline = new Polyline {
                        eaveOne.From, eaveOne.To, ridge.To, eaveTwo.To, eaveTwo.From, ridge.From, eaveOne.From
                    };

                    Brep[] gableRoof = Brep.CreateFromLoft(new List <Curve> {
                        eaveOne.ToNurbsCurve(), ridge.ToNurbsCurve(), eaveTwo.ToNurbsCurve()
                    }, Point3d.Unset, Point3d.Unset, LoftType.Straight, false);
                    gableRoof[0].Faces.SplitKinkyFaces();
                    gableBreps.Add(gableRoof[0]);
                }

                if ((edgesSimplified[0].Length > edgesSimplified[1].Length && roofOrientationString == "across") || (edgesSimplified[0].Length < edgesSimplified[1].Length && roofOrientationString != "across"))
                {
                    ridge         = new Line(edgesSimplified[0].PointAt(0.5), edgesSimplified[2].PointAt(0.5));
                    ridge.FromZ   = height;
                    ridge.ToZ     = height;
                    eaveOne       = edgesSimplified[1];
                    eaveOne.FromZ = facadeHeight;
                    eaveOne.ToZ   = facadeHeight;
                    eaveTwo       = edgesSimplified[3];
                    eaveTwo.Flip();
                    eaveTwo.FromZ    = facadeHeight;
                    eaveTwo.ToZ      = facadeHeight;
                    topGablePolyline = new Polyline {
                        eaveTwo.From, ridge.From, eaveOne.From, eaveOne.To, ridge.To, eaveTwo.To, eaveTwo.From
                    };

                    Brep[] gableRoof = Brep.CreateFromLoft(new List <Curve> {
                        eaveOne.ToNurbsCurve(), ridge.ToNurbsCurve(), eaveTwo.ToNurbsCurve()
                    }, Point3d.Unset, Point3d.Unset, LoftType.Straight, false);
                    gableRoof[0].Faces.SplitKinkyFaces();
                    gableBreps.Add(gableRoof[0]);
                }

                Brep[] gablewalls = Brep.CreateFromLoft(new List <Curve> {
                    pLSimplified.ToPolylineCurve(), topGablePolyline.ToPolylineCurve()
                }, Point3d.Unset, Point3d.Unset, LoftType.Straight, false);
                gablewalls[0].Faces.SplitKinkyFaces();
                gablewalls[0].MergeCoplanarFaces(DocumentTolerance());
                gableBreps.Add(gablewalls[0]);

                Brep baseGable = Brep.CreateFromCornerPoints(edgesSimplified[0].From, edgesSimplified[0].To, edgesSimplified[2].From, edgesSimplified[2].To, DocumentTolerance());
                gableBreps.Add(baseGable);
                Brep[] gable = Brep.JoinBreps(gableBreps, DocumentTolerance());

                if (gable[0].IsValid)
                {
                    roof = GH_Convert.ToGeometricGoo(gable[0]);
                }
                break;

            default:
                break;
            }

            return(roof);
        }
Exemplo n.º 9
0
        public Brep subFrameBoundary()
        {
            List <Curve> curves = new List <Curve>();

            if (internalStub.Count() == 0)
            {
                curves = new List <Curve>()
                {
                    cornerStub[0].Stub.ToNurbsCurve(),

                    cornerStub[1].Stub.ToNurbsCurve(),

                    cornerStub[3].Stub.ToNurbsCurve(),

                    cornerStub[2].Stub.ToNurbsCurve()
                };
            }
            else if (internalStub.Count() == 2 && frameGrid.Count == 2)
            {
                curves = new List <Curve>()
                {
                    cornerStub[0].Stub.ToNurbsCurve(),
                    internalStub[0].Stub.ToNurbsCurve(),
                    cornerStub[1].Stub.ToNurbsCurve(),

                    cornerStub[3].Stub.ToNurbsCurve(),
                    internalStub[1].Stub.ToNurbsCurve(),
                    cornerStub[2].Stub.ToNurbsCurve()
                };
            }
            else if (internalStub.Count() == 2 && frameGrid.Count == 3)
            {
                curves = new List <Curve>()
                {
                    cornerStub[0].Stub.ToNurbsCurve(),

                    cornerStub[1].Stub.ToNurbsCurve(),
                    internalStub[1].Stub.ToNurbsCurve(),
                    cornerStub[3].Stub.ToNurbsCurve(),

                    cornerStub[2].Stub.ToNurbsCurve(),
                    internalStub[0].Stub.ToNurbsCurve()
                };
            }

            else
            {
                curves = new List <Curve>()
                {
                    cornerStub[0].Stub.ToNurbsCurve(),
                    internalStub[0].Stub.ToNurbsCurve(),
                    cornerStub[1].Stub.ToNurbsCurve(),
                    internalStub[3].Stub.ToNurbsCurve(),
                    cornerStub[3].Stub.ToNurbsCurve(),
                    internalStub[4].Stub.ToNurbsCurve(),
                    cornerStub[2].Stub.ToNurbsCurve(),
                    internalStub[1].Stub.ToNurbsCurve()
                };
            }


            Brep[] brep = Brep.CreateFromLoft(curves, Point3d.Unset, Point3d.Unset, LoftType.Straight, true);
            ;
            return(MakeFrameBox(brep));
        }
Exemplo n.º 10
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and
        /// to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            var curves     = new DataTree <Polyline>();
            var points     = new DataTree <Point3d>();
            var frames     = new DataTree <Plane>();
            int collisions = 0;

            var gCurves = new GH_Structure <GH_Curve>();
            var gPoints = new GH_Structure <GH_Point>();
            var gFrames = new GH_Structure <GH_Plane>();

            if (!DA.GetDataTree(0, out gPoints))
            {
                return;
            }
            if (!DA.GetDataTree(1, out gFrames))
            {
                return;
            }
            DA.GetData(2, ref collisions);
            if (!DA.GetDataTree(3, out gCurves))
            {
                return;
            }

            var tempPoint = new Point3d();

            foreach (var path in gPoints.Paths)
            {
                var branch = gPoints.get_Branch(path);

                foreach (var item in branch)
                {
                    GH_Convert.ToPoint3d(item, ref tempPoint, GH_Conversion.Both);

                    points.Add(tempPoint, path);
                }
            }

            Curve tempCurve  = null;
            var   tempPoly   = new Polyline();
            var   curvesList = new List <Curve>();

            foreach (var path in gCurves.Paths)
            {
                var branch = gCurves.get_Branch(path);

                foreach (var item in branch)
                {
                    GH_Convert.ToCurve(item, ref tempCurve, GH_Conversion.Both);
                    tempCurve.TryGetPolyline(out tempPoly);

                    curves.Add(tempPoly, path);
                }
            }

            var tempPlane = new Plane();

            foreach (var path in gFrames.Paths)
            {
                var branch = gFrames.get_Branch(path);

                foreach (var item in branch)
                {
                    GH_Convert.ToPlane(item, ref tempPlane, GH_Conversion.Both);
                    frames.Add(tempPlane, path);
                }
            }

            int             branches = curves.BranchCount;
            List <Polyline> listOut  = new List <Polyline>();

            if (branches == 1)
            {
                listOut.AddRange(curves.Branch(0));
            }

            if (branches == 2)
            {
                if (collisions != 0)
                {
                    int branchOneCount = curves.Branch(0).Count;

                    var pointComparer = points.Branch(0)[curves.Branch(0).Count - 1].Z;

                    var comparer = new List <double>();

                    var listOfCurves    = new DataTree <Polyline>();
                    var listOfCurvesOne = new List <Polyline>();
                    var listOfCurvesTwo = new List <Polyline>();

                    listOfCurves.AddRange(curves.Branch(0));

                    var listOfPlanes    = new List <Plane>();
                    var listOfPlanesOne = new List <Plane>();

                    listOfPlanes.AddRange(frames.Branch(0));

                    var pathOne = new GH_Path(1);
                    var pathTwo = new GH_Path(2);

                    for (int i = 0; i < curves.Branch(1).Count; ++i)
                    {
                        comparer.Add(points.Branch(1)[i].Z);

                        if (pointComparer >= comparer[i])
                        {
                            listOfCurves.Add(curves.Branch(1)[i], pathOne);
                        }

                        else
                        {
                            listOfCurvesOne.Add(curves.Branch(1)[i]);
                            listOfPlanesOne.Add(frames.Branch(1)[i]);
                        }
                    }

                    var listOfUnions = RegionUnion(listOfCurves, listOfPlanes);

                    listOut.AddRange(listOfUnions);
                    listOut.AddRange(listOfCurvesOne);
                }

                else
                {
                    for (int i = 0; i < branches; ++i)
                    {
                        listOut.AddRange(curves.Branch(i));
                    }
                }
            }

            if (branches == 3)
            {
                if (collisions != 0)
                {
                    int branchOneCount = curves.Branch(0).Count;

                    var pointComparer    = points.Branch(0)[curves.Branch(0).Count - 1].Z;
                    var pointComparerOne = points.Branch(1)[curves.Branch(1).Count - 1].Z;

                    var comparer = new List <double>();

                    var listOfCurves    = new DataTree <Polyline>();
                    var listOfCurvesOne = new DataTree <Polyline>();
                    var listOfCurvesTwo = new List <Polyline>();

                    listOfCurves.AddRange(curves.Branch(0));

                    var listOfPlanes    = new List <Plane>();
                    var listOfPlanesOne = new List <Plane>();

                    listOfPlanes.AddRange(frames.Branch(0));

                    var pathOne = new GH_Path(1);
                    var pathTwo = new GH_Path(2);

                    for (int i = 0; i < curves.Branch(1).Count; ++i)
                    {
                        comparer.Add(points.Branch(1)[i].Z);

                        if (pointComparer >= comparer[i])
                        {
                            listOfCurves.Add(curves.Branch(1)[i], pathOne);
                        }

                        else
                        {
                            listOfCurvesOne.Add(curves.Branch(1)[i], pathOne);
                            listOfCurvesOne.Add(curves.Branch(2)[i], pathTwo);
                            listOfPlanesOne.Add(frames.Branch(1)[i]);
                        }
                    }

                    var comparerOne = new List <double>();

                    for (int i = 0; i < curves.Branch(2).Count; ++i)
                    {
                        comparerOne.Add(points.Branch(2)[i].Z);

                        if (pointComparer >= comparerOne[i])
                        {
                            listOfCurves.Add(curves.Branch(2)[i], pathTwo);
                        }

                        if (pointComparerOne >= comparerOne[i])
                        {
                        }

                        else
                        {
                            listOfCurvesTwo.Add(curves.Branch(2)[i]);
                        }
                    }

                    List <Polyline> listOfUnionObjs    = RegionUnion(listOfCurves, listOfPlanes);
                    List <Polyline> listOfUnionObjsOne = RegionUnion(listOfCurvesOne, listOfPlanesOne);

                    listOut.AddRange(listOfUnionObjs);
                    listOut.AddRange(listOfUnionObjsOne);
                    listOut.AddRange(listOfCurvesTwo);
                }

                else
                {
                    for (int i = 0; i < branches; ++i)
                    {
                        listOut.AddRange(curves.Branch(i));
                    }
                }
            }

            DA.SetDataList(0, listOut);

            var volume       = new DataTree <Brep>();
            var polyToCurves = new DataTree <Curve>();

            for (int i = 0; i < branches; ++i)
            {
                var path = new GH_Path(i);

                for (int j = 0; j < curves.Branch(i).Count; ++j)
                {
                    polyToCurves.Add(curves.Branch(i)[j].ToNurbsCurve(), path);
                }
            }

            for (int i = 0; i < branches; ++i)
            {
                volume.Add(Brep.CreateFromLoft(polyToCurves.Branch(i), Point3d.Unset, Point3d.Unset, LoftType.Tight, false)[0].CapPlanarHoles(0.0001), new GH_Path(i));
            }

            DA.SetDataTree(1, volume);

            DA.SetData(2, branches);
        }
Exemplo n.º 11
0
        public override bool Construct(bool append = false)
        {
            debug = new List <object>();

            var beams = new Beam[2];

            beams[0] = (FirstHalf.Element as BeamElement).Beam;
            beams[1] = (SecondHalf.Element as BeamElement).Beam;

            var planes = new Plane[2];

            for (int i = 0; i < 2; ++i)
            {
                planes[i] = beams[i].GetPlane(Parts[i].Parameter);
            }

            // TODO: Align curve tangents and ends

            var endPlanes = new Plane[2];

            endPlanes[0] = beams[0].GetPlane(planes[0].Origin - planes[0].ZAxis * TenonLength * 0.5);
            endPlanes[1] = beams[1].GetPlane(planes[1].Origin + planes[1].ZAxis * TenonLength * 0.5);

            var x0 = endPlanes[0].XAxis;
            var x1 = endPlanes[1].XAxis;

            if (x0 * x1 < 0)
            {
                x1 = -x1;
            }

            var common = (x0 + x1) / 2;

            endPlanes[0] = new Plane(endPlanes[0].Origin, common, endPlanes[0].YAxis);
            endPlanes[1] = new Plane(endPlanes[1].Origin, common, endPlanes[1].YAxis);

            debug.Add(planes[0]);
            debug.Add(planes[1]);
            debug.Add(endPlanes[0]);
            debug.Add(endPlanes[1]);

            double third  = beams[0].Width / 3;
            double height = Math.Max(beams[0].Height, beams[1].Height);

            var topPts = new Point3d[6];
            var btmPts = new Point3d[6];

            topPts[0] = endPlanes[0].PointAt(-beams[0].Width * 0.5 - Added, height * 0.5 + Added);
            topPts[1] = endPlanes[0].PointAt(-third * 0.5, height * 0.5 + Added);
            topPts[2] = endPlanes[1].PointAt(-third * 0.5, height * 0.5 + Added);
            topPts[3] = endPlanes[1].PointAt(third * 0.5, height * 0.5 + Added);
            topPts[4] = endPlanes[0].PointAt(third * 0.5, height * 0.5 + Added);
            topPts[5] = endPlanes[0].PointAt(beams[0].Width * 0.5 + Added, height * 0.5 + Added);

            var topOutline = new Polyline(topPts).ToNurbsCurve();

            btmPts[0] = endPlanes[0].PointAt(-beams[0].Width * 0.5 - Added, -height * 0.5 - Added);
            btmPts[1] = endPlanes[0].PointAt(-third * 0.5, -height * 0.5 - Added);
            btmPts[2] = endPlanes[1].PointAt(-third * 0.5, -height * 0.5 - Added);
            btmPts[3] = endPlanes[1].PointAt(third * 0.5, -height * 0.5 - Added);
            btmPts[4] = endPlanes[0].PointAt(third * 0.5, -height * 0.5 - Added);
            btmPts[5] = endPlanes[0].PointAt(beams[0].Width * 0.5 + Added, -height * 0.5 - Added);

            var btmOutline = new Polyline(btmPts).ToNurbsCurve();

            for (int i = 0; i < 6; ++i)
            {
                debug.Add(topPts[i]);
                debug.Add(btmPts[i]);
            }

            debug.Add(topOutline);
            debug.Add(btmOutline);

            var tenonCutter = Brep.CreateFromLoft(new Curve[] { topOutline, btmOutline }, Point3d.Unset, Point3d.Unset, LoftType.Straight, false)[0];

            tenonCutter.Faces.SplitKinkyFaces();

            FirstHalf.Geometry.Add(tenonCutter);
            SecondHalf.Geometry.Add(tenonCutter);

            // Create dowels
            var    dowelPlanes   = new Plane[2];
            double dowelDistance = beams[0].Height / 3;

            dowelPlanes[0] = new Plane(planes[0].Origin + planes[0].YAxis * dowelDistance * 0.5, planes[0].XAxis);
            dowelPlanes[1] = new Plane(planes[0].Origin - planes[0].YAxis * dowelDistance * 0.5, planes[0].XAxis);

            dowelPlanes[0].Transform(Transform.Translation(dowelPlanes[0].ZAxis * -DowelLength * 0.5));
            dowelPlanes[1].Transform(Transform.Translation(dowelPlanes[1].ZAxis * -DowelLength * 0.5));

            for (int i = 0; i < 2; ++i)
            {
                dowelPlanes[i].Transform(Transform.Rotation(DowelInclination, planes[0].ZAxis, planes[0].Origin));
            }

            var dowels = new Brep[2];

            for (int i = 0; i < 2; ++i)
            {
                dowels[i] = new Cylinder(
                    new Circle(dowelPlanes[i], DowelDiameter * 0.5), DowelLength).ToBrep(true, true);
            }

            FirstHalf.Geometry.AddRange(dowels);
            SecondHalf.Geometry.AddRange(dowels);

            return(true);
        }
Exemplo n.º 12
0
        private void createStripe(int firstVertexIndex, int secondVertexIndex, int thirdVertexIndex)
        {
            Point3d a = bottomCps[firstVertexIndex];
            Point3d A = topCps[firstVertexIndex];

            Point3d aA = 0.5 * (a + A);

            Point3d b = bottomCps[secondVertexIndex];
            Point3d B = topCps[secondVertexIndex];

            Point3d c = bottomCps[thirdVertexIndex];
            Point3d C = topCps[thirdVertexIndex];

            Point3d ab = 0.5 * (a + b);
            Point3d AB = 0.5 * (A + B);

            Point3d ac = 0.5 * (a + c);
            Point3d AC = 0.5 * (A + C);

            Point3d m = 0.33333 * (ab + ac + 0.5 * (b + c));
            Point3d M = 0.33333 * (AB + AC + 0.5 * (B + C));

            Point3d AAB = iTangentScale * A + (1.0 - iTangentScale) * AB;
            Point3d aab = iTangentScale * a + (1.0 - iTangentScale) * ab;

            Point3d AAC = iTangentScale * A + (1.0 - iTangentScale) * AC;
            Point3d aac = iTangentScale * a + (1.0 - iTangentScale) * ac;

            Curve profileCurve1 = Curve.CreateControlPointCurve(new List <Point3d>()
            {
                AB, AAB, aA, aab, ab
            });
            Curve profileCurve2 = Curve.CreateControlPointCurve(new List <Point3d>()
            {
                AC, AAC, aA, aac, ac
            });



            // =============================================
            // Stripe as one single (trimmed) surface
            // =============================================

            if (menuItemValue_Standard)
            {
                Curve profileCurveExtended1 = Curve.JoinCurves(
                    new List <Curve>()
                {
                    new LineCurve(B, AB), profileCurve1, new LineCurve(ab, b)
                },
                    documentTolerance,
                    true)[0];

                Curve profileCurveExtended2 = Curve.JoinCurves(
                    new List <Curve>()
                {
                    new LineCurve(C, AC), profileCurve2, new LineCurve(ac, c)
                },
                    documentTolerance,
                    true)[0];

                Brep brep = Brep.CreateFromLoft(
                    new List <Curve>()
                {
                    profileCurveExtended1, profileCurveExtended2
                },
                    Point3d.Unset, Point3d.Unset,
                    LoftType.Normal,
                    false
                    )[0];

                double   offsetAmount = 0.2;
                Vector3d normal;
                Brep[]   breps;

                normal = Vector3d.CrossProduct(B - A, C - A);

                Point3d A_ = A + offsetAmount * normal;

                breps = brep.Trim(new Plane(A_, AB, M), documentTolerance);
                if (breps.Length > 0)
                {
                    brep = breps[0];
                }
                else
                {
                    oDebugBreps2.Add(brep); return;
                }

                breps = brep.Trim(new Plane(A_, M, AC), documentTolerance);
                if (breps.Length > 0)
                {
                    brep = breps[0];
                }
                else
                {
                    oDebugBreps2.Add(brep); return;
                }

                normal = Vector3d.CrossProduct(b - a, c - a);

                Point3d a_ = a - offsetAmount * normal;

                breps = brep.Trim(new Plane(a_, m, ab), documentTolerance);
                if (breps.Length > 0)
                {
                    brep = breps[0];
                }
                else
                {
                    oDebugBreps2.Add(brep); return;
                }

                breps = brep.Trim(new Plane(a_, ac, m), documentTolerance);
                if (breps.Length > 0)
                {
                    brep = breps[0];
                }
                else
                {
                    oDebugBreps2.Add(brep); return;
                }

                oStripes.Add(brep);
            }

            // =============================================
            // Stripe as three separate surfaces
            // =============================================

            //profileCurve1.Domain = new Interval(0.0, 1.0);
            //profileCurve2.Domain = new Interval(0.0, 1.0);

            //Curve[] profileCurves1 = profileCurve1.Split(0.5);
            //Curve[] profileCurves2 = profileCurve2.Split(0.5);

            //oStructuralInteriorStripes.Add(
            //    Brep.CreateFromLoft(
            //       new List<Curve>() { new LineCurve(m, ac), new LineCurve(m, ab) },
            //       Point3d.Unset, Point3d.Unset,
            //       LoftType.Normal,
            //       false
            //       )[0]
            //   );

            //oStructuralInteriorStripes.Add(
            //    Brep.CreateFromLoft(
            //       new List<Curve>() { profileCurves1[1], profileCurves2[1] },
            //       Point3d.Unset, Point3d.Unset,
            //       LoftType.Normal,
            //       false
            //       )[0]
            //   );

            //oStructuralExteriorStripes.Add(
            //    Brep.CreateFromLoft(
            //       new List<Curve>() { profileCurves1[0], profileCurves2[0] },
            //       Point3d.Unset, Point3d.Unset,
            //       LoftType.Normal,
            //       false
            //       )[0]
            //   );

            //oStructuralExteriorStripes.Add(
            //    Brep.CreateFromLoft(
            //       new List<Curve>() { new LineCurve(M, AB), new LineCurve(M, AC) },
            //       Point3d.Unset, Point3d.Unset,
            //       LoftType.Normal,
            //       false
            //       )[0]
            //   );


            // =============================================
            // Stripe without triangles
            // =============================================

            if (menuItemValue_StructuralAnalysis)
            {
                profileCurve1.Domain = new Interval(0.0, 1.0);
                profileCurve2.Domain = new Interval(0.0, 1.0);

                Curve[] profileCurves1 = profileCurve1.Split(0.5);
                Curve[] profileCurves2 = profileCurve2.Split(0.5);

                oStructuralInteriorStripes.Add(
                    Brep.CreateFromLoft(
                        new List <Curve>()
                {
                    profileCurves1[1], profileCurves2[1]
                },
                        Point3d.Unset, Point3d.Unset,
                        LoftType.Normal,
                        false
                        )[0]
                    );

                oStructuralExteriorStripes.Add(
                    Brep.CreateFromLoft(
                        new List <Curve>()
                {
                    profileCurves1[0], profileCurves2[0]
                },
                        Point3d.Unset, Point3d.Unset,
                        LoftType.Normal,
                        false
                        )[0]
                    );
            }
        }
Exemplo n.º 13
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            double tolerance = doc.ModelAbsoluteTolerance;

            List <Curve> icur = new List <Curve>();

            GetObject gcr = new Rhino.Input.Custom.GetObject();

            gcr.SetCommandPrompt("Select reference circles for drill. (No curves)");
            gcr.GeometryFilter              = Rhino.DocObjects.ObjectType.Curve;
            gcr.GroupSelect                 = true;
            gcr.SubObjectSelect             = true;
            gcr.DeselectAllBeforePostSelect = true;
            gcr.OneByOnePostSelect          = false;
            gcr.GetMultiple(1, 0);

            for (int ie = 0; ie < gcr.ObjectCount; ie++)
            {
                Rhino.DocObjects.ObjRef      objref = gcr.Object(ie);
                Rhino.DocObjects.RhinoObject obj    = objref.Object();
                if (obj == null)
                {
                    return(Result.Failure);
                }
                Curve refcr = objref.Curve();
                if (refcr == null)
                {
                    return(Result.Failure);
                }
                obj.Select(false);

                icur.Add(refcr);
            }

            while (true)
            {
                m_escape_key_pressed       = false;
                RhinoApp.EscapeKeyPressed += RhinoApp_EscapeKeyPressed;


                List <Curve> curveDrill = new List <Curve>();

                Point3d centerTop = new Point3d(0, 0, (headDrill + topDrill) * drillScale);
                Circle  circleTop = new Circle(centerTop, ancheadDrill / 2 * drillScale);
                Curve   curveTop  = circleTop.ToNurbsCurve();
                curveDrill.Add(curveTop);
                Point3d centerMid = new Point3d(0, 0, topDrill * drillScale);
                Circle  circleMid = new Circle(centerMid, drillScale / 2);
                Curve   curveMid  = circleMid.ToNurbsCurve();
                curveDrill.Add(curveMid);
                Circle circleBase = new Circle(drillScale / 2);
                Curve  curveBase  = circleBase.ToNurbsCurve();
                curveDrill.Add(curveBase);
                Point3d centerLow = new Point3d(0, 0, -midDrill * drillScale);
                Circle  circleLow = new Circle(centerLow, ancDrill / 2 * drillScale);
                Curve   curveLow  = circleLow.ToNurbsCurve();
                curveDrill.Add(curveLow);
                if (bottDrill != 0)
                {
                    Point3d centerBot = new Point3d(0, 0, (-midDrill - bottDrill) * drillScale);
                    Circle  circleBot = new Circle(centerBot, ancDrill / 2 * drillScale);
                    Curve   curveBot  = circleBot.ToNurbsCurve();
                    curveDrill.Add(curveBot);
                }


                Brep[] cylBrep1     = Brep.CreateFromLoft(curveDrill, Point3d.Unset, Point3d.Unset, LoftType.Straight, false);
                Brep[] cylBrep2     = Brep.CreateBooleanUnion(cylBrep1, tolerance);
                Brep   cylBrepFinal = cylBrep1[0];
                cylBrepFinal = cylBrepFinal.CapPlanarHoles(tolerance);


                string instDefCount = DateTime.Now.ToString("ddMMyyyyHHmmss");
                Brep[] brepArray    = new Brep[1] {
                    cylBrepFinal
                };
                var drillIndex = doc.InstanceDefinitions.Add("Drill" + instDefCount, "RefDrill 1mm", Point3d.Origin, brepArray);

                foreach (Curve c in icur)
                {
                    Circle circleDrill = new Circle();
                    c.TryGetCircle(out circleDrill, tolerance);

                    double   radiusDrill = circleDrill.Diameter;
                    Point3d  center      = circleDrill.Center;
                    Vector3d moveV       = new Vector3d(center);
                    Vector3d zaxis       = new Vector3d(0.0, 0.0, 1.0);
                    Plane    planeOr     = new Plane(center, zaxis);
                    Plane    planeNew    = circleDrill.Plane;
                    var      transform1  = Transform.Translation(moveV);
                    var      transform2  = Transform.Scale(center, radiusDrill);
                    var      transform3  = Transform.PlaneToPlane(planeOr, planeNew);

                    var stoneA = doc.Objects.AddInstanceObject(drillIndex, transform1);
                    var stoneB = doc.Objects.Transform(stoneA, transform2, true);
                    var stoneC = doc.Objects.Transform(stoneB, transform3, true);

                    ids.Add(stoneC);

                    doc.Views.Redraw();
                }


                GetOption go = new Rhino.Input.Custom.GetOption();
                go.SetCommandPrompt("Set drill parameters.");
                go.AcceptNothing(true);

                var drillHead    = new Rhino.Input.Custom.OptionDouble(headDrill);
                var drillAncHead = new Rhino.Input.Custom.OptionDouble(ancheadDrill);
                var drillTop     = new Rhino.Input.Custom.OptionDouble(topDrill);
                var drillMid     = new Rhino.Input.Custom.OptionDouble(midDrill);
                var drillAnc     = new Rhino.Input.Custom.OptionDouble(ancDrill);
                var drillBott    = new Rhino.Input.Custom.OptionDouble(bottDrill);
                var scaleDrill   = new Rhino.Input.Custom.OptionDouble(drillScale);
                go.AddOptionDouble("Top", ref drillHead);
                go.AddOptionDouble("TopAngle", ref drillAncHead);
                go.AddOptionDouble("Mid", ref drillTop);
                go.AddOptionDouble("Bottom", ref drillMid);
                go.AddOptionDouble("BottomAngle", ref drillAnc);
                go.AddOptionDouble("Tail", ref drillBott);
                go.AddOptionDouble("Scale", ref scaleDrill);


                GetResult res = go.Get();

                if (m_escape_key_pressed)
                {
                    break;
                }



                topDrill     = drillTop.CurrentValue;
                midDrill     = drillMid.CurrentValue;
                ancDrill     = drillAnc.CurrentValue;
                bottDrill    = drillBott.CurrentValue;
                drillScale   = scaleDrill.CurrentValue;
                headDrill    = drillHead.CurrentValue;
                ancheadDrill = drillAncHead.CurrentValue;


                if (res == GetResult.Nothing)
                {
                    break;
                }

                doc.Objects.Delete(ids, true);
            }
            RhinoApp.EscapeKeyPressed -= RhinoApp_EscapeKeyPressed;

            doc.Groups.Add(ids);

            return(Result.Success);
        }
Exemplo n.º 14
0
        /// <summary>
        /// Return bounding geometry of the wall
        /// Bounding geometry is the geometry wrapping Stacked or Curtain walls (different from Bounding Box).
        /// For Basic Walls the bounding geometry is identical to the default wall geometry
        /// </summary>
        /// <returns>Bounding geometry of a wall</returns>
        public static Rhino.Geometry.Brep ComputeWallBoundingGeometry(this Wall wall)
        {
            // TODO: brep creation might be crude and could use performance improvements

            // extract global properties
            // e.g. base height, thickness, ...
            var height    = wall.get_Parameter(BuiltInParameter.WALL_USER_HEIGHT_PARAM).AsDouble() * Revit.ModelUnits;
            var thickness = wall.GetWidth() * Revit.ModelUnits;
            // construct a base offset plane that is used later to offset base curves
            var offsetPlane   = Rhino.Geometry.Plane.WorldXY;
            var baseElevation = wall.get_Parameter(BuiltInParameter.WALL_BASE_OFFSET).AsDouble();

            // calculate slant
            double topOffset = double.NaN;

#if REVIT_2021
            // if wall slant is supported grab the slant angle
            var slantParam = wall.get_Parameter(BuiltInParameter.WALL_SINGLE_SLANT_ANGLE_FROM_VERTICAL);
            if (slantParam is Parameter)
            {
                // and calculate the cuvre offset at the top based on the curve slant angle
                //     O = top offset distance
                // ---------
                //  \      |
                //   \  S = slant angle
                //    \    |
                //     \   | H = wall height
                //      \  |
                //       \ |
                //        \|
                var slantAngle = slantParam.AsDouble();
                if (slantAngle > 0)
                {
                    topOffset = height * (Math.Sin(slantAngle) / Math.Abs(Math.Cos(slantAngle)));
                }
            }
#endif


            // get the base curve of wall (center curve), and wall thickness
            // this will be used to create a bottom-profile of the wall
            var baseCurve = ((LocationCurve)wall.Location).Curve.ToCurve();
            // transform to where the wall base is
            baseCurve.Translate(0, 0, baseElevation);

            // create the base curves on boths sides
            var side1BottomCurve = baseCurve.Offset(offsetPlane, thickness / 2.0, 0.1, Rhino.Geometry.CurveOffsetCornerStyle.None)[0];
            var side2BottomCurve = baseCurve.Offset(offsetPlane, thickness / -2.0, 0.1, Rhino.Geometry.CurveOffsetCornerStyle.None)[0];

            // create top curves, by moving a duplicate of base curves to top
            var fromPoint     = side1BottomCurve.PointAtStart;
            var side1TopCurve = side1BottomCurve.DuplicateCurve();
            side1TopCurve.Translate(0, 0, fromPoint.Z + height);
            var side2TopCurve = side2BottomCurve.DuplicateCurve();
            side2TopCurve.Translate(0, 0, fromPoint.Z + height);

            // offset the top curves to get the slanted wall top curves, based on the previously calculated offset distance
            if (topOffset > 0)
            {
                side1TopCurve = side1TopCurve.Offset(offsetPlane, topOffset, 0.1, CurveOffsetCornerStyle.None)[0];
                side2TopCurve = side2TopCurve.Offset(offsetPlane, topOffset, 0.1, CurveOffsetCornerStyle.None)[0];
            }

            // build a list of curve-pairs for the 6 sides
            var sideCurvePairs = new List <Tuple <Rhino.Geometry.Curve, Rhino.Geometry.Curve> >()
            {
                // side 1
                new Tuple <Rhino.Geometry.Curve, Rhino.Geometry.Curve>(side1BottomCurve, side1TopCurve),
                // side 2
                new Tuple <Rhino.Geometry.Curve, Rhino.Geometry.Curve>(side2BottomCurve, side2TopCurve),
                // bottom
                new Tuple <Rhino.Geometry.Curve, Rhino.Geometry.Curve>(side1BottomCurve, side2BottomCurve),
                // start side
                new Tuple <Rhino.Geometry.Curve, Rhino.Geometry.Curve>(
                    new Rhino.Geometry.Line(side1BottomCurve.PointAtStart, side1TopCurve.PointAtStart).ToNurbsCurve(),
                    new Rhino.Geometry.Line(side2BottomCurve.PointAtStart, side2TopCurve.PointAtStart).ToNurbsCurve()
                    ),
                // top
                new Tuple <Rhino.Geometry.Curve, Rhino.Geometry.Curve>(side1TopCurve, side2TopCurve),
                // end side
                new Tuple <Rhino.Geometry.Curve, Rhino.Geometry.Curve>(
                    new Rhino.Geometry.Line(side1TopCurve.PointAtEnd, side1BottomCurve.PointAtEnd).ToNurbsCurve(),
                    new Rhino.Geometry.Line(side2TopCurve.PointAtEnd, side2BottomCurve.PointAtEnd).ToNurbsCurve()
                    )
            };

            // build breps for each side and add to list
            var finalBreps = new List <Brep>();
            foreach (var curvePair in sideCurvePairs)
            {
                var loft = Brep.CreateFromLoft(
                    curves: new List <Rhino.Geometry.Curve>()
                {
                    curvePair.Item1, curvePair.Item2
                },
                    start: Point3d.Unset,
                    end: Point3d.Unset,
                    loftType: LoftType.Normal,
                    closed: false
                    ).First(); // grab the first loft
                finalBreps.Add(loft);
            }
            // join all the breps into one
            return(Brep.JoinBreps(finalBreps, 0.1).First());
        }
Exemplo n.º 15
0
        public Brep GetGlulamFace(Side side)
        {
            Plane[]  planes;
            double[] parameters;

            int N = Math.Max(Data.Samples, 6);

            GenerateCrossSectionPlanes(N, out planes, out parameters, Data.InterpolationType);

            double hWidth = this.Width / 2;
            double hHeight = this.Height / 2;
            double x1, y1, x2, y2;

            x1 = y1 = x2 = y2 = 0;
            Rectangle3d face;

            GetSectionOffset(out double offsetX, out double offsetY);

            switch (side)
            {
            case (Side.Back):
                face = new Rectangle3d(planes.First(), new Interval(-hWidth + offsetX, hWidth + offsetX), new Interval(-hHeight + offsetY, hHeight + offsetY));
                return(Brep.CreateFromCornerPoints(face.Corner(0), face.Corner(1), face.Corner(2), face.Corner(3), 0.001));

            case (Side.Front):
                face = new Rectangle3d(planes.Last(), new Interval(-hWidth + offsetX, hWidth + offsetX), new Interval(-hHeight + offsetY, hHeight + offsetY));
                return(Brep.CreateFromCornerPoints(face.Corner(0), face.Corner(1), face.Corner(2), face.Corner(3), 0.001));

            case (Side.Left):
                x1 = hWidth + offsetX; y1 = hHeight + offsetY;
                x2 = hWidth + offsetX; y2 = -hHeight + offsetY;
                break;

            case (Side.Right):
                x1 = -hWidth + offsetX; y1 = hHeight + offsetY;
                x2 = -hWidth + offsetX; y2 = -hHeight + offsetY;
                break;

            case (Side.Top):
                x1 = hWidth + offsetX; y1 = hHeight + offsetY;
                x2 = -hWidth + offsetX; y2 = hHeight + offsetY;
                break;

            case (Side.Bottom):
                x1 = hWidth + offsetX; y1 = -hHeight + offsetY;
                x2 = -hWidth + offsetX; y2 = -hHeight + offsetY;
                break;
            }

            Curve[] rules = new Curve[parameters.Length];
            for (int i = 0; i < planes.Length; ++i)
            {
                rules[i] = new Line(
                    planes[i].Origin + planes[i].XAxis * x1 + planes[i].YAxis * y1,
                    planes[i].Origin + planes[i].XAxis * x2 + planes[i].YAxis * y2
                    ).ToNurbsCurve();
            }

            Brep[] loft = Brep.CreateFromLoft(rules, Point3d.Unset, Point3d.Unset, LoftType.Normal, false);
            if (loft == null || loft.Length < 1)
            {
                throw new Exception("Glulam::GetGlulamFace::Loft failed!");
            }

            Brep brep = loft[0];

            return(brep);
        }
Exemplo n.º 16
0
        public override Brep ToBrep(double offset = 0.0)
        {
            //Curve CL = Centreline.Extend(CurveEnd.Both, offset, CurveExtensionStyle.Line);
            Curve  CL     = Centreline;
            double Length = CL.GetLength();
            double hW     = Data.NumWidth * Data.LamWidth / 2 + offset;
            double hH     = Data.NumHeight * Data.LamHeight / 2 + offset;

            double[] DivParams = new double[] { CL.Domain.Min, CL.Domain.Max };

            m_section_corners = CornerGenerator(offset);



            Curve[][] LoftCurves = new Curve[4][];

            for (int i = 0; i < 4; ++i)
            {
                LoftCurves[i] = new Curve[2];
            }

            Rhino.Geometry.Transform xform;
            Line l1 = new Line(m_section_corners[0], m_section_corners[1]);
            Line l2 = new Line(m_section_corners[1], m_section_corners[2]);
            Line l3 = new Line(m_section_corners[2], m_section_corners[3]);
            Line l4 = new Line(m_section_corners[3], m_section_corners[0]);
            Line temp;

            for (int i = 0; i < DivParams.Length; ++i)
            {
                Plane p = GetPlane(DivParams[i]);
                xform            = Rhino.Geometry.Transform.PlaneToPlane(Plane.WorldXY, p);
                temp             = l1; temp.Transform(xform);
                LoftCurves[0][i] = temp.ToNurbsCurve();
                temp             = l2; temp.Transform(xform);
                LoftCurves[1][i] = temp.ToNurbsCurve();
                temp             = l3; temp.Transform(xform);
                LoftCurves[2][i] = temp.ToNurbsCurve();
                temp             = l4; temp.Transform(xform);
                LoftCurves[3][i] = temp.ToNurbsCurve();
            }

            Brep brep = new Brep();

            for (int i = 0; i < 4; ++i)
            {
                Brep[] loft = Brep.CreateFromLoft(LoftCurves[i], Point3d.Unset, Point3d.Unset, LoftType.Normal, false);
                if (loft == null || loft.Length < 1)
                {
                    continue;
                }
                for (int j = 0; j < loft.Length; ++j)
                {
                    brep.Append(loft[j]);
                }
            }

            brep.JoinNakedEdges(Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance);
            brep = brep.CapPlanarHoles(Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance);

            //brep.UserDictionary.Set("glulam", GetArchivableDictionary());


            return(brep);
        }
Exemplo n.º 17
0
        public Brep GetSideSurface(int side, double offset, double width, double extension = 0.0, bool flip = false)
        {
            // TODO: Create access for Glulam ends, with offset (either straight or along Centreline).

            side = side.Modulus(2);
            double w2 = width / 2;

            Curve c = Centreline.DuplicateCurve();

            if (extension > 0.0)
            {
                c = c.Extend(CurveEnd.Both, extension, CurveExtensionStyle.Smooth);
            }

            int N = Math.Max(6, Data.Samples);

            GenerateCrossSectionPlanes(N, out Plane[] planes, out double[] parameters, Data.InterpolationType);

            Curve[] rules = new Curve[planes.Length];

            double offsetX, offsetY;

            GetSectionOffset(out offsetX, out offsetY);

            for (int i = 0; i < planes.Length; ++i)
            {
                Plane p = planes[i];
                if (side == 0)
                {
                    rules[i] = new Line(
                        p.Origin + p.XAxis * (offset + offsetX) + p.YAxis * (w2 + offsetY),
                        p.Origin + p.XAxis * (offset + offsetX) - p.YAxis * (w2 - offsetY)
                        ).ToNurbsCurve();
                }
                else
                {
                    rules[i] = new Line(
                        p.Origin + p.YAxis * (offset + offsetY) + p.XAxis * (w2 + offsetX),
                        p.Origin + p.YAxis * (offset + offsetY) - p.XAxis * (w2 - offsetX)
                        ).ToNurbsCurve();
                }
            }

            Brep[] loft = Brep.CreateFromLoft(rules, Point3d.Unset, Point3d.Unset, LoftType.Normal, false);
            if (loft == null || loft.Length < 1)
            {
                throw new Exception("Glulam::GetSideSurface::Loft failed!");
            }

            Brep brep = loft[0];

            Point3d  pt  = brep.Faces[0].PointAt(brep.Faces[0].Domain(0).Mid, brep.Faces[0].Domain(1).Mid);
            Vector3d nor = brep.Faces[0].NormalAt(brep.Faces[0].Domain(0).Mid, brep.Faces[0].Domain(1).Mid);

            double ct;

            Centreline.ClosestPoint(pt, out ct);
            Vector3d nor2 = Centreline.PointAt(ct) - pt;

            nor2.Unitize();

            if (nor2 * nor < 0.0)
            {
                brep.Flip();
            }

            if (flip)
            {
                brep.Flip();
            }

            return(brep);
        }
Exemplo n.º 18
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Surface mySurface = null;

            if (!DA.GetData(0, ref mySurface))
            {
                return;
            }
            int myMinRad = 0;

            if (!DA.GetData(1, ref myMinRad))
            {
                return;
            }
            int mySampleDensity = 0;

            if (!DA.GetData(2, ref mySampleDensity))
            {
                return;
            }
            double myFactor = 0.0;

            if (!DA.GetData(3, ref myFactor))
            {
                return;
            }


            List <Curve>   myCurveList    = new List <Curve>();
            List <double>  myOffsetList   = new List <double>();
            List <Point3d> myOriginalList = new List <Point3d>();

            List <List <Point3d> > myNewListList = new List <List <Point3d> >();
            List <Vector3d>        myNormalList  = new List <Vector3d>();
            //Get Curve from Surface
            double MIN1   = mySurface.Domain(1).Min;
            double MAX1   = mySurface.Domain(1).Max;
            double myStep = (MAX1 - MIN1) / mySampleDensity;

            for (int i = 0; i < (mySampleDensity - 1); i++)
            {
                Curve myCurve = mySurface.IsoCurve(0, i * myStep); //Problem here? 1 and 0?
                myCurveList.Add(myCurve);
            }
            //Loop through Curve;
            foreach (Curve myCurve in myCurveList)
            {
                /*Curve c = myCurve.DuplicateCurve();
                 *
                 *
                 * for(int iter=0; iter<10; ++iter) {
                 *  double[] t = c.DivideByCount(100, true);
                 *  List<Point3d> cp = new List<Point3d>();
                 *  for (int k = 0; k <t.Length; ++k)
                 *  {
                 *      Point3d p = c.PointAt(t[k]);
                 *      Vector3d k1=c.CurvatureAt(t[k]);
                 *      p += k1 * 0.01;
                 *      cp.Add(p);
                 *  }
                 *  c = NurbsCurve.CreateInterpolatedCurve(cp, 3);
                 * }*/

                List <Point3d> myNewList = new List <Point3d>();
                double         Max       = myCurve.Domain.Max;
                double         Min       = myCurve.Domain.Min;
                double         step      = (Max - Min) / mySampleDensity;
                for (int i = 0; i < mySampleDensity - 1; i++)
                {
                    Point3d P = new Point3d(myCurve.PointAt(step * i));
                    myOriginalList.Add(P); //Make List of Points
                    myNewList.Add(P);
                    Vector3d myCurvature = myCurve.CurvatureAt(step * i);
                    double   myRadius    = 1 / myCurvature.Length;
                    double   myOffset    = myMinRad - myRadius;
                    myOffsetList.Add(myOffset); //Make List of offset
                    double u;
                    double v;
                    mySurface.ClosestPoint(P, out u, out v);
                    Vector3d myNormal = mySurface.NormalAt(u, v);
                    myNormal.Unitize();
                    myNormalList.Add(myNormal);
                    SurfaceCurvature mySurfaceCurvature = mySurface.CurvatureAt(u, v);
                    //double myGaussian = mySurfaceCurvature.Gaussian;//Gaussian from Surface

                    double Kappa0 = mySurfaceCurvature.Kappa(0);//Problem here?
                    if (myOffset > 0)
                    {
                        if (Math.Abs(Kappa0) > 0)
                        {
                            Point3d PNew = new Point3d();
                            PNew = P + myNormal * myOffset * myFactor;
                            myNewList.RemoveAt(i);
                            myNewList.Insert(i, PNew);
                        }
                        else
                        {
                            Point3d PNew = new Point3d();
                            PNew = P - myNormal * myOffset * myFactor;
                            myNewList.RemoveAt(i);
                            myNewList.Insert(i, PNew);
                        }
                    }
                }
                myNewListList.Add(myNewList);
            }
            List <Curve> myNewCurveList = new List <Curve>();
            Brep         FINAL          = new Brep();

            for (int i = 0; i < myNewListList.Count; i++)
            {
                Curve myNewCurve = NurbsCurve.CreateControlPointCurve(myNewListList[i], 3);
                myNewCurveList.Add(myNewCurve);
            }
            FINAL = Brep.CreateFromLoft(myNewCurveList, Point3d.Unset, Point3d.Unset, LoftType.Normal, false)[0];
            DA.SetData(0, FINAL);
        }
Exemplo n.º 19
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            double span = 0;
            List <VariableSection> vSect = new List <VariableSection>();

            if (!DA.GetData(0, ref span))
            {
                return;
            }
            if (!DA.GetDataList(1, vSect))
            {
                return;
            }

            int N = vSect.Count;

            if (N < 2)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "VSect needs at least 2 inputs");
                return;
            }

            Transform mirrorYZ = Transform.Mirror(Plane.WorldYZ);
            Transform mirrorXZ = Transform.Mirror(Plane.WorldZX);

            Point3d spPtA    = new Point3d(-span * 0.5, 0, 0);
            Curve   spCrv    = new Line(spPtA, Plane.WorldXY.XAxis, span).ToNurbsCurve();
            Curve   spCrvHlf = new Line(spPtA, Plane.WorldXY.XAxis, span * 0.5).ToNurbsCurve();

            //if (N < 2) { N = 3; }
            double[] spCrvDiv = spCrv.DivideByCount(N - 1, true);
            Plane[]  spCrvPln = spCrv.GetPerpendicularFrames(spCrvDiv);
            for (int i = 0; i < spCrvPln.Length; i++) //reorient planes to align with z-axis
            {
                Plane pl = spCrvPln[i];
                pl.Rotate(-Math.PI * 0.5, Plane.WorldXY.XAxis);
                spCrvPln[i] = pl;
            }

            List <Point3d> allPts = new List <Point3d>();
            List <Curve>   crvs   = new List <Curve>();

            int ptCnt = vSect[0].sctPts.Count;

            Point3d[,] crvPts = new Point3d[ptCnt, vSect.Count];
            //for(int i = 0; i < vSect.Count; i++) { Point3d[] crvPt = new Point3d[vSect.Count]; }


            for (int i = 0; i < vSect.Count; i++) //moves and reorients points from input i indicates number section, j number curve/point in section
            {
                List <Point3d> sctPts = vSect[i].sctPts;
                Plane          sctPln = vSect[i].sctPln;

                if (sctPts.Count != ptCnt)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Each section needs the same number of points"); return;
                }

                Transform reorient = Transform.PlaneToPlane(sctPln, spCrvPln[i]);
                //foreach (Point3d pt in sctPts) { pt.Transform(reorient); allPts.Add(pt); } //remove when workaround is figured out

                for (int j = 0; j < sctPts.Count; j++) //separate points to each "row" in a list of arrays
                {
                    Point3d pt = sctPts[j];
                    pt.Transform(reorient);
                    crvPts[j, i] = pt;
                }
            }

            int degree = 3;

            for (int i = 0; i < crvPts.GetLength(0); i++) //creates curves through points
            {
                Point3d[] aCrvPts = new Point3d[vSect.Count];
                for (int j = 0; j < crvPts.GetLength(1); j++)
                {
                    aCrvPts[j] = crvPts[i, j];
                }
                Curve crv = Curve.CreateInterpolatedCurve(aCrvPts, degree);
                crvs.Add(crv);
            }

            List <Brep> faces = new List <Brep>();

            Brep[] loftFace = Brep.CreateFromLoft(crvs, Point3d.Unset, Point3d.Unset, LoftType.Straight, false);
            //Brep face1 = new Brep();
            //foreach(Brep face in loftFace) { face1 = face.DuplicateBrep(); }
            Brep face1 = loftFace[0].DuplicateBrep();
            Brep face2 = face1.DuplicateBrep(); face2.Transform(mirrorXZ);

            faces.Add(face1); faces.Add(face2);

            Curve[] naked1 = face1.DuplicateNakedEdgeCurves(true, false); Curve[] naked2 = face2.DuplicateNakedEdgeCurves(true, false);
            Curve[] loftCrv1 = new Curve[] { naked1[1], naked2[1] }; Curve[] loftCrv2 = new Curve[] { naked1[3], naked2[3] };
            Brep[]  face3 = Brep.CreateFromLoft(loftCrv1, Point3d.Unset, Point3d.Unset, LoftType.Straight, false);
            Brep[]  face4 = Brep.CreateFromLoft(loftCrv2, Point3d.Unset, Point3d.Unset, LoftType.Straight, false);
            faces.Add(face3[0]); faces.Add(face4[0]);

            Brep[] beamBreps = Brep.JoinBreps(faces, DocumentTolerance());
            Brep   beam      = beamBreps[0].CapPlanarHoles(DocumentTolerance());

            int intersects = 0;
            int a          = crvs.Count;

            for (int i = 0; i < (a - 1); i++)
            {
                for (int j = (i + 1); j < a; j++)
                {
                    Rhino.Geometry.Intersect.CurveIntersections crvCheck = Rhino.Geometry.Intersect.Intersection.CurveCurve(
                        crvs[i], crvs[j], DocumentTolerance(), 0.0);

                    intersects += crvCheck.Count;
                }
            }

            if (intersects > 0)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Beam volume is invalid.");
                return;
            }

            DA.SetDataList(0, spCrvPln);
            DA.SetDataList(1, crvPts);
            DA.SetDataList(2, crvs);
            DA.SetData(3, beam);
            DA.SetData(4, spCrv);
        }
        // dual loop directly connected to plates
        private void half_dualLoop_type_1(int edgeIndex)
        {
            Edge edge = iSpringMesh.Edges[edgeIndex];

            int rightTriIndex = edge.FirstTriangleIndex;
            int leftTriIndex  = edge.SecondTriangleIndex;

            // vertex point
            int vertex1 = edge.FirstVertexIndex;
            int vertex2 = edge.SecondVertexIndex;

            int vertex = vertex1;

            if (iVertexStatus[vertex1] == false && iVertexStatus[vertex2] == true)
            {
                vertex = vertex1;
            }
            else if (iVertexStatus[vertex2] == false && iVertexStatus[vertex1] == true)
            {
                vertex = vertex2;
            }
            else
            {
                oInfo += "got it...";
            }

            Point3d vertexPt = iSpringMesh.Vertices[vertex].Position;

            // layer up
            Point3d rightUp01 = topCenterPts[rightTriIndex];
            Point3d leftUp01  = topCenterPts[leftTriIndex];

            Point3d up03 = topCps[vertex]; //reference point not for construct surfaces

            Point3d rightUp02 = (1 - iTangentScale) * rightUp01 + (iTangentScale) * up03;
            Point3d leftUp02  = (1 - iTangentScale) * leftUp01 + (iTangentScale) * up03;

            // layer down
            Point3d rightDown01 = bottomCenterPts[rightTriIndex];
            Point3d leftDown01  = bottomCenterPts[leftTriIndex];

            Point3d down03 = bottomCps[vertex]; //reference point not for construct surfaces

            Point3d rightDown02 = (1 - iTangentScale) * rightDown01 + (iTangentScale) * down03;
            Point3d leftDown02  = (1 - iTangentScale) * leftDown01 + (iTangentScale) * down03;

            Curve right = Curve.CreateControlPointCurve(
                new List <Point3d>()
            {
                rightUp01, rightUp02, vertexPt, rightDown02, rightDown01
            });

            Curve left = Curve.CreateControlPointCurve(
                new List <Point3d>()
            {
                leftUp01, leftUp02, vertexPt, leftDown02, leftDown01
            });


            // compare their polygon index to sort the lofting sequence
            int[] rightIndex = indexSortPolygon[rightTriIndex];
            int[] leftIndex  = indexSortPolygon[leftTriIndex];

            for (int r = 0; r < 3; r++)
            {
                for (int l = 0; l < 3; l++)
                {
                    if (rightIndex[r] == leftIndex[l] && rightIndex[r] != -1 && leftIndex[l] != -1)
                    {
                        if ((rightIndex[r + 3] == 0 && leftIndex[l + 3] != 1) ||
                            (leftIndex[l + 3] == 0 && rightIndex[r + 3] != 1) && (rightIndex[r + 3] < leftIndex[l + 3]))
                        {
                            Brep[] brep = Brep.CreateFromLoft(
                                new List <Curve>()
                            {
                                right, left
                            },
                                Point3d.Unset, Point3d.Unset,
                                LoftType.Normal,
                                false
                                );
                            if (brep.Length > 0)
                            {
                                oDualLoop.Add(brep[0]);
                            }
                        }
                        else if ((rightIndex[r + 3] == 0 && leftIndex[l + 3] != 1) ||
                                 (leftIndex[l + 3] == 0 && rightIndex[r + 3] != 1) && (rightIndex[r + 3] >= leftIndex[l + 3]))
                        {
                            Brep[] brep = Brep.CreateFromLoft(
                                new List <Curve>()
                            {
                                left, right
                            },
                                Point3d.Unset, Point3d.Unset,
                                LoftType.Normal,
                                false
                                );
                            if (brep.Length > 0)
                            {
                                oDualLoop.Add(brep[0]);
                            }
                        }
                        else if (rightIndex[r + 3] >= leftIndex[l + 3])
                        {
                            Brep[] brep = Brep.CreateFromLoft(
                                new List <Curve>()
                            {
                                right, left
                            },
                                Point3d.Unset, Point3d.Unset,
                                LoftType.Normal,
                                false
                                );
                            if (brep.Length > 0)
                            {
                                oDualLoop.Add(brep[0]);
                            }
                            //break;
                        }
                        else if (rightIndex[r + 3] < leftIndex[l + 3])
                        {
                            Brep[] brep = Brep.CreateFromLoft(
                                new List <Curve>()
                            {
                                left, right
                            },
                                Point3d.Unset, Point3d.Unset,
                                LoftType.Normal,
                                false
                                );
                            if (brep.Length > 0)
                            {
                                oDualLoop.Add(brep[0]);
                            }
                            //break;
                        }
                    }
                }
            }

            /*
             * Brep[] brep = Brep.CreateFromLoft(
             *        new List<Curve>() { right, left },
             *        Point3d.Unset, Point3d.Unset,
             *        LoftType.Normal,
             *        false
             *        );
             *
             * if (brep.Length > 0)
             * {
             *  //oInfo += "got it...";
             *  oDualLoop.Add(brep[0]);
             * }*/
        }
Exemplo n.º 21
0
        public void PitchCones(List <Circle> C, Polyline Poly, List <double> shifts, double Depth, List <double> Hole)
        {
            pitchCones  = new List <List <Brep> >();
            coneCircles = new List <List <Circle> >();
            for (int i = 0; i < C.Count; i++)
            {
                if (Hole.Count <= i)
                {
                    Hole.Add(Hole[Hole.Count - 1]);
                }
            }
            #region Trigonometry
            var     ccx   = Rhino.Geometry.Intersect.Intersection.CurveCurve(new ArcCurve(C[0]), new ArcCurve(C[1]), 1.0, 1.0);
            Point3d pitch = ccx[0].PointA;

            /*[0]  b     [1] c _C_ a
             *    |\           \  |
             *   C| \A         A\ |B
             *    | _\           \|
             *   a  B  c = pitch = b
             */
            //Triangle: [0]_A, [1]_B = r, [2]_C = h, [3]_alpha = 90, [4]_beta, [5]_gamma
            List <double>         TA = Trigonometry(C[0].Radius, Math.PI * 0.5, C[0].Center.DistanceTo(Poly[1]), TrigLaw.SAS_B_alpha_C, Traingle.ALL);
            List <double>         TB = Trigonometry(C[1].Radius, Math.PI * 0.5, C[1].Center.DistanceTo(Poly[1]), TrigLaw.SAS_B_alpha_C, Traingle.ALL);
            List <List <double> > TT = new List <List <double> > {
                TA, TB
            };

            double        map = (TA[2] - Depth) / TA[2]; //TA[2] is C = Heigh
            List <double> ta  = new List <double> {
                TA[0] * map, TA[1] * map, TA[2] * map, TA[3], TA[4], TA[5]
            };                                                                                                 //456 is angle
            List <double> tb = new List <double> {
                TB[0] * map, TB[1] * map, TB[2] * map, TB[3], TB[4], TB[5]
            };
            List <List <double> > tt = new List <List <double> > {
                ta, tb
            };
            //compute back cone angle
            //TCone: [0]_A = profile, [1]_B = shiftA, [2]_C = shiftB, [3]_a = sumBeta, [4]_b = c1A, [5]_r = c2A
            double        sumBeta = TA[4] + TB[4];
            List <double> TCone   = Trigonometry(shifts[0], sumBeta, shifts[1], TrigLaw.SAS_B_alpha_C, Traingle.ALL);
            #endregion

            //cone surface

            for (int i = 0; i < C.Count; i++)
            {
                List <Circle> thisConeCircles = new List <Circle>();
                List <Brep>   thisPitchCones  = new List <Brep>();
                //lower circle
                Circle BC = new Circle(C[i].Plane, C[i].Radius - shifts[i]);
                double h  = shifts[i] * 3 * Math.Sin(TCone[4]);
                double r  = shifts[i] * 3 * Math.Cos(TCone[4]);
                Circle TC = new Circle(new Plane(C[i].Center + C[i].Plane.ZAxis * h, C[i].Plane.XAxis, C[i].Plane.YAxis), BC.Radius + r);

                Circle BChole = new Circle(BC.Plane, Hole[i]);
                thisConeCircles.Add(BC);
                thisConeCircles.Add(BChole);
                List <Curve> Circles = new List <Curve> {
                    new ArcCurve(BC), new ArcCurve(TC)
                };
                thisPitchCones.Add(Brep.CreateFromLoft(Circles, Point3d.Unset, Point3d.Unset, LoftType.Normal, false)[0]);

                //upper circle
                Plane  hPln   = new Plane(C[i].Center + (C[i].Plane.ZAxis * (TT[i][2] - tt[i][2])), C[i].Plane.XAxis, C[i].Plane.YAxis);
                double hshift = shifts[i] * map;
                Circle bc     = new Circle(hPln, tt[i][1] - hshift);
                double hh     = h * map;
                double hr     = r * map;
                Circle tc     = new Circle(new Plane((bc.Center + bc.Plane.ZAxis * hh), C[i].Plane.XAxis, C[i].Plane.YAxis), bc.Radius + hr);

                Circle bchole = new Circle(bc.Plane, Hole[i]);
                thisConeCircles.Add(bchole);
                thisConeCircles.Add(bc);
                List <Curve> circles = new List <Curve> {
                    new ArcCurve(bc), new ArcCurve(tc)
                };
                thisPitchCones.Add(Brep.CreateFromLoft(circles, Point3d.Unset, Point3d.Unset, LoftType.Normal, false)[0]);

                pitchCones.Add(thisPitchCones);
                coneCircles.Add(thisConeCircles);

                //getBevelParameterOut
                profileCircles.AddRange(thisConeCircles);
                profileBreps.AddRange(thisPitchCones);
            }
        }
        private void createStripe(int firstVertexIndex, int secondVertexIndex, int thirdVertexIndex)
        {
            Point3d a = bottomCps[firstVertexIndex];
            Point3d A = topCps[firstVertexIndex];

            Point3d aA = 0.5 * (a + A);

            Point3d b = bottomCps[secondVertexIndex];
            Point3d B = topCps[secondVertexIndex];

            Point3d c = bottomCps[thirdVertexIndex];
            Point3d C = topCps[thirdVertexIndex];

            Point3d ab = 0.5 * (a + b);
            Point3d AB = 0.5 * (A + B);

            Point3d ac = 0.5 * (a + c);
            Point3d AC = 0.5 * (A + C);

            Point3d m = 0.33333 * (ab + ac + 0.5 * (b + c));
            Point3d M = 0.33333 * (AB + AC + 0.5 * (B + C));

            Point3d AAB = iTangentScale * A + (1.0 - iTangentScale) * AB;
            Point3d aab = iTangentScale * a + (1.0 - iTangentScale) * ab;

            Point3d AAC = iTangentScale * A + (1.0 - iTangentScale) * AC;
            Point3d aac = iTangentScale * a + (1.0 - iTangentScale) * ac;

            Curve profileCurve1 = Curve.CreateControlPointCurve(new List <Point3d>()
            {
                ab, aab, aA, AAB, AB
            });
            Curve profileCurve2 = Curve.CreateControlPointCurve(new List <Point3d>()
            {
                ac, aac, aA, AAC, AC
            });

            if (iPolySrf)
            {
                PolyCurve polyCurve1 = new PolyCurve();
                polyCurve1.Append(new LineCurve(m, ab));
                polyCurve1.Append(profileCurve1);
                polyCurve1.Append(new LineCurve(AB, M));

                PolyCurve polyCurve2 = new PolyCurve();
                polyCurve2.Append(new LineCurve(m, ac));
                polyCurve2.Append(profileCurve2);
                polyCurve2.Append(new LineCurve(AC, M));

                oTriLoop.Add(
                    Brep.CreateFromLoft(
                        new List <Curve>()
                {
                    polyCurve1, polyCurve2
                },
                        Point3d.Unset, Point3d.Unset,
                        LoftType.Normal,
                        false
                        )[0]
                    );
            }
            else
            {
                profileCurve1 = Curve.JoinCurves(
                    new List <Curve>()
                {
                    new LineCurve(b, ab), profileCurve1, new LineCurve(AB, B)
                },
                    documentTolerance,
                    true)[0];

                profileCurve2 = Curve.JoinCurves(
                    new List <Curve>()
                {
                    new LineCurve(c, ac), profileCurve2, new LineCurve(AC, C)
                },
                    documentTolerance,
                    true)[0];

                Brep brep = Brep.CreateFromLoft(
                    new List <Curve>()
                {
                    profileCurve1, profileCurve2
                },
                    Point3d.Unset, Point3d.Unset,
                    LoftType.Normal,
                    false
                    )[0];

                // =============================================
                // Trim the brep using planes
                // =============================================

                double   offsetAmount = 0.2;
                Vector3d normal;
                Brep[]   breps;

                normal = Vector3d.CrossProduct(B - A, C - A);

                Point3d A_ = A + offsetAmount * normal;

                breps = brep.Trim(new Plane(A_, AB, M), documentTolerance);
                if (breps.Length > 0)
                {
                    brep = breps[0];
                }
                else
                {
                    oTriLoop.Add(brep); return;
                }

                breps = brep.Trim(new Plane(A_, M, AC), documentTolerance);
                if (breps.Length > 0)
                {
                    brep = breps[0];
                }
                else
                {
                    oTriLoop.Add(brep); return;
                }

                normal = Vector3d.CrossProduct(b - a, c - a);

                Point3d a_ = a - offsetAmount * normal;

                breps = brep.Trim(new Plane(a_, m, ab), documentTolerance);
                if (breps.Length > 0)
                {
                    brep = breps[0];
                }
                else
                {
                    oTriLoop.Add(brep); return;
                }

                breps = brep.Trim(new Plane(a_, ac, m), documentTolerance);
                if (breps.Length > 0)
                {
                    brep = breps[0];
                }
                else
                {
                    oTriLoop.Add(brep); return;
                }

                oTriLoop.Add(brep);
            }
        }
Exemplo n.º 23
0
        public override Brep GetBoundingBrep(double offset = 0.0)
        {
            /*
             * int N = Math.Max(Data.Samples, 6);
             *
             * GenerateCrossSectionPlanes(N, out Plane[] frames, out double[] parameters, Data.InterpolationType);
             *
             * int numCorners = 4;
             * GenerateCorners(offset);
             *
             * List<Point3d>[] crvPts = new List<Point3d>[numCorners];
             * for (int i = 0; i < numCorners; ++i)
             * {
             *  crvPts[i] = new List<Point3d>();
             * }
             *
             * Transform xform;
             * Point3d temp;
             *
             * for (int i = 0; i < parameters.Length; ++i)
             * {
             *  //frames[i] = frames[i].FlipAroundYAxis();
             *  xform = Rhino.Geometry.Transform.PlaneToPlane(Plane.WorldXY, frames[i]);
             *
             *  for (int j = 0; j < numCorners; ++j)
             *  {
             *      temp = new Point3d(m_section_corners[j]);
             *      temp.Transform(xform);
             *      crvPts[j].Add(temp);
             *  }
             * }
             */

            var edge_points = GetEdgePoints(offset);
            int numCorners  = m_section_corners.Length;
            var num_points  = edge_points[0].Count;

            NurbsCurve[] edges           = new NurbsCurve[numCorners + 4];
            var          edge_parameters = new List <double> [numCorners];
            double       t;

            for (int i = 0; i < numCorners; ++i)
            {
                //edges[i] = NurbsCurve.CreateInterpolatedCurve(edge_points[i], 3, CurveKnotStyle.Chord, Centreline.TangentAtStart, Centreline.TangentAtEnd);
                edges[i]           = NurbsCurve.Create(false, 3, edge_points[i]);
                edge_parameters[i] = new List <double>();

                foreach (Point3d pt in edge_points[i])
                {
                    edges[i].ClosestPoint(pt, out t);
                    edge_parameters[i].Add(t);
                }
            }

            edges[numCorners + 0] = new Line(edge_points[3].First(), edge_points[0].First()).ToNurbsCurve();
            edges[numCorners + 1] = new Line(edge_points[2].First(), edge_points[1].First()).ToNurbsCurve();

            edges[numCorners + 2] = new Line(edge_points[2].Last(), edge_points[1].Last()).ToNurbsCurve();
            edges[numCorners + 3] = new Line(edge_points[3].Last(), edge_points[0].Last()).ToNurbsCurve();

            Brep[] sides = new Brep[numCorners + 2];
            int    ii    = 0;

            for (int i = 0; i < numCorners; ++i)
            {
                ii = (i + 1).Modulus(numCorners);

                List <Point2d> rulings = new List <Point2d>();
                for (int j = 0; j < num_points; ++j)
                {
                    rulings.Add(new Point2d(edge_parameters[i][j], edge_parameters[ii][j]));
                }

                sides[i] = Brep.CreateDevelopableLoft(edges[i], edges[ii], rulings).First();
                //sides[i] = Brep.CreateFromLoft(
                //  new Curve[] { edges[i], edges[ii] },
                //  Point3d.Unset, Point3d.Unset, LoftType.Normal, false)[0];
            }

            // Make ends

            sides[numCorners + 0] = Brep.CreateFromLoft(
                new Curve[] {
                edges[numCorners + 0],
                edges[numCorners + 1]
            },
                Point3d.Unset, Point3d.Unset, LoftType.Straight, false)[0];

            sides[numCorners + 1] = Brep.CreateFromLoft(
                new Curve[] {
                edges[numCorners + 2],
                edges[numCorners + 3]
            },
                Point3d.Unset, Point3d.Unset, LoftType.Straight, false)[0];

            // Join Breps

            Brep brep = Brep.JoinBreps(
                sides,
                Tolerance
                )[0];

            //brep.UserDictionary.Set("glulam", GetArchivableDictionary());

            return(brep);
        }
Exemplo n.º 24
0
        public static Elevation drawElevation(Curve baseCurve, List <List <Household> > houseHolds, List <Core> cores)
        {
            double storiesHeight = Consts.FloorHeight;
            double pilotiHeight  = Consts.PilotiHeight;

            double windowSide   = 300;
            double windowLow    = 300;
            double windowHeight = 2100;

            Curve groundCurve = new LineCurve(new Point3d(0, 0, 0), new Point3d(baseCurve.GetLength(), 0, 0));

            List <Curve> outlineCurve = new List <Curve>();
            List <Curve> windowDetail = new List <Curve>();
            List <Curve> banister     = new List <Curve>();
            List <Curve> core         = new List <Curve>();

            List <double> widthList = new List <double>();

            foreach (List <Household> i in houseHolds)
            {
                foreach (Household j in i)
                {
                    widthList.Add(j.YLengthA);
                }
            }

            List <double> uniqueWidthList = widthList.Distinct().ToList();

            uniqueWidthList.Sort();

            List <Brep>   tempElevationBase = new List <Brep>();
            List <Curve>  BalconyBase       = new List <Curve>();
            List <double> pilotiParameter   = new List <double>();
            List <Curve>  coreBase          = new List <Curve>();

            for (int h = 0; h < houseHolds.Count(); h++)
            {
                for (int i = 0; i < houseHolds[h].Count(); i++)
                {
                    Point3d start = houseHolds[h][i].Origin + houseHolds[h][i].XDirection * (-houseHolds[h][i].XLengthB);
                    Point3d end   = houseHolds[h][i].Origin + houseHolds[h][i].XDirection * (houseHolds[h][i].XLengthA - houseHolds[h][i].XLengthB);

                    double startDomain; double endDomain;

                    baseCurve.ClosestPoint(start, out startDomain);
                    baseCurve.ClosestPoint(end, out endDomain);

                    if (h == 0)
                    {
                        pilotiParameter.Add((endDomain - baseCurve.Domain.T0) * baseCurve.GetLength() + groundCurve.Domain.T0);
                        pilotiParameter.Add((startDomain - baseCurve.Domain.T0) * baseCurve.GetLength() + groundCurve.Domain.T0);
                    }

                    Curve tempHousingBase = new LineCurve(groundCurve.PointAt((startDomain - baseCurve.Domain.T0) * baseCurve.GetLength() + groundCurve.Domain.T0), groundCurve.PointAt((endDomain - baseCurve.Domain.T0) * baseCurve.GetLength() + groundCurve.Domain.T0));

                    tempHousingBase.Transform(Transform.Translation(new Vector3d(0, start.Z, 0)));
                    Curve tempHousingTop = tempHousingBase.DuplicateCurve();
                    tempHousingTop.Transform(Transform.Translation(new Vector3d(0, storiesHeight, 0)));

                    Curve[] tempLoftBase = { tempHousingBase, tempHousingTop };

                    Brep tempHousingBrep = Brep.CreateFromLoft(tempLoftBase, Point3d.Unset, Point3d.Unset, LoftType.Straight, false)[0];

                    Curve tempBalconyBase = tempHousingBase.DuplicateCurve();
                    tempBalconyBase.Transform(Transform.Translation(new Vector3d(0, windowLow, 0)));

                    double balconyBaseStart; double balconyBaseEnd;

                    tempBalconyBase.LengthParameter(windowSide, out balconyBaseStart);
                    tempBalconyBase.LengthParameter(tempBalconyBase.GetLength() - windowSide, out balconyBaseEnd);

                    tempBalconyBase = new LineCurve(tempBalconyBase.PointAt(balconyBaseStart), tempBalconyBase.PointAt(balconyBaseEnd));

                    tempElevationBase.Add(tempHousingBrep);
                    BalconyBase.Add(tempBalconyBase);
                }
            }

            for (int i = 0; i < cores.Count(); i++)
            {
                Point3d tempCoreStart = cores[i].Origin;
                Point3d tempCoreEnd   = cores[i].Origin + cores[i].XDirection * cores[i].Width;

                double startDomain; double endDomain;

                baseCurve.ClosestPoint(tempCoreStart, out startDomain);
                baseCurve.ClosestPoint(tempCoreEnd, out endDomain);

                Curve tempCoreBase = new LineCurve(groundCurve.PointAt((startDomain - baseCurve.Domain.T0) * baseCurve.GetLength() + groundCurve.Domain.T0), groundCurve.PointAt((endDomain - baseCurve.Domain.T0) * baseCurve.GetLength() + groundCurve.Domain.T0));

                coreBase.Add(tempCoreBase);
            }

            List <List <Brep> > elevationBrepSortedByWidth = new List <List <Brep> >();

            for (int i = 0; i < uniqueWidthList.Count(); i++)
            {
                elevationBrepSortedByWidth.Add(new List <Brep>());
            }

            for (int i = 0; i < widthList.Count; i++)
            {
                int tempWidthIndex = uniqueWidthList.IndexOf(widthList[i]);

                elevationBrepSortedByWidth[tempWidthIndex].Add(tempElevationBase[i]);
            }

            //elevationBrepSortedByWidth[elevationBrepSortedByWidth.Count() - 1].AddRange(DrawPiloti(groundCurve, pilotiParameter.Distinct().ToList(), pilotiHeight));

            List <Curve> joinedOutLineCurve = new List <Curve>();

            foreach (List <Brep> i in elevationBrepSortedByWidth)
            {
                Brep[] joinedBreps = Brep.JoinBreps(i, 2);

                foreach (Brep j in joinedBreps)
                {
                    outlineCurve.AddRange(j.DuplicateNakedEdgeCurves(true, true).ToList());
                    joinedOutLineCurve.AddRange(Curve.JoinCurves(j.DuplicateNakedEdgeCurves(true, true).ToList()).ToList());
                }
            }

            for (int i = 0; i < coreBase.Count(); i++)
            {
                Curve coreBoundary = offsetOneSide(coreBase[i], (cores[i].Stories + 1) * Consts.FloorHeight + Consts.PilotiHeight);

                core.AddRange(getOuterCurve(coreBoundary, joinedOutLineCurve));
            }

            foreach (Curve h in BalconyBase)
            {
                double[]      target            = { double.MaxValue, 2, 2 };
                List <object> typeList          = new List <object>();
                List <Curve>  splittedBaseCurve = divideBaseCurve(h, target, out typeList);

                for (int i = 0; i < splittedBaseCurve.Count(); i++)
                {
                    List <string> windowTypeList = Enum.GetValues(typeof(WindowType)).Cast <WindowType>().Select(v => v.ToString()).ToList();

                    if (windowTypeList.IndexOf(typeList[i].ToString()) != -1)
                    {
                        int index = windowTypeList.IndexOf(typeList[i].ToString());

                        List <Curve> tempWindow = drawWindow((WindowType)index, splittedBaseCurve[i], windowHeight);

                        windowDetail.AddRange(tempWindow);

                        List <Curve> tempBanister = drawBanister(splittedBaseCurve[i], 25, 900);

                        banister.AddRange(tempBanister);
                    }
                }
            }

            return(new Elevation(outlineCurve, windowDetail, banister, core));
        }
Exemplo n.º 25
0
        public Brep buildHelicalRack(Line L, double M, double Teeth, double Angle, double HAngle, double H, double addendum, double dedendum)
        {
            double Pitch = Math.PI * M;
            int    time  = (int)(L.Length / Pitch);

            Vector3d dir  = L.Direction; dir.Unitize();
            Vector3d dirA = dir;

            dirA.Rotate(toRadian(90.0 - Angle), Vector3d.ZAxis);
            Vector3d dirB = dir;

            dirB.Rotate(toRadian(-90.0 + Angle), Vector3d.ZAxis);

            addendum = addendum * M;
            dedendum = dedendum * M;

            double slope  = (addendum + dedendum) / Math.Cos(toRadian(Angle));
            double tip    = (Pitch * 0.5) - Math.Tan(Angle) * addendum * 2;
            double buttom = (Pitch * 0.5) - Math.Tan(Angle) * dedendum;

            List <Curve> profiles = new List <Curve>();

            profiles.Add(new LineCurve(new Line(L.From, dirA * slope)));
            profiles.Add(new LineCurve(new Line(profiles[0].PointAtEnd, dir * tip)));
            profiles.Add(new LineCurve(new Line(profiles[1].PointAtEnd, dirB * slope)));
            profiles.Add(new LineCurve(new Line(profiles[2].PointAtEnd, dir * buttom)));

            Transform move = Transform.Translation(Vector3d.CrossProduct(dir, Vector3d.ZAxis) * dedendum);
            Curve     rack = Curve.JoinCurves(profiles, 0.01, true)[0];

            rack.Transform(move);

            //Display
            locations.Add(rack.PointAtNormalizedLength(0.5));
            texts.Add(Math.Round(tip, 2).ToString());
            sizes.Add(Pitch * 4);

            List <Curve> racks = new List <Curve>();

            for (int i = 0; i < time + 1; i++)
            {
                Transform duplicate = Transform.Translation(dir * Pitch * i);
                Curve     thisC     = rack.DuplicateCurve();
                thisC.Transform(duplicate);
                racks.Add(thisC);
            }

            //build helical
            double    hShift = H / (Math.Tan(toRadian(90.0 - HAngle)) * 2 * Math.PI); //helical shift
            double    hTime  = Math.Ceiling(hShift / Pitch);
            Transform shift  = Transform.Translation(dir * hShift);
            Transform zH     = Transform.Translation(Vector3d.ZAxis * H);

            List <Curve> helicals = new List <Curve>();

            if (hTime / Math.Abs(hTime) == 1)
            {
                for (int i = -1; i < time; i++)
                {
                    Transform duplicate = Transform.Translation(dir * Pitch * i);
                    Curve     thisC     = rack.DuplicateCurve();
                    thisC.Transform(duplicate);
                    helicals.Add(thisC);
                }
            }
            else
            {
                for (int i = 0; i < time + 1; i++)
                {
                    Transform duplicate = Transform.Translation(dir * Pitch * i);
                    Curve     thisC     = rack.DuplicateCurve();
                    thisC.Transform(duplicate);
                    helicals.Add(thisC);
                }
            }


            Curve helical = Curve.JoinCurves(helicals, 1, true)[0];

            rack = Curve.JoinCurves(racks, 1, true)[0];
            helical.Transform(shift);
            helical.Transform(zH);

            List <Curve> sections = new List <Curve> {
                rack, helical
            };
            Brep profile = Brep.CreateFromLoft(sections, Point3d.Unset, Point3d.Unset, LoftType.Normal, false)[0];

            return(profile);
        }