Esempio n. 1
0
        /// <summary>
        /// Create Edge (Circle) from Dynamo Circle.
        /// </summary>
        public static Geometry.Edge FromDynamoCircle(Autodesk.DesignScript.Geometry.Circle obj)
        {
            double    radius      = obj.Radius;
            FdPoint3d centerPoint = FdPoint3d.FromDynamo(obj.CenterPoint);

            // lcs
            FdCoordinateSystem cs = FdCoordinateSystem.FromDynamoCurve(obj);

            // return
            return(new Geometry.Edge(radius, centerPoint, cs));
        }
Esempio n. 2
0
        /// <summary>
        /// Create Edge (Line) from Dynamo NurbsCurve.
        /// </summary>
        public static Geometry.Edge FromDynamoLinearNurbsCurve(Autodesk.DesignScript.Geometry.NurbsCurve obj)
        {
            FdPoint3d startPoint = FdPoint3d.FromDynamo(obj.StartPoint);
            FdPoint3d endPoint   = FdPoint3d.FromDynamo(obj.EndPoint);

            // lcs
            FdCoordinateSystem cs = FdCoordinateSystem.FromDynamoCurve(obj);

            // return
            return(new Geometry.Edge(startPoint, endPoint, cs));
        }
Esempio n. 3
0
        /// <summary>
        /// Create Edge (Arc2) from Dynamo Arc.
        /// Used for bar definition.
        /// </summary>
        public static Geometry.Edge FromDynamoArc2(Autodesk.DesignScript.Geometry.Arc obj)
        {
            FdPoint3d p0 = FdPoint3d.FromDynamo(obj.StartPoint);
            FdPoint3d p1 = FdPoint3d.FromDynamo(obj.PointAtParameter(0.5));
            FdPoint3d p2 = FdPoint3d.FromDynamo(obj.EndPoint);

            // lcs
            FdCoordinateSystem cs = FdCoordinateSystem.FromDynamoCurve(obj);

            // return
            return(new Geometry.Edge(p0, p1, p2, cs));
        }
Esempio n. 4
0
        /// <summary>
        /// Create Edge (Arc1) from Dynamo Arc.
        /// </summary>
        public static Geometry.Edge FromDynamoArc1(Autodesk.DesignScript.Geometry.Arc obj)
        {
            double     radius      = obj.Radius;
            double     startAngle  = 0;
            double     endAngle    = startAngle + Degree.ToRadians(obj.SweepAngle);
            FdPoint3d  centerPoint = FdPoint3d.FromDynamo(obj.CenterPoint);
            FdVector3d xAxis       = new FdVector3d(centerPoint, FdPoint3d.FromDynamo(obj.StartPoint)).Normalize();

            // lcs
            FdCoordinateSystem cs = FdCoordinateSystem.FromDynamoCurve(obj);

            // return
            return(new Geometry.Edge(radius, startAngle, endAngle, centerPoint, xAxis, cs));
        }
        /// <summary>
        /// Create FdCoordinateSystem from Dynamo coordinate system on curve mid u-point.
        /// </summary>
        internal static FdCoordinateSystem FromDynamoCurve(Autodesk.DesignScript.Geometry.Curve obj)
        {
            // CoordinateSystemAtParameter returns a coordinate system on curve
            // with origin at the point at the given parameter.
            // The XAxis is aligned with the curve normal,
            // the YAxis is aligned with the curve tangent at this point,
            // and the ZAxis is aligned with the up-vector or binormal at this point
            Autodesk.DesignScript.Geometry.CoordinateSystem cs = obj.CoordinateSystemAtParameter(0.5);

            // Note: Arcs and Circles in Dynamo are defined with left-hand rule while coordinate system is defined by right-hand rule
            if (obj.GetType() == typeof(Autodesk.DesignScript.Geometry.Arc) || obj.GetType() == typeof(Autodesk.DesignScript.Geometry.Circle))
            {
                return(FdCoordinateSystem.FromDynamoCoordinateSystemArcOrCircle(cs));
            }
            else
            {
                return(FromDynamoCoordinateSystemLine(cs));
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Create region by points and coordinate system.
        /// </summary>
        /// <param name="points">List of sorted points defining the outer perimeter of the region.</param>
        /// <param name="coordinateSystem">Coordinate system of the region</param>
        public Region(List <FdPoint3d> points, FdCoordinateSystem coordinateSystem)
        {
            // edge normal
            FdVector3d edgeLocalY = coordinateSystem.LocalZ;

            List <Edge> edges = new List <Edge>();

            for (int idx = 0; idx < points.Count; idx++)
            {
                // startPoint
                FdPoint3d p0 = p0 = points[idx];

                // endPoint
                FdPoint3d p1;
                if (idx != points.Count - 1)
                {
                    p1 = points[idx + 1];
                }

                else
                {
                    p1 = points[0];
                }

                // create edge
                edges.Add(new Edge(p0, p1, edgeLocalY));
            }

            // create contours
            Contour contour = new Contour(edges);

            // set properties
            this.Contours = new List <Contour> {
                contour
            };
            this.CoordinateSystem = coordinateSystem;
        }
Esempio n. 7
0
 public Region(List <Contour> contours, FdCoordinateSystem coordinateSystem)
 {
     this.Contours         = contours;
     this.CoordinateSystem = coordinateSystem;
 }
Esempio n. 8
0
        /// <summary>
        /// Create Region from Dynamo surface.
        /// </summary>
        public static Geometry.Region FromDynamo(Autodesk.DesignScript.Geometry.Surface obj)
        {
            // get all perimeter curves
            // curves[] is ordered by the loops of the surface.
            // the assumption here is that the loop with the largest circumference (i.e. the outline) is placed first in the array
            // for fd definition it is neccessary that the outline is the first contour, the subsequent loops can have any order.
            Autodesk.DesignScript.Geometry.Curve[] curves = obj.PerimeterCurves();

            // find closed outlines
            List <Autodesk.DesignScript.Geometry.Curve>         perimeterCurves = new List <Autodesk.DesignScript.Geometry.Curve>();
            List <List <Autodesk.DesignScript.Geometry.Curve> > container       = new List <List <Autodesk.DesignScript.Geometry.Curve> >();

            Autodesk.DesignScript.Geometry.Point pA0, pA1, pB0, pB1;
            // control if new perimeter
            // this happens is pA0/pA1 != pB0/pB1
            for (int idx = 0; idx < curves.Length; idx++)
            {
                if (idx == 0)
                {
                    perimeterCurves.Add(curves[idx]);
                }

                else
                {
                    pA0 = curves[idx - 1].StartPoint;
                    pA1 = curves[idx - 1].EndPoint;
                    pB0 = curves[idx].StartPoint;
                    pB1 = curves[idx].EndPoint;

                    // using Autodesk.DesignScript.Geometry.Point.Equals causes tolerance errors
                    // instead Autodesk.DesignScript.Geometry.Point.IsAlmostEqualTo is used
                    // note that this can cause errors as it is unclear what tolerance IsAlmostEqualTo uses
                    // another alternative would be to create an extension method, Equal(Point point, double tolerance), to Autodesk.DesignScript.Geometry.Point
                    if (pA0.IsAlmostEqualTo(pB0) || pA0.IsAlmostEqualTo(pB1) || pA1.IsAlmostEqualTo(pB0) || pA1.IsAlmostEqualTo(pB1))
                    {
                        perimeterCurves.Add(curves[idx]);
                    }

                    // new perimeter
                    else
                    {
                        container.Add(new List <Autodesk.DesignScript.Geometry.Curve>(perimeterCurves));
                        perimeterCurves.Clear();
                        perimeterCurves.Add(curves[idx]);
                    }
                }
            }
            // add last perimeter to container
            container.Add(new List <Autodesk.DesignScript.Geometry.Curve>(perimeterCurves));
            perimeterCurves.Clear();

            // control if direction is consistent
            // as FromRhinoBrep.
            foreach (List <Autodesk.DesignScript.Geometry.Curve> items in container)
            {
                // if Contour consists of one curve.
                if (items.Count == 1)
                {
                    // check if curve is a Circle

                    // if curve is not a Circle, raise error.
                }

                // if Contour consists of more than one curve.
                else
                {
                    // using Autodesk.DesignScript.Geometry.Point.Equals causes tolerance errors
                    // instead Autodesk.DesignScript.Geometry.Point.IsAlmostEqualTo is used
                    // note that this can cause errors as it is unclear what tolerance IsAlmostEqualTo uses
                    // another alternative would be to create an extension method, Equal(Point point, double tolerance), to Autodesk.DesignScript.Geometry.Point
                    for (int idx = 0; idx < items.Count - 1; idx++)
                    {
                        // curve a = items[idx]
                        // curve b = items[idx + 1]
                        pA0 = items[idx].StartPoint;
                        pA1 = items[idx].EndPoint;
                        pB0 = items[idx + 1].StartPoint;
                        pB1 = items[idx + 1].EndPoint;

                        if (pA0.IsAlmostEqualTo(pB0))
                        {
                            if (idx == 0)
                            {
                                items[idx] = items[idx].Reverse();
                            }
                            else
                            {
                                throw new System.ArgumentException("pA0 == pB0 even though idx != 0. Bad outline.");
                            }
                        }

                        else if (pA0.IsAlmostEqualTo(pB1))
                        {
                            if (idx == 0)
                            {
                                items[idx]     = items[idx].Reverse();
                                items[idx + 1] = items[idx + 1].Reverse();
                            }
                            else
                            {
                                throw new System.ArgumentException("pA0 == pB1 even though idx != 0. Bad outline.");
                            }
                        }

                        else if (pA1.IsAlmostEqualTo(pB0))
                        {
                            // pass
                        }

                        else if (pA1.IsAlmostEqualTo(pB1))
                        {
                            items[idx + 1] = items[idx + 1].Reverse();
                        }

                        else
                        {
                            throw new System.ArgumentException("Can't close outline. Bad outline.");
                        }
                    }
                }
            }

            // create contours
            List <Geometry.Edge>    edges    = new List <Geometry.Edge>();
            List <Geometry.Contour> contours = new List <Geometry.Contour>();

            foreach (List <Autodesk.DesignScript.Geometry.Curve> items in container)
            {
                foreach (Autodesk.DesignScript.Geometry.Curve curve in items)
                {
                    edges.Add(Geometry.Edge.FromDynamo(curve));
                }
                contours.Add(new Geometry.Contour(new List <Edge>(edges)));
                edges.Clear();
            }

            // get LCS
            FdCoordinateSystem cs = FdCoordinateSystem.FromDynamoSurface(obj);

            // return
            return(new Geometry.Region(contours, cs));
        }
 /// <summary>
 /// Create FdCoordinateSystem from Dynamo coordinate system on surface mid u/v-point.
 /// </summary>
 internal static FdCoordinateSystem FromDynamoSurface(Autodesk.DesignScript.Geometry.Surface obj)
 {
     Autodesk.DesignScript.Geometry.CoordinateSystem cs = obj.CoordinateSystemAtParameter(0.5, 0.5);
     return(FdCoordinateSystem.FromDynamoCoordinateSystemSurface(cs));
 }