Ejemplo n.º 1
0
        /***************************************************/

        public static RHG.Vector3d ToRhino(this BHG.Vector vector)
        {
            if (vector == null)
            {
                return(default(RHG.Vector3d));
            }

            return(new RHG.Vector3d(vector.X, vector.Y, vector.Z));
        }
Ejemplo n.º 2
0
        /***************************************************/

        public static bool NormalAwayFromSpace(this BHG.Polyline pline, List <BHE.BuildingElement> elementsAsSpace)
        {
            List <BHG.Point> centrePtList = new List <BHG.Point>();

            BHG.Point centrePt = pline.Centre();
            centrePtList.Add(centrePt);

            if (!pline.IsClosed())
            {
                return(false);                   //Prevent failures of the clockwise check
            }
            List <BHG.Point> pts = BH.Engine.Geometry.Query.DiscontinuityPoints(pline);

            if (pts.Count < 3)
            {
                return(false);               //Protection in case there aren't enough points to make a plane
            }
            BHG.Plane plane = BH.Engine.Geometry.Create.Plane(pts[0], pts[1], pts[2]);



            //The polyline can be locally concave. Check if the polyline is clockwise.
            if (!BH.Engine.Geometry.Query.IsClockwise(pline, plane.Normal))
            {
                plane.Normal = -plane.Normal;
            }

            if (!BH.Engine.Geometry.Query.IsContaining(pline, centrePtList, false))
            {
                BHG.Point  pointOnLine = BH.Engine.Geometry.Query.ClosestPoint(pline, centrePt);
                BHG.Vector vector      = new BHG.Vector();
                if (BH.Engine.Geometry.Query.Distance(pointOnLine, centrePt) > BH.oM.Geometry.Tolerance.MicroDistance)
                {
                    vector = pointOnLine - centrePt;
                }
                else
                {
                    BHG.Line line = BH.Engine.Geometry.Query.GetLineSegment(pline, pointOnLine);
                    vector = ((line.Start - line.End).Normalise()).CrossProduct(plane.Normal);
                }

                centrePt = BH.Engine.Geometry.Modify.Translate(pointOnLine, BH.Engine.Geometry.Modify.Normalise(vector) * 0.001);
            }

            //Move centrepoint along the normal.
            if (BH.Engine.Environment.Query.IsContaining(elementsAsSpace, centrePt.Translate(plane.Normal * 0.01)))
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Ejemplo n.º 3
0
        /***************************************************/

        public static bool IsEqual(this BHG.Vector bhVector, RHG.Vector3f rhVector, double tolerance = BHG.Tolerance.Distance)
        {
            if (bhVector == null & rhVector == default(RHG.Vector3f))
            {
                return(true);
            }

            return(Math.Abs(bhVector.X - rhVector.X) < tolerance &&
                   Math.Abs(bhVector.Y - rhVector.Y) < tolerance &&
                   Math.Abs(bhVector.Z - rhVector.Z) < tolerance);
        }
Ejemplo n.º 4
0
        public static SpeckleVector ToSpeckle(this BHG.Vector bhomVector)
        {
            if (bhomVector == null)
            {
                return(default(SpeckleVector));
            }

            SpeckleVector speckleVector = new SpeckleVector(bhomVector.X, bhomVector.Y, bhomVector.X);

            return(speckleVector);
        }
Ejemplo n.º 5
0
        /***************************************************/

        public static RHG.Cone ToRhino(this BHG.Cone cone)
        {
            if (cone == null)
            {
                return(default(RHG.Cone));
            }

            BHG.Vector axis  = cone.Axis * -1.0;
            RHG.Plane  plane = new RHG.Plane((cone.Centre + cone.Axis.Normalise() * cone.Height).ToRhino(), axis.ToRhino());

            return(new RHG.Cone(plane, cone.Height, cone.Radius));
        }
Ejemplo n.º 6
0
        /***************************************************/
        /**** Public Methods                            ****/
        /***************************************************/

        public static double Orientation(IBuildingObject buildingPanel)
        {
            Panel panel = buildingPanel as Panel;

            BHG.Polyline pLine = new BHG.Polyline {
                ControlPoints = panel.PanelCurve.IControlPoints()
            };

            List <BHG.Point> pts = pLine.DiscontinuityPoints();

            BHG.Plane plane = BH.Engine.Geometry.Create.Plane(pts[0], pts[1], pts[2]); //Some protection on this needed maybe?

            BHG.Vector xyNormal = BH.Engine.Geometry.Create.Vector(0, 1, 0);

            return(BH.Engine.Geometry.Query.Angle(plane.Normal, xyNormal) * (180 / Math.PI));
        }
Ejemplo n.º 7
0
        /***************************************************/

        public static BHG.IGeometry FromRhino(this RHG.Extrusion extrusion)
        {
            if (extrusion == null)
            {
                return(null);
            }

            RHG.LineCurve line    = extrusion.PathLineCurve();
            BHG.Vector    extrVec = BH.Engine.Geometry.Create.Vector(line.PointAtStart.FromRhino(), line.PointAtEnd.FromRhino());

            List <BHG.Extrusion> extrs = new List <BHG.Extrusion>();

            // Exploits the fact that GetWireframe returns first the "profile" curves of the extrusion.
            var profileCurves = extrusion.GetWireframe();

            for (int i = 0; i < extrusion.ProfileCount; i++)
            {
                var           profileConverted = profileCurves.ElementAt(i).FromRhino();
                BHG.Extrusion extr             = BH.Engine.Geometry.Create.Extrusion(profileConverted, extrVec, extrusion.IsCappedAtBottom && extrusion.IsCappedAtTop);

                extrs.Add(extr);
            }


            if (extrs.Count == 1)
            {
                return(extrs[0]);
            }

            if (extrs.Count > 1)
            {
                return new BH.oM.Geometry.CompositeGeometry()
                       {
                           Elements = extrs.OfType <BH.oM.Geometry.IGeometry>().ToList()
                       }
            }
            ;

            BH.Engine.Reflection.Compute.RecordError("Could not convert the extrusion.");
            return(null);
        }
Ejemplo n.º 8
0
        /***************************************************/

        public static double Azimuth(this BHG.Polyline pline, BHG.Vector refVector)
        {
            double azimuth;

            List <BHG.Point> pts = BH.Engine.Geometry.Query.DiscontinuityPoints(pline);

            if (pts.Count < 3 || !BH.Engine.Geometry.Query.IsClosed(pline))
            {
                return(-1);                                                            //Protection in case there aren't enough points to make a plane
            }
            BHG.Plane plane = BH.Engine.Geometry.Create.Plane(pts[0], pts[1], pts[2]);

            //The polyline can be locally concave. Check if the polyline is clockwise.
            if (!BH.Engine.Geometry.Query.IsClockwise(pline, plane.Normal))
            {
                plane.Normal = -plane.Normal;
            }

            if (Geometry.Modify.Normalise(plane.Normal).Z == 1)
            {
                azimuth = 0;
            }
            else if (Geometry.Modify.Normalise(plane.Normal).Z == -1)
            {
                azimuth = 180;
            }
            else
            {
                BHG.Vector v1 = Geometry.Modify.Project(plane.Normal, BHG.Plane.XY);
                BHG.Vector v2 = (Geometry.Modify.Project(refVector, BHG.Plane.XY));

                azimuth = (BH.Engine.Geometry.Query.SignedAngle(v1, v2, BHG.Vector.ZAxis) * (180 / Math.PI));
                if (azimuth < 0)
                {
                    azimuth = 360 + azimuth;
                }
            }
            return(azimuth);
        }
Ejemplo n.º 9
0
        public static BHG.Point ToLatLon(this BHG.Point point, GeoReference geoReference)
        {
            BHG.Vector vector = point - geoReference.Reference;
            //vector in plane
            vector.Z = 0;
            double degLatInM  = 10000000.0 / 90;
            double bearing    = vector.SignedAngle(BHG.Vector.YAxis, BHG.Vector.ZAxis);
            double DeltaNorth = vector.Length() * Math.Cos(bearing) / degLatInM;
            double DeltaEast  = vector.Length() * Math.Sin(bearing) / Math.Cos(geoReference.ReferenceLatitude * Math.PI / 180) / degLatInM;

            if (geoReference.AltitudeMode == AltitudeMode.Absolute)
            {
                point.Z += geoReference.ReferenceAltitude;
            }

            return(new BHG.Point()
            {
                X = geoReference.ReferenceLongitude + DeltaEast,
                Y = geoReference.ReferenceLatitude + DeltaNorth,
                Z = point.Z
            });
            //https://gis.stackexchange.com/questions/5821/calculating-latitude-longitude-x-miles-from-point
        }
Ejemplo n.º 10
0
        /***************************************************/
        /**** Public Methods                            ****/
        /***************************************************/

        public static double Azimuth(this BHEI.IBuildingObject buildingElementGeometry, BHG.Vector refVector)
        {
            BHG.Polyline pline = new BHG.Polyline {
                ControlPoints = BH.Engine.Geometry.Query.IControlPoints(buildingElementGeometry.ICurve())
            };

            double azimuth = Azimuth(pline, refVector);

            return(azimuth);
        }
Ejemplo n.º 11
0
        /***************************************************/

        public static void RenderMeshes(BHG.Vector vector, Rhino.Display.DisplayPipeline pipeline, DisplayMaterial material)
        {
            return;
        }
Ejemplo n.º 12
0
        /***************************************************/

        public static void RenderWires(BHG.Vector vector, Rhino.Display.DisplayPipeline pipeline, Color bhColour)
        {
            //args.Pipeline.DrawLineArrow(vector.ToRhino(), args.Color, args.Thickness, args.Thickness);
        }