コード例 #1
0
ファイル: Ellipse.cs プロジェクト: l2obin/Dynamo
        public override FScheme.Value Evaluate(FSharpList <FScheme.Value> args)
        {
            var ptA  = ((FScheme.Value.Container)args[0]).Item;
            var radX = (double)((FScheme.Value.Number)args[1]).Item;
            var radY = (double)((FScheme.Value.Number)args[2]).Item;

            Autodesk.Revit.DB.Ellipse ell = null;

            if (ptA is XYZ)
            {
                ell = dynRevitSettings.Doc.Application.Application.Create.NewEllipse(
                    //ptA, radX, radY, XYZ.BasisX, XYZ.BasisY, 0, 2 * Math.PI
                    (XYZ)ptA, radX, radY, XYZ.BasisX, XYZ.BasisY, 0, 2 * RevitPI
                    );
            }
            else if (ptA is ReferencePoint)
            {
                ell = dynRevitSettings.Doc.Application.Application.Create.NewEllipse(
                    //ptA, radX, radY, XYZ.BasisX, XYZ.BasisY, 0, 2 * Math.PI
                    (XYZ)((ReferencePoint)ptA).Position, radX, radY, XYZ.BasisX, XYZ.BasisY, 0, 2 * RevitPI
                    );
            }
            else if (ptA is Transform)
            {
                Transform trf    = ptA as Transform;
                XYZ       center = trf.Origin;
                ell = dynRevitSettings.Doc.Application.Application.Create.NewEllipse(
                    //ptA, radX, radY, XYZ.BasisX, XYZ.BasisY, 0, 2 * Math.PI
                    center, radX, radY, trf.BasisX, trf.BasisY, 0, 2 * RevitPI
                    );
            }

            return(FScheme.Value.NewContainer(ell));
        }
コード例 #2
0
        public static NurbsCurve ToRhino(this DB.Ellipse ellipse)
        {
            var plane      = new Plane(ellipse.Center.ToRhino(), new Vector3d(ellipse.XDirection.ToRhino()), new Vector3d(ellipse.YDirection.ToRhino()));
            var e          = new Ellipse(plane, ellipse.RadiusX, ellipse.RadiusY);
            var nurbsCurve = e.ToNurbsCurve();

            return(ellipse.IsBound ?
                   nurbsCurve.Trim(ellipse.GetEndParameter(0), ellipse.GetEndParameter(1)) as NurbsCurve :
                   nurbsCurve);
        }
コード例 #3
0
        public static NurbsCurve ToRhino(this DB.Ellipse ellipse)
        {
            var plane      = new Plane(ellipse.Center.ToRhino(), new Vector3d(ellipse.XDirection.ToRhino()), new Vector3d(ellipse.YDirection.ToRhino()));
            var e          = new Ellipse(plane, ellipse.RadiusX, ellipse.RadiusY);
            var nurbsCurve = e.ToNurbsCurve();

            if (ellipse.IsBound)
            {
                nurbsCurve.ClosestPoint(ellipse.GetEndPoint(0).ToRhino(), out var param0);
                nurbsCurve.ClosestPoint(ellipse.GetEndPoint(1).ToRhino(), out var param1);
                nurbsCurve        = nurbsCurve.Trim(param0, param1) as NurbsCurve;
                nurbsCurve.Domain = new Interval(ellipse.GetEndParameter(0), ellipse.GetEndParameter(1));
            }

            return(nurbsCurve);
        }
コード例 #4
0
        private static Autodesk.DesignScript.Geometry.Curve Convert(Autodesk.Revit.DB.Ellipse crv)
        {
            var isFullEllipse = !crv.IsBound ||
                                Math.Abs(Math.Abs(crv.GetEndParameter(1) - crv.GetEndParameter(0)) - 2 * Math.PI) < 1e-6;

            if (isFullEllipse)
            {
                return
                    (Autodesk.DesignScript.Geometry.Ellipse.ByOriginVectors(
                         crv.Center.ToPoint(false),
                         (crv.XDirection * crv.RadiusX).ToVector(false),
                         (crv.YDirection * crv.RadiusY).ToVector(false)));
            }

            // We need to define the major and minor axis as the curve
            // will be trimmed starting from the major axis (not the xaxis)
            var major = Math.Max(crv.RadiusX, crv.RadiusY);
            var minor = Math.Min(crv.RadiusX, crv.RadiusY);

            Vector majorAxis;
            Vector minorAxis;

            double startParam;

            var span = Math.Abs(crv.GetEndParameter(0) - crv.GetEndParameter(1)).ToDegrees();

            if (crv.RadiusX > crv.RadiusY)
            {
                majorAxis  = crv.XDirection.ToVector();
                minorAxis  = crv.YDirection.ToVector();
                startParam = crv.GetEndParameter(0).ToDegrees();
            }
            else
            {
                majorAxis  = crv.YDirection.ToVector().Reverse();
                minorAxis  = crv.XDirection.ToVector();
                startParam = crv.GetEndParameter(0).ToDegrees() + 90;
            }

            using (var pl = Plane.ByOriginXAxisYAxis(crv.Center.ToPoint(false), majorAxis, minorAxis))
            {
                return(EllipseArc.ByPlaneRadiiStartAngleSweepAngle(pl, major, minor, startParam, span));
            }
        }
コード例 #5
0
        private static Autodesk.DesignScript.Geometry.Curve Convert(Autodesk.Revit.DB.Ellipse crv)
        {
            var isComplete = !crv.IsBound ||
                             Math.Abs(Math.Abs(crv.GetEndParameter(1) - crv.GetEndParameter(0)) - 2 * Math.PI) < 1e-6;

            if (!isComplete)
            {
                var pl = Plane.ByOriginXAxisYAxis(crv.Center.ToPoint(),
                                                  crv.XDirection.ToVector(), crv.YDirection.ToVector());

                var s = crv.GetEndParameter(0).ToDegrees();
                var e = crv.GetEndParameter(1).ToDegrees();

                return(EllipseArc.ByPlaneRadiiStartAngleSweepAngle(pl, crv.RadiusX, crv.RadiusY, s, e - s));
            }

            return(Autodesk.DesignScript.Geometry.Ellipse.ByOriginVectors(crv.Center.ToPoint(),
                                                                          (crv.XDirection * crv.RadiusX).ToVector(), (crv.YDirection * crv.RadiusY).ToVector()));
        }
コード例 #6
0
        public static NurbsCurve ToRhino(DB.Ellipse ellipse)
        {
            var plane      = new Plane(AsPoint3d(ellipse.Center), AsVector3d(ellipse.XDirection), AsVector3d(ellipse.YDirection));
            var e          = new Ellipse(plane, ellipse.RadiusX, ellipse.RadiusY);
            var nurbsCurve = e.ToNurbsCurve();

            if (ellipse.IsBound)
            {
                nurbsCurve.ClosestPoint(AsPoint3d(ellipse.GetEndPoint(0)), out var param0);
                if (!nurbsCurve.ChangeClosedCurveSeam(param0))
                {
                    nurbsCurve.Domain = new Interval(param0, param0 + nurbsCurve.Domain.Length);
                }

                nurbsCurve.ClosestPoint(AsPoint3d(ellipse.GetEndPoint(1)), out var param1);
                nurbsCurve        = nurbsCurve.Trim(param0, param1) as NurbsCurve;
                nurbsCurve.Domain = new Interval(ellipse.GetEndParameter(0), ellipse.GetEndParameter(1));
            }

            return(nurbsCurve);
        }
コード例 #7
0
        private static Autodesk.DesignScript.Geometry.Curve Convert(Autodesk.Revit.DB.Ellipse crv)
        {
            var isFullEllipse = !crv.IsBound ||
                                Math.Abs(Math.Abs(crv.GetEndParameter(1) - crv.GetEndParameter(0)) - 2 * Math.PI) < 1e-6;

            if (isFullEllipse)
            {
                return
                    (Autodesk.DesignScript.Geometry.Ellipse.ByOriginVectors(
                         crv.Center.ToPoint(false),
                         (crv.XDirection * crv.RadiusX).ToVector(false),
                         (crv.YDirection * crv.RadiusY).ToVector(false)));
            }
            double startParam;

            var span = Math.Abs(crv.GetEndParameter(0) - crv.GetEndParameter(1)).ToDegrees();

            startParam = crv.GetEndParameter(0).ToDegrees();
            using (var pl = Plane.ByOriginXAxisYAxis(crv.Center.ToPoint(false), crv.XDirection.ToVector(), crv.YDirection.ToVector()))
            {
                return(EllipseArc.ByPlaneRadiiAngles(pl, crv.RadiusX, crv.RadiusY, startParam, span));
            }
        }
コード例 #8
0
ファイル: AnalysisDisplay.cs プロジェクト: l2obin/Dynamo
        public override Value Evaluate(FSharpList <Value> args)
        {
            this.ClearPreviousResults();

            //unwrap the values
            IEnumerable <double> nvals = ((Value.List)args[0]).Item.Select(q => (double)((Value.Number)q).Item);

            var curve = (Curve)((Value.Container)args[1]).Item;

            SpatialFieldManager = (Autodesk.Revit.DB.Analysis.SpatialFieldManager)((Value.Container)args[2]).Item;

            if (!SpatialFieldManager.IsResultSchemaNameUnique(DYNAMO_TEMP_CURVES_SCHEMA, -1))
            {
                IList <int> arses = SpatialFieldManager.GetRegisteredResults();
                foreach (int i in arses)
                {
                    AnalysisResultSchema arsTest = SpatialFieldManager.GetResultSchema(i);
                    if (arsTest.Name == DYNAMO_TEMP_CURVES_SCHEMA)
                    {
                        schemaId = i;
                        break;
                    }
                }
            }
            else
            {
                var ars = new AnalysisResultSchema(DYNAMO_TEMP_CURVES_SCHEMA, "Temporary curves from Dynamo.");
                schemaId = SpatialFieldManager.RegisterResult(ars);
            }

            Transform trf = Transform.Identity;

            //http://thebuildingcoder.typepad.com/blog/2012/09/sphere-creation-for-avf-and-filtering.html#3

            var create = dynRevitSettings.Doc.Application.Application.Create;

            Transform t = curve.ComputeDerivatives(0, true);

            XYZ x = t.BasisX.Normalize();
            XYZ y = t.BasisX.IsAlmostEqualTo(XYZ.BasisZ) ?
                    t.BasisX.CrossProduct(XYZ.BasisY).Normalize() :
                    t.BasisX.CrossProduct(XYZ.BasisZ).Normalize();
            XYZ z = x.CrossProduct(y);

            Autodesk.Revit.DB.Ellipse arc1 = dynRevitSettings.Revit.Application.Create.NewEllipse(t.Origin, .1, .1, y, z, -Math.PI, 0);
            Autodesk.Revit.DB.Ellipse arc2 = dynRevitSettings.Revit.Application.Create.NewEllipse(t.Origin, .1, .1, y, z, 0, Math.PI);

            var pathLoop = new Autodesk.Revit.DB.CurveLoop();

            pathLoop.Append(curve);
            var profileLoop = new Autodesk.Revit.DB.CurveLoop();

            profileLoop.Append(arc1);
            profileLoop.Append(arc2);

            double curveDomain = curve.get_EndParameter(1) - curve.get_EndParameter(0);

            int idx = -1;
            var s   = GeometryCreationUtilities.CreateSweptGeometry(pathLoop, 0, 0, new List <Autodesk.Revit.DB.CurveLoop> {
                profileLoop
            });

            foreach (Face face in s.Faces)
            {
                //divide the V domain by the number of incoming
                BoundingBoxUV domain = face.GetBoundingBox();
                double        vSpan  = domain.Max.V - domain.Min.V;

                //analysis values
                idx = SpatialFieldManager.AddSpatialFieldPrimitive(face, trf);

                //a list to hold the analysis points
                IList <UV> uvPts = new List <UV>();

                //a list to hold the analysis values
                IList <ValueAtPoint> valList = new List <ValueAtPoint>();

                //int count = nvals.Count();

                //this is creating a lot of sample points, but if we used less
                //sampling points, AVF would draw the two surfaces as if there was a hard
                //edge between them. this provides a better blend.
                int count = 10;
                for (int i = 0; i < count; i++)
                {
                    //get a UV point on the face
                    //find its XYZ location and project to
                    //the underlying curve. find the value which corresponds
                    //to the location on the curve
                    var uv  = new UV(domain.Min.U, domain.Min.V + vSpan / count * (double)i);
                    var uv1 = new UV(domain.Max.U, domain.Min.V + vSpan / count * (double)i);
                    uvPts.Add(uv);
                    uvPts.Add(uv1);

                    XYZ facePt                    = face.Evaluate(uv);
                    IntersectionResult ir         = curve.Project(facePt);
                    double             curveParam = curve.ComputeNormalizedParameter(ir.Parameter);

                    if (curveParam < 0)
                    {
                        curveParam = 0;
                    }

                    if (curveParam > 1)
                    {
                        curveParam = 1;
                    }

                    var valueIndex = (int)Math.Floor(curveParam * (double)nvals.Count());
                    if (valueIndex >= nvals.Count())
                    {
                        valueIndex = nvals.Count() - 1;
                    }

                    //create list of values at this point - currently supporting only one
                    //var doubleList = new List<double> { nvals.ElementAt(i) };
                    var doubleList = new List <double> {
                        nvals.ElementAt(valueIndex)
                    };

                    //add value at point object containing the value list
                    valList.Add(new ValueAtPoint(doubleList));
                    valList.Add(new ValueAtPoint(doubleList));
                }

                var pnts = new FieldDomainPointsByUV(uvPts);
                var vals = new FieldValues(valList);

                SpatialFieldManager.UpdateSpatialFieldPrimitive(
                    idx, pnts, vals, schemaId);

                PastResultIds.Add(idx);
            }

            return(Value.NewNumber(idx));
        }
コード例 #9
0
 public static Curve ToCurve(this DB.Ellipse value)
 {
     var rhino = RawDecoder.ToRhino(value); UnitConverter.Scale(rhino, UnitConverter.ToRhinoUnits); return(rhino);
 }
コード例 #10
0
 public static NurbsCurve ToRhino(this DB.Ellipse ellipse) => RawDecoder.ToRhino(ellipse);