Exemplo n.º 1
0
    /// <summary>
    /// Same as SimplifyCurve, but simplifies only the last two segments at "side" end.
    /// </summary>
    /// <param name="end">If CurveEnd.Start the function simplifies the last two start 
    /// side segments, otherwise if CurveEnd.End the last two end side segments are simplified.
    /// </param>
    /// <param name="options">Simplification options.</param>
    /// <param name="distanceTolerance">A distance tolerance for the simplification.</param>
    /// <param name="angleToleranceRadians">An angle tolerance for the simplification.</param>
    /// <returns>New simplified curve on success, null on failure.</returns>
    public Curve SimplifyEnd(CurveEnd end, CurveSimplifyOptions options, double distanceTolerance, double angleToleranceRadians)
    {
      // CurveEnd must be Start or End
      if (end != CurveEnd.Start && end != CurveEnd.End)
        return null;

      int side = 0;//Start
      if (CurveEnd.End == end)
        side = 1; //end
      int _options = SimplifyOptionsToInt(options);
      IntPtr pConstPtr = ConstPointer();
      IntPtr rc = UnsafeNativeMethods.RHC_RhinoSimplifyCurveEnd(pConstPtr, side, _options, distanceTolerance, angleToleranceRadians);
      return GeometryBase.CreateGeometryHelper(rc, null) as Curve;
    }
Exemplo n.º 2
0
 static int SimplifyOptionsToInt(CurveSimplifyOptions options)
 {
   int none = 63;
   if ((options & CurveSimplifyOptions.SplitAtFullyMultipleKnots) == CurveSimplifyOptions.SplitAtFullyMultipleKnots)
   {
     // remove DontSplitFMK flag
     none -= (1 << 0);
   }
   if ((options & CurveSimplifyOptions.RebuildLines) == CurveSimplifyOptions.RebuildLines)
   {
     //remove DontRebuildLines flag
     none -= (1 << 1);
   }
   if ((options & CurveSimplifyOptions.RebuildArcs) == CurveSimplifyOptions.RebuildArcs)
   {
     //remove DontRebuildArcs flag
     none -= (1 << 2);
   }
   if ((options & CurveSimplifyOptions.RebuildRationals) == CurveSimplifyOptions.RebuildRationals)
   {
     // remove DontRebuildRationals flag
     none -= (1 << 3);
   }
   if ((options & CurveSimplifyOptions.AdjustG1) == CurveSimplifyOptions.AdjustG1)
   {
     // remove DontAdjustG1 flag
     none -= (1 << 4);
   }
   if ((options & CurveSimplifyOptions.Merge) == CurveSimplifyOptions.Merge)
   {
     // remove DontMerge flag
     none -= (1 << 5);
   }
   return none;
 }
Exemplo n.º 3
0
 /// <summary>
 /// Returns a geometrically equivalent PolyCurve.
 /// <para>The PolyCurve has the following properties</para>
 /// <para>
 ///	1. All the PolyCurve segments are LineCurve, PolylineCurve, ArcCurve, or NurbsCurve.
 /// </para>
 /// <para>
 ///	2. The Nurbs Curves segments do not have fully multiple interior knots.
 /// </para>
 /// <para>
 ///	3. Rational Nurbs curves do not have constant weights.
 /// </para>
 /// <para>
 ///	4. Any segment for which IsLinear() or IsArc() is true is a Line, 
 ///    Polyline segment, or an Arc.
 /// </para>
 /// <para>
 ///	5. Adjacent Colinear or Cocircular segments are combined.
 /// </para>
 /// <para>
 ///	6. Segments that meet with G1-continuity have there ends tuned up so
 ///    that they meet with G1-continuity to within machine precision.
 /// </para>
 /// </summary>
 /// <param name="options">Simplification options.</param>
 /// <param name="distanceTolerance">A distance tolerance for the simplification.</param>
 /// <param name="angleToleranceRadians">An angle tolerance for the simplification.</param>
 /// <returns>New simplified curve on success, null on failure.</returns>
 public Curve Simplify(CurveSimplifyOptions options, double distanceTolerance, double angleToleranceRadians)
 {
   IntPtr pConstPtr = ConstPointer();
   int _options = SimplifyOptionsToInt(options);
   IntPtr rc = UnsafeNativeMethods.RHC_RhinoSimplifyCurve(pConstPtr, _options, distanceTolerance, angleToleranceRadians);
   return GeometryBase.CreateGeometryHelper(rc, null) as Curve;
 }
Exemplo n.º 4
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)
        {
            //List<double> MP = new List<double>();
            MaterialProperties mp = null;

            List <double> Mu    = new List <double>();
            Brep          BBrep = new Brep();
            Curve         spCrv = null;
            //int N = 0;
            double CC    = 0;
            double selAs = 0;
            bool   fix   = false;
            int    code  = 0;


            if (!DA.GetData(0, ref mp))
            {
                return;
            }
            if (!DA.GetDataList(1, Mu))
            {
                return;
            }
            if (!DA.GetData(2, ref BBrep))
            {
                return;
            }
            if (!DA.GetData(3, ref spCrv))
            {
                return;
            }
            //if (!DA.GetData(4, ref N)) return;
            if (!DA.GetData(4, ref CC))
            {
                return;
            }
            if (!DA.GetData(5, ref selAs))
            {
                return;
            }
            if (!DA.GetData(6, ref fix))
            {
                return;
            }
            if (!DA.GetData(7, ref code))
            {
                return;
            }

            //MaterialProperties mp = null;
            //try
            //{
            //    mp = (MaterialProperties)mpobj;
            //}
            //catch (Exception e)
            //{
            //    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Must provide a valid Material Properties object");
            //    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e.ToString());
            //    return;
            //}

            int N = Mu.Count;

            if (N < 2)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Input Mu needs to have at least 2 values");
                return;
            }


            //if (N > spCrv.GetLength() * 0.5)
            //{
            //    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Input n must be less than half of the beam's length");
            //    return;
            //}

            //Copy to each analysis plugin - extracts material properties from MP input
            //double fc = MP[0]; double Ec = MP[1]; double ec = MP[2]; double rhoc = MP[3]; double EEc = MP[4];
            //double fy = MP[5]; double Es = MP[6]; double es = MP[7]; double rhos = MP[8]; double EEs = MP[9];

            double fc = mp.fC; double Ec = mp.EC; double ec = mp.eC; double rhoc = mp.rhoC; double EEc = mp.EEC;
            double fy = mp.fY; double Es = mp.ES; double es = mp.eS; double rhos = mp.rhoS; double EEs = mp.EES;

            //double fc = mp.FC;


            //Code limits for design
            double cdMax, rhoMax, rhoMin = 0;
            double rhoDes, sConst = 0;

            if (code == 1)
            {
                cdMax  = ec / (ec + es);
                rhoMax = (0.36 * fc / (0.87 * fy)) * cdMax;
                rhoMin = 0.25 * Math.Sqrt(fc) / fy;

                //Steel design constants
                rhoDes = 0.66 * rhoMax;
                sConst = 0.87 * fy * (1 - 1.005 * rhoDes * (fy / fc));
            }
            else
            {
                cdMax  = ec / (ec + es);
                rhoMax = (0.36 * fc / (0.87 * fy)) * cdMax;
                rhoMin = Math.Max(0.25 * Math.Sqrt(fc) / fy, 1.4 / fy);

                //Steel design constants
                rhoDes = 0.66 * rhoMax;
                sConst = 0.87 * fy * (1 - 1.005 * rhoDes * (fy / fc));
            }


            Console.Write(sConst);

            //Extract beam sections
            BoundingBox boundBBrep = BBrep.GetBoundingBox(false);

            Curve edge0            = spCrv;

            Double[] edge0div = edge0.DivideByCount(N - 1, true);
            //Double[] edge0div = edge0.DivideByLength(N, true);
            Plane[] splitPls = edge0.GetPerpendicularFrames(edge0div);

            List <Curve> AgCrv = new List <Curve>();
            List <Curve> AsCrv = new List <Curve>();

            double[] AsCrvArea = new double[splitPls.Length];

            List <Point3d> origins  = new List <Point3d>();
            List <Plane>   planesAg = new List <Plane>();

            //for testing with single moment at all points
            double[] newMu = new double[splitPls.Length];
            for (int i = 0; i < splitPls.Length; i++)
            {
                newMu[i] = Mu[0];
            }
            if (Mu.Count == splitPls.Length)
            {
                newMu = Mu.ToArray();
            }

            CurveSimplifyOptions crvSimp = new CurveSimplifyOptions();

            for (int i = 0; i < splitPls.Length; i++)
            {
                Curve[] ag     = Brep.CreateContourCurves(BBrep, splitPls[i]);
                Brep[]  brepAg = Brep.CreatePlanarBreps(ag, DocumentTolerance());
                Surface srfAg  = brepAg[0].Faces[0];

                Curve ag0 = ag[0].Simplify(CurveSimplifyOptions.All, DocumentTolerance(), DocumentAngleTolerance());

                AgCrv.Add(ag0);

                Double uSrfC = srfAg.Domain(0)[1] - srfAg.Domain(0)[0];
                Double vSrfC = srfAg.Domain(1)[1] - srfAg.Domain(1)[0];

                Curve U = srfAg.IsoCurve(0, 0.5 * vSrfC + srfAg.Domain(1)[0]);
                Curve V = srfAg.IsoCurve(1, 0.5 * uSrfC + srfAg.Domain(0)[0]);

                Point3d endPtV = V.PointAtEnd; Point3d startPtV = V.PointAtStart;
                if (endPtV.Z < startPtV.Z)
                {
                    V.Reverse();
                }
                if (newMu[i] > DocumentTolerance())
                {
                    V.Reverse();
                }

                srfAg.TryGetPlane(out Plane plAg);

                double d      = V.GetLength() - (CC / 1000);
                double areaAs = 0;

                if (selAs == 0)
                {
                    areaAs = (1000000 * Math.Abs(newMu[i])) / (sConst * d * 1000); //As in mm2
                }
                else
                {
                    areaAs = selAs;
                }

                double radAs = Math.Sqrt(areaAs / Math.PI) / 1000; //radius in m

                if (radAs <= DocumentTolerance())
                {
                    radAs = DocumentTolerance();
                }                                                                  //insert correction for when radius is equal to 0

                Point3d origin = V.PointAtLength(CC / 1000);
                origins.Add(origin);
                planesAg.Add(plAg);

                Circle crcAs = new Circle(plAg, origin, radAs);
                Curve  crvAs = NurbsCurve.CreateFromCircle(crcAs);

                AsCrv.Add(crvAs);
                AsCrvArea[i] = areaAs;
            }


            double startAg0 = 0;

            AgCrv[0].ClosestPoint(new Point3d(0, 0, 0), out startAg0);
            AgCrv[0].ChangeClosedCurveSeam(startAg0);
            double startAs0 = 0;

            AgCrv[0].ClosestPoint(new Point3d(0, 0, 0), out startAs0);
            AgCrv[0].ChangeClosedCurveSeam(startAs0);

            double  newStartAg = 0;
            Point3d startAg    = new Point3d();
            double  newStartAs = 0;
            Point3d startAs    = new Point3d();

            for (int i = 1; i < AgCrv.Count; i++)
            {
                if (AgCrv[i] != null && AgCrv[i - 1] != null)
                {
                    if (!Curve.DoDirectionsMatch(AgCrv[i], AgCrv[0]))
                    {
                        AgCrv[i].Reverse();
                    }
                    startAg = AgCrv[i - 1].PointAtStart;
                    AgCrv[i].ClosestPoint(startAg, out newStartAg);
                    AgCrv[i].ChangeClosedCurveSeam(newStartAg);
                }

                if (AsCrv[i] != null && AsCrv[i - 1] != null)
                {
                    if (!Curve.DoDirectionsMatch(AsCrv[i], AsCrv[0]))
                    {
                        AsCrv[i].Reverse();
                    }
                    startAs = AsCrv[i - 1].PointAtStart;
                    AsCrv[i].ClosestPoint(startAs, out newStartAs);
                    AsCrv[i].ChangeClosedCurveSeam(newStartAs);
                }
            }


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

            Curve[] AsCrvArray = AsCrv.ToArray();
            Array.Sort(AsCrvArea, AsCrvArray);
            double AsCrvAreaMax = AsCrvArea[AsCrvArea.Length - 1];
            double radAsMax     = Math.Sqrt(AsCrvAreaMax / Math.PI) / 1000; //radius in m
            Curve  AsCrvMax     = AsCrvArray[AsCrvArray.Length - 1];

            if (fix != false)
            {
                for (int i = 0; i < AsCrv.Count; i++)
                {
                    Circle newCrcAs = new Circle(planesAg[i], origins[i], radAsMax);
                    Curve  newCrvAs = NurbsCurve.CreateFromCircle(newCrcAs);
                    finalAsCrv.Add(newCrvAs);
                }
            }
            else
            {
                finalAsCrv = AsCrv;
            }

            if (finalAsCrv.Count == 0 || AgCrv.Count == 0)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "One or both outputs are empty, check input loads and geometry!");
                return;
            }

            DA.SetDataList(0, AgCrv);
            DA.SetDataList(1, finalAsCrv);
        }