public void EllipseArc_Basic()
        {
            var o          = Point.ByCoordinates(1, 2, 3);
            var n          = Vector.ByCoordinates(2, 3, 4, true);
            var pl         = Autodesk.DesignScript.Geometry.Plane.ByOriginNormal(o, n);
            var ellipseArc = EllipseArc.ByPlaneRadiiStartAngleSweepAngle(pl, 10, 5, 45, 90);

            var revitCurve = ellipseArc.ToRevitType(false);

            Assert.NotNull(revitCurve);
            Assert.IsAssignableFrom <Autodesk.Revit.DB.Ellipse>(revitCurve);

            var revitEllipse = (Autodesk.Revit.DB.Ellipse)revitCurve;

            revitEllipse.GetEndParameter(0).ToDegrees().ShouldBeApproximately(ellipseArc.StartAngle);
            revitEllipse.GetEndParameter(1).ToDegrees().ShouldBeApproximately(ellipseArc.StartAngle + ellipseArc.SweepAngle);
            revitEllipse.GetEndPoint(0).ShouldBeApproximately(ellipseArc.StartPoint);
            revitEllipse.GetEndPoint(1).ShouldBeApproximately(ellipseArc.EndPoint);

            revitEllipse.Length.ShouldBeApproximately(ellipseArc.Length);

            // ClosestPointTo fails in ProtoGeometry
            var tessPts = revitEllipse.Tessellate().Select(x => x.ToPoint(false));

            //assert the tesselation is very close to original curve
            foreach (var pt in tessPts)
            {
                var closestPt = ellipseArc.ClosestPointTo(pt);
                Assert.Less(closestPt.DistanceTo(pt), 1e-6);
            }
        }
        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));
            }
        }
Beispiel #3
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()));
        }