示例#1
0
        public static IEnumerable <Parasite_Line> ToParasiteType(IEnumerable <Autodesk.DesignScript.Geometry.Curve> curves)
        {
            Parasite_Line[] output = new Parasite_Line[curves.Count()];

            for (int i = 0; i < curves.Count(); i++)
            {
                Autodesk.DesignScript.Geometry.Curve crv = curves.ElementAt(i);



                ////THIS IS FAILING IN DIFFERENT CASES FOR SOME REASON
                //Vector tanVecStrt = crv.ToNurbsCurve().TangentAtParameter(0.25/*crv.StartParameter()*/);
                //Vector tanVecEnd = crv.ToNurbsCurve().TangentAtParameter(0.50/*crv.EndParameter()*/);

                //// TODO  WETHER CURVE IS LINEAR
                //if (tanVecStrt.Dot(tanVecEnd) !=1.0)
                //    throw new ParasiteArgumentException("Cant convert a Dynamo Curve to a Parasite_Line!");

                ////THIS IS FAILING IN DIFFERENT CASES FOR SOME REASON

                output[i] = new Parasite_Line(ToParasiteType(crv.StartPoint), ToParasiteType(crv.EndPoint), null);
            }

            return(output);
        }
示例#2
0
 protected LoftedSurface(Curve[] crossSections, Curve path,bool persist)
     : base(FromCrossSectionsPathCore(crossSections, path),persist)
 {
     InitializeGuaranteedProperties();
     CrossSections = crossSections;
     Path = path;
 }
        private IEnumerable <GeometryObject> Tessellate(Curve curve)
        {
            var result = new List <GeometryObject>();

            // use the ASM tesselation of the curve
            var pkg = renderPackageFactory.CreateRenderPackage();

            curve.Tessellate(pkg, renderPackageFactory.TessellationParameters);

            // get necessary info to enumerate and convert the lines
            //var lineCount = pkg.LineVertexCount * 3 - 3;
            var verts = pkg.LineStripVertices.ToList();

            // we scale the tesselation rather than the curve
            var conv = UnitConverter.DynamoToHostFactor(UnitType.UT_Length);

            var scaledXYZs = new List <XYZ>();

            for (var i = 0; i < verts.Count; i += 3)
            {
                scaledXYZs.Add(new XYZ(verts[i] * conv, verts[i + 1] * conv, verts[i + 2] * conv));
            }
            result.Add(PolyLine.Create(scaledXYZs));

            return(result);
        }
示例#4
0
        public static DS.Ellipse GetAsEllipse(this DS.Curve curve)
        {
            if (!curve.IsClosed)
            {
                throw new ArgumentException("Curve is not closed, cannot be an Ellipse");
            }

            double[] parameters = new double[4] {
                0, 0.25, 0.5, 0.75
            };
            DS.Point[] points = parameters.Select(p => curve.PointAtParameter(p)).ToArray();
            double     a      = points[0].DistanceTo(points[2]) * 0.5; // Max Radius
            double     b      = points[1].DistanceTo(points[3]) * 0.5; // Min Radius

            using (DS.Point centre = DS.Point.ByCoordinates(Median(points[0].X, points[2].X),
                                                            Median(points[0].Y, points[2].Y), Median(points[0].Z, points[2].Z)))
            {
                points.ForEach(p => p.Dispose());

                return(DS.Ellipse.ByPlaneRadii(
                           DS.Plane.ByOriginNormalXAxis(centre, curve.Normal, DS.Vector.ByTwoPoints(centre, curve.StartPoint)),
                           a,
                           b
                           ));
            }
        }
示例#5
0
 protected SweptSurface(Curve profile, Curve path,bool persist)
     : base(ByProfilePathCore(profile, path),persist)
 {
     InitializeGuaranteedProperties();
     Profile = profile;
     Path = path;
 }
示例#6
0
 protected LoftedSurface(Curve[] crossSections, Curve[] guides, bool persist)
     : base(FromCrossSectionsGuidesCore(crossSections, guides),persist)
 {
     InitializeGuaranteedProperties();
     CrossSections = crossSections;
     Guides = guides;
 }
示例#7
0
        public static bool IsEllipse(this DS.Curve curve)
        {
            try
            {
                if (!curve.IsClosed)
                {
                    return(false);
                }

                //http://www.numericana.com/answer/ellipse.htm
                double[] parameters = new double[4] {
                    0, 0.25, 0.5, 0.75
                };
                DS.Point[] points = parameters.Select(p => curve.PointAtParameter(p)).ToArray();
                double     a      = points[0].DistanceTo(points[2]) * 0.5; // Max Radius
                double     b      = points[1].DistanceTo(points[3]) * 0.5; // Min Radius
                points.ForEach(p => p.Dispose());

                double h         = Math.Pow(a - b, 2) / Math.Pow(a + b, 2);
                double perimeter = Math.PI * (a + b) * (1 + (3 * h / (10 + Math.Sqrt(4 - 3 * h))));

                return(Threshold(curve.Length, perimeter, 1e-5)); //Ellipse perimeter is an approximation
            }
            catch (Exception e)
            {
                return(false);
            }
        }
示例#8
0
        //族实例化,创建族并对其进行旋转
        private FamilyInstance CreateFamlyInstance(DG.Point DGpoint, DG.Curve curve, FamilySymbol FamilySymbol, ExternalCommandData commandData)
        {
            UIDocument uiDoc = commandData.Application.ActiveUIDocument; //取得当前活动文档

            XYZ point = DGpoint.ToRevitType(false);                      //dynamo转Revit

            FamilyInstance familyInstance = uiDoc.Document.Create.NewFamilyInstance(point, FamilySymbol, Autodesk.Revit.DB.Structure.StructuralType.NonStructural);
            LocationPoint  locationPoint  = familyInstance.Location as LocationPoint;//自适应族基点
            XYZ            axisP          = new XYZ(point.X, point.Y, point.Z + 100);

            Autodesk.Revit.DB.Line axis = Autodesk.Revit.DB.Line.CreateBound(point, axisP);//旋转轴

            //计算旋转角度
            double ratio = curve.ParameterAtPoint(DGpoint);

            DG.Vector vector = curve.TangentAtParameter(ratio);

            MessageBox.Show(vector.ToString());

            DG.Vector vector1 = DG.Vector.ByCoordinates(vector.X, vector.Y, 0);//三维切向量的平面向量
            DG.Vector vectorY = DG.Vector.ByCoordinates(0, 1, 0);
            double    angle   = vector1.AngleWithVector(vectorY) / 180 * Math.PI;

            MessageBox.Show(angle.ToString());
            //locationPoint.Rotate(axis, angle);//旋转横梁
            ElementTransformUtils.RotateElement(uiDoc.Document, familyInstance.Id, axis, -angle);

            return(familyInstance);
        }
示例#9
0
        public static Dictionary <string, object> CurveSinusoidalPoints(
            Autodesk.DesignScript.Geometry.Curve _Curve,
            double WaveLength = 5.0,
            double Amplitude  = 1.0,
            double Resolution = 2.0)
        {
            double n     = (_Curve.Length / WaveLength) * 4 * Resolution;
            double _Span = _Curve.Length / n;
            List <Autodesk.DesignScript.Geometry.Point> points = new List <Autodesk.DesignScript.Geometry.Point>();
            List <double> ks = new List <double>();

            for (int i = 0; i < n; i++)
            {
                double k = Amplitude * Math.Sin(i * _Span * Math.PI * 2 / WaveLength + Math.PI * 2);
                Autodesk.DesignScript.Geometry.Plane pl = _Curve.PlaneAtParameter(_Curve.ParameterAtSegmentLength(i * _Span));
                Autodesk.DesignScript.Geometry.Point p  = _Curve.PointAtSegmentLength(i * _Span);
                points.Add((Autodesk.DesignScript.Geometry.Point)p.Translate(pl.YAxis, k));
                ks.Add(k);
            }

            return(new Dictionary <string, object>
            {
                { "Points", points },
                { "k", ks }
            });
        }
示例#10
0
        public static Dictionary <string, object> CurveSinusoidalPointsWithVoxel(
            Autodesk.DesignScript.Geometry.Curve _Curve,
            VoxelImage Voxel,
            double WaveLength = 5.0,
            double Amplitude  = 1.0,
            double Resolution = 2.0)
        {
            VoxelChannel _VoxelChannel = Voxel.GetChannel(VoxelImageLayout.SHAPECHANNEL);

            double n     = (_Curve.Length / WaveLength) * 4 * Resolution;
            double _Span = _Curve.Length / n;
            List <Autodesk.DesignScript.Geometry.Point> points = new List <Autodesk.DesignScript.Geometry.Point>();
            List <double> ks = new List <double>();

            for (int i = 0; i < n; i++)
            {
                Autodesk.DesignScript.Geometry.Plane pl = _Curve.PlaneAtParameter(_Curve.ParameterAtSegmentLength(i * _Span));
                Autodesk.DesignScript.Geometry.Point p  = _Curve.PointAtSegmentLength(i * _Span);
                double FieldValue = V2GVoxel.GetVoxelFieldValue(_VoxelChannel, p.X, p.Y, p.Z);

                double k = FieldValue * Amplitude * Math.Sin(i * _Span * Math.PI * 2 / WaveLength + Math.PI * 2);

                points.Add((Autodesk.DesignScript.Geometry.Point)p.Translate(pl.YAxis, k));
                ks.Add(k);
            }

            return(new Dictionary <string, object>
            {
                { "Points", points },
                { "k", ks }
            });
        }
示例#11
0
        /// <summary>
        /// Creates a Conduit by a curve.
        /// </summary>
        /// <param name="conduitType">Type of the conduit.</param>
        /// <param name="curve">The curve.</param>
        /// <param name="featureline">The featureline.</param>
        /// <returns></returns>
        public static Conduit ByCurveFeatureline(Revit.Elements.Element conduitType, Autodesk.DesignScript.Geometry.Curve curve, Featureline featureline)
        {
            Utils.Log(string.Format("Conduit.ByCurveFeatureline started...", ""));

            var totalTransform = RevitUtils.DocumentTotalTransform();

            if (!SessionVariables.ParametersCreated)
            {
                UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument);
            }

            var pipe = Conduit.ByCurve(conduitType, curve);  //  new Conduit(oType, s, e);

            var start = curve.StartPoint;
            var end   = curve.EndPoint;

            var startSOE = featureline.GetStationOffsetElevationByPoint(start);
            var endSOE   = featureline.GetStationOffsetElevationByPoint(end);

            double startStation   = (double)startSOE["Station"];
            double startOffset    = (double)startSOE["Offset"];
            double startElevation = (double)startSOE["Elevation"];
            double endStation     = (double)endSOE["Station"];
            double endOffset      = (double)endSOE["Offset"];
            double endElevation   = (double)endSOE["Elevation"];

            pipe.SetParameterByName(ADSK_Parameters.Instance.Corridor.Name, featureline.Baseline.CorridorName);
            pipe.SetParameterByName(ADSK_Parameters.Instance.BaselineIndex.Name, featureline.Baseline.Index);
            pipe.SetParameterByName(ADSK_Parameters.Instance.RegionIndex.Name, featureline.BaselineRegionIndex);                                                 // 1.1.0
            pipe.SetParameterByName(ADSK_Parameters.Instance.RegionRelative.Name, startStation - featureline.Start);                                             // 1.1.0
            pipe.SetParameterByName(ADSK_Parameters.Instance.RegionNormalized.Name, (startStation - featureline.Start) / (featureline.End - featureline.Start)); // 1.1.0
            pipe.SetParameterByName(ADSK_Parameters.Instance.Code.Name, featureline.Code);
            pipe.SetParameterByName(ADSK_Parameters.Instance.Side.Name, featureline.Side.ToString());
            pipe.SetParameterByName(ADSK_Parameters.Instance.X.Name, Math.Round(curve.StartPoint.X, 3));
            pipe.SetParameterByName(ADSK_Parameters.Instance.Y.Name, Math.Round(curve.StartPoint.Y, 3));
            pipe.SetParameterByName(ADSK_Parameters.Instance.Z.Name, Math.Round(curve.StartPoint.Z, 3));
            pipe.SetParameterByName(ADSK_Parameters.Instance.Station.Name, Math.Round(startStation, 3));
            pipe.SetParameterByName(ADSK_Parameters.Instance.Offset.Name, Math.Round(startOffset, 3));
            pipe.SetParameterByName(ADSK_Parameters.Instance.Elevation.Name, Math.Round(startElevation, 3));
            pipe.SetParameterByName(ADSK_Parameters.Instance.Update.Name, 1);
            pipe.SetParameterByName(ADSK_Parameters.Instance.Delete.Name, 0);
            pipe.SetParameterByName(ADSK_Parameters.Instance.EndStation.Name, Math.Round(endStation, 3));
            pipe.SetParameterByName(ADSK_Parameters.Instance.EndOffset.Name, Math.Round(endOffset, 3));
            pipe.SetParameterByName(ADSK_Parameters.Instance.EndElevation.Name, Math.Round(endElevation, 3));
            pipe.SetParameterByName(ADSK_Parameters.Instance.EndRegionRelative.Name, endStation - featureline.Start);                                             // 1.1.0
            pipe.SetParameterByName(ADSK_Parameters.Instance.EndRegionNormalized.Name, (endStation - featureline.Start) / (featureline.End - featureline.Start)); // 1.1.0

            if (start != null)
            {
                start.Dispose();
            }
            if (end != null)
            {
                end.Dispose();
            }

            Utils.Log(string.Format("Conduit.ByCurveFeatureline completed.", ""));

            return(pipe);
        }
示例#12
0
        /// <summary>
        /// Creates a Conduit by a curve.
        /// </summary>
        /// <param name="conduitType">Type of the conduit.</param>
        /// <param name="curve">The curve.</param>
        /// <returns></returns>
        public static Conduit ByCurve(Revit.Elements.Element conduitType, Autodesk.DesignScript.Geometry.Curve curve)
        {
            Utils.Log(string.Format("Conduit.ByCurve started...", ""));

            var totalTransform = RevitUtils.DocumentTotalTransform();

            if (!SessionVariables.ParametersCreated)
            {
                UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument);
            }
            var oType = conduitType.InternalElement as Autodesk.Revit.DB.Electrical.ConduitType;

            Autodesk.DesignScript.Geometry.Point start = curve.StartPoint.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point;
            var s = start.ToXyz();

            Autodesk.DesignScript.Geometry.Point end = curve.EndPoint.Transform(totalTransform) as Autodesk.DesignScript.Geometry.Point;
            var e = end.ToXyz();

            if (start != null)
            {
                start.Dispose();
            }
            if (end != null)
            {
                end.Dispose();
            }

            Utils.Log(string.Format("Conduit.ByCurve completed.", ""));

            return(new Conduit(oType, s, e));
        }
示例#13
0
        /// <summary>
        /// Convert a generic Circle to a Revit Curve
        /// </summary>
        /// <param name="crvCurve"></param>
        /// <returns></returns>
        private static Autodesk.Revit.DB.Curve Convert(Autodesk.DesignScript.Geometry.Curve crvCurve)
        {
            Autodesk.DesignScript.Geometry.Curve[] curves = crvCurve.ApproximateWithArcAndLineSegments();
            if (curves.Length == 1)
            {
                //line or arc?
                var point0   = crvCurve.PointAtParameter(0.0);
                var point1   = crvCurve.PointAtParameter(1.0);
                var pointMid = crvCurve.PointAtParameter(0.5);
                if (point0.DistanceTo(point1) > 1e-7)
                {
                    var line = Autodesk.DesignScript.Geometry.Line.ByStartPointEndPoint(point0, point1);
                    if (pointMid.DistanceTo(line) < 1e-7)
                    {
                        return(Convert(line));
                    }
                }
                //then arc
                if (point0.DistanceTo(point1) < 1e-7)
                {
                    point1 = crvCurve.PointAtParameter(0.9);
                }
                var arc = Autodesk.DesignScript.Geometry.Arc.ByThreePoints(point0, pointMid, point1);
                return(Convert(arc));
            }

            return(Convert(crvCurve.ToNurbsCurve()));
        }
示例#14
0
        public static Autodesk.DesignScript.Geometry.Curve ToProtoType(this Autodesk.Revit.DB.Curve revitCurve,
                                                                       bool performHostUnitConversion = true, Reference referenceOverride = null)
        {
            if (revitCurve == null)
            {
                throw new ArgumentNullException("revitCurve");
            }
            dynamic dyCrv = revitCurve;

            Autodesk.DesignScript.Geometry.Curve converted = RevitToProtoCurve.Convert(dyCrv);
            if (converted == null)
            {
                throw new Exception("An unexpected failure occurred when attempting to convert the curve");
            }
            if (performHostUnitConversion)
            {
                UnitConverter.ConvertToDynamoUnits(ref converted);
            }

            // If possible, add a geometry reference for downstream Element creation
            var revitRef = referenceOverride ?? revitCurve.Reference;

            if (revitRef != null)
            {
                converted.Tags.AddTag(ElementCurveReference.DefaultTag, revitRef);
            }

            return(converted);
        }
示例#15
0
 private static Autodesk.DesignScript.Geometry.Curve Transform(Autodesk.DesignScript.Geometry.Curve curve, CoordinateSystem coordinateSystem)
 {
     if (coordinateSystem == null)
     {
         return(curve);
     }
     return((curve as Autodesk.DesignScript.Geometry.Geometry).Transform(coordinateSystem) as Autodesk.DesignScript.Geometry.Curve);
 }
示例#16
0
 /// <summary>
 /// Creates a CableTray using the start and end points of a curve.
 /// </summary>
 /// <param name="cableTrayType">The CableTray Type.</param>
 /// <param name="curve">The Curve</param>
 /// <returns></returns>
 public static CableTray ByCurve(Revit.Elements.Element cableTrayType, Autodesk.DesignScript.Geometry.Curve curve)
 {
     if (!SessionVariables.ParametersCreated)
     {
         UtilsObjectsLocation.CheckParameters(DocumentManager.Instance.CurrentDBDocument);
     }
     return(CableTrayByCurve(cableTrayType, curve));
 }
示例#17
0
        public static object SnowDrift_ByEdgeHeight(Dyn.Curve edgeCurve, bool flipDirectioin, double snowLoad_ground_psf, double snowLoad_flatRoof_psf, double roofLength_lower_ft, double roofLength_upper_ft, double roofHeight_delta_ft, double adjustmentFactor_ft = 10.0)
        {
            sDynamoUtilities dynutil = new sDynamoUtilities();

            double designLen;
            double designHeight;
            double designMaxLoad;
            double designSnowDensity;

            dynutil.GetSnowDriftInformation(snowLoad_ground_psf, snowLoad_flatRoof_psf, roofHeight_delta_ft, roofLength_lower_ft, roofLength_upper_ft, out designLen, out designHeight, out designMaxLoad, out designSnowDensity);

            double fac = designLen;

            if (flipDirectioin)
            {
                fac *= -1;
            }

            Dyn.PolyCurve edgeCrvEx = Dyn.PolyCurve.ByJoinedCurves(new Dyn.Curve[1] {
                edgeCurve.ExtendStart(adjustmentFactor_ft).ExtendEnd(adjustmentFactor_ft)
            });
            Dyn.PolyCurve driftCrv_onRoof = Dyn.PolyCurve.ByJoinedCurves(new Dyn.Curve[1] {
                edgeCrvEx.Offset(fac)
            });
            Dyn.PolyCurve driftCrv_onEdge = Dyn.PolyCurve.ByJoinedCurves(new Dyn.Curve[1] {
                edgeCrvEx.Translate(Dyn.Vector.ZAxis().Scale(designHeight)) as Dyn.Curve
            });

            List <Dyn.Solid> snows = new List <Dyn.Solid>();

            for (int i = 0; i < driftCrv_onRoof.NumberOfCurves; ++i)
            {
                List <Dyn.PolyCurve> cs = new List <Dyn.PolyCurve>();
                cs.Add(Dyn.PolyCurve.ByPoints(new Dyn.Point[3] {
                    driftCrv_onRoof.CurveAtIndex(i).StartPoint, driftCrv_onEdge.CurveAtIndex(i).StartPoint, edgeCrvEx.CurveAtIndex(i).StartPoint
                }, true));
                cs.Add(Dyn.PolyCurve.ByPoints(new Dyn.Point[3] {
                    driftCrv_onRoof.CurveAtIndex(i).EndPoint, driftCrv_onEdge.CurveAtIndex(i).EndPoint, edgeCrvEx.CurveAtIndex(i).EndPoint
                }, true));
                snows.Add(Dyn.Solid.ByLoft(cs));
            }

            Dyn.Solid snowSolid = Dyn.Solid.ByUnion(snows);

            // edgeCrvEx.Dispose();
            // driftCrv_onEdge.Dispose();
            // driftCrv_onRoof.Dispose();

            return(new Dictionary <string, object>
            {
                { "DesignLength_ft", designLen },
                { "DesignHeight_ft", designHeight },
                { "DesignMaxLoad_psf", designMaxLoad },
                { "DesignDensity_pcf", designSnowDensity },
                { "DrfitVolumeSolid", snowSolid },
            });
        }
示例#18
0
        public static DS.Line GetAsLine(this DS.Curve curve)
        {
            if (curve.IsClosed)
            {
                throw new ArgumentException("Curve is closed, cannot be a Line");
            }

            return(DS.Line.ByStartPointEndPoint(curve.StartPoint, curve.EndPoint));
        }
示例#19
0
        /// <summary>
        /// Tessellate the curve:
        /// 1). If there are more than 2 points, create a polyline out of the points;
        /// 2). If there are exactly 2 points, create a line;
        /// 3). If there's exception thrown during the tessellation process, attempt to create
        /// a line from start and end points. If that fails, a point will be created instead.
        /// </summary>
        /// <param name="curve"></param>
        /// <returns></returns>
        private IEnumerable <GeometryObject> Tessellate(Curve curve)
        {
            var result = new List <GeometryObject>();

            try
            {
                // we scale the tesselation rather than the curve
                var conv = UnitConverter.DynamoToHostFactor(UnitType.UT_Length);

                // use the ASM tesselation of the curve
                var pkg = renderPackageFactory.CreateRenderPackage();
                curve.Tessellate(pkg, renderPackageFactory.TessellationParameters);

                // get necessary info to enumerate and convert the lines
                //var lineCount = pkg.LineVertexCount * 3 - 3;
                var verts = pkg.LineStripVertices.ToList();

                if (verts.Count > 2)
                {
                    var scaledXYZs = new List <XYZ>();
                    for (var i = 0; i < verts.Count; i += 3)
                    {
                        scaledXYZs.Add(new XYZ(verts[i] * conv, verts[i + 1] * conv, verts[i + 2] * conv));
                    }
                    result.Add(PolyLine.Create(scaledXYZs));
                }
                else if (verts.Count == 2)
                {
                    result.Add(Line.CreateBound(curve.StartPoint.ToXyz(), curve.EndPoint.ToXyz()));
                }
            }
            catch (Exception)
            {
                // Add a red bounding box geometry to identify that some errors occur
                var bbox = curve.BoundingBox;
                result.AddRange(ProtoToRevitMesh.CreateBoundingBoxMeshForErrors(bbox.MinPoint, bbox.MaxPoint));

                try
                {
                    result.Add(Line.CreateBound(curve.StartPoint.ToXyz(), curve.EndPoint.ToXyz()));
                }
                catch (Exception)
                {
                    try
                    {
                        result.Add(DocumentManager.Instance.CurrentUIApplication.Application.Create.NewPoint(curve.StartPoint.ToXyz()));
                    }
                    catch (ArgumentException)
                    {
                        //if either the X, Y or Z of the point is infinite, no need to add it for preview
                    }
                }
            }

            return(result);
        }
示例#20
0
 protected RevolvedSurface(Curve profile, Point axisOrigin, Vector axisDirection, double startAngle, double sweepAngle, bool persist)
     : base(ByProfileAxisOriginDirectionAngleCore(profile, axisOrigin, axisDirection, startAngle, sweepAngle), persist)
 {
     InitializeGuaranteedProperties();
     Profile = profile;
     AxisOrigin = axisOrigin;
     AxisDirection = axisDirection;
     StartAngle = startAngle;
     SweepAngle = sweepAngle;
 }
示例#21
0
        private double SelectPoint(ExternalCommandData commandData)
        {
            Document    revitDoc = commandData.Application.ActiveUIDocument.Document; //取得文档
            Application revitApp = commandData.Application.Application;               //取得应用程序
            UIDocument  uiDoc    = commandData.Application.ActiveUIDocument;          //取得当前活动文档

            Selection sel        = uiDoc.Selection;
            Reference ref1       = sel.PickObject(ObjectType.Element, "选择一条模型线");
            Element   elem       = revitDoc.GetElement(ref1);
            ModelLine modelLine1 = elem as ModelLine;

            Autodesk.Revit.DB.Curve curve1;
            //做一个判断,判断其是否为ModelNurbSpline
            if (modelLine1 == null)
            {
                ModelNurbSpline modelNurbSpline = elem as ModelNurbSpline;
                curve1 = modelNurbSpline.GeometryCurve;
            }
            else
            {
                curve1 = modelLine1.GeometryCurve;
            }


            Reference ref2 = sel.PickObject(ObjectType.Element, "选择一条模型线");

            elem = revitDoc.GetElement(ref2);
            ModelLine modelLine2 = elem as ModelLine;

            Autodesk.Revit.DB.Curve curve2;
            //做一个判断,判断其是否为ModelNurbSpline
            if (modelLine2 == null)
            {
                ModelNurbSpline modelNurbSpline = elem as ModelNurbSpline;
                curve2 = modelNurbSpline.GeometryCurve;
            }
            else
            {
                curve2 = modelLine2.GeometryCurve;
            }


            //删除第二条选中的线
            uiDoc.Document.Delete(elem.Id);
            //求交点
            curve1.Intersect(curve2, out IntersectionResultArray intersectionResultArray);
            XYZ pointIntersect = intersectionResultArray.get_Item(0).XYZPoint;

            //交点和线都转化为dynamo的点和线
            DG.Point dgP   = pointIntersect.ToPoint(false);
            DG.Curve dgC   = curve1.ToProtoType(false);
            double   ratio = dgC.ParameterAtPoint(dgP);

            return(ratio);
        }
示例#22
0
 protected RevolvedSurface(Curve profile, Line axis, double startAngle, double sweepAngle, bool persist)
     : base(ByProfileAxisAngleCore(profile, axis, startAngle, sweepAngle), persist)
 {
     InitializeGuaranteedProperties();
     Profile = profile;
     AxisOrigin = axis.StartPoint;
     AxisDirection = axis.Direction;
     StartAngle = startAngle;
     SweepAngle = sweepAngle;
     Axis = axis;
 }
示例#23
0
        /// <summary>
        /// Sort a series of curves in the shortest printing path.
        /// </summary>
        /// <param name="_curves"></param>
        /// <returns name="Curves"></returns>
        public static List <Autodesk.DesignScript.Geometry.Curve> SortPrintableCurves(List <Autodesk.DesignScript.Geometry.Curve> _curves)
        {
            List <Autodesk.DesignScript.Geometry.Curve> sortedCurves = new List <Autodesk.DesignScript.Geometry.Curve>();
            List <Autodesk.DesignScript.Geometry.Curve> curves       = new List <Autodesk.DesignScript.Geometry.Curve>();

            curves.AddRange(_curves); // Copying elements to curves to avoid modifying the original list of curves

            Autodesk.DesignScript.Geometry.Curve currentCurve = curves[curves.Count - 1];
            curves.RemoveAt(curves.Count - 1);
            sortedCurves.Add(currentCurve);

            // find ouf next curve either startpoint or endpoint is closest to the end point of the current curve

            while (curves.Count != 0)
            {
                int    bestI        = 0;
                double bestDistance = double.MaxValue;
                Autodesk.DesignScript.Geometry.Point currentPoint = currentCurve.EndPoint;
                for (int i = 0; i < curves.Count; ++i)
                {
                    Autodesk.DesignScript.Geometry.Curve c = curves[i];

                    Autodesk.DesignScript.Geometry.Line l1 = Autodesk.DesignScript.Geometry.Line.ByStartPointEndPoint(currentPoint, c.StartPoint);
                    Autodesk.DesignScript.Geometry.Line l2 = Autodesk.DesignScript.Geometry.Line.ByStartPointEndPoint(currentPoint, c.EndPoint);

                    double distanceToStartPoint = l1.Length;
                    double distanceToEndPoint   = l2.Length;

                    double d = Math.Min(distanceToStartPoint, distanceToEndPoint);

                    if (bestDistance > d)
                    {
                        bestI        = i;
                        bestDistance = d;
                    }
                }

                currentCurve = curves[bestI];
                curves.RemoveAt(bestI);

                double distanceToCurrentCurveEndPoint   = Autodesk.DesignScript.Geometry.Line.ByStartPointEndPoint(currentPoint, currentCurve.EndPoint).Length;
                double distanceToCurrentCurveStartPoint = Autodesk.DesignScript.Geometry.Line.ByStartPointEndPoint(currentPoint, currentCurve.StartPoint).Length;

                if (distanceToCurrentCurveEndPoint < distanceToCurrentCurveStartPoint)
                {
                    currentCurve = currentCurve.Reverse();
                }

                sortedCurves.Add(currentCurve);
            }

            return(sortedCurves);
        }
示例#24
0
        public static DS.Arc GetAsArc(this DS.Curve curve)
        {
            if (curve.IsClosed)
            {
                throw new ArgumentException("Curve is closed, cannot be an Arc");
            }

            using (DS.Point midPoint = curve.PointAtParameter(0.5))
            {
                return(DS.Arc.ByThreePoints(curve.StartPoint, midPoint, curve.EndPoint));
            }
        }
示例#25
0
        private static ISurfaceEntity FromCurveCore(Curve profile)
        {
            if (null == profile)
                throw new System.ArgumentNullException("profile");
            if (!profile.IsClosed || profile.IsSelfIntersecting)
                throw new System.ArgumentException(string.Format(Properties.Resources.CurveNotClosed), "profile");

            ISurfaceEntity entity = HostFactory.Factory.SurfacePatchFromCurve(profile.CurveEntity);
            if (entity == null)
                throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "Surface.CreateFromCurve"));
            return entity;
        }
示例#26
0
        private static ISurfaceEntity ByProfilePathCore(Curve profile, Curve path)
        {
            if (null == profile)
                throw new System.ArgumentNullException("profile");

            if (null == path)
                throw new System.ArgumentNullException("path");

            ISurfaceEntity entity = HostFactory.Factory.SurfaceBySweep(profile.CurveEntity, path.CurveEntity);
            if (entity == null)
                throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "SweptSurface.ByProfilePath"));
            return entity;
        }
示例#27
0
        public void ByCurveAndEqualDivisions_NullArgument()
        {
            // build dividedPath
            ElementCurveReference faceRef = null;

            Assert.Throws(typeof(ArgumentNullException), () => DividedPath.ByCurveAndDivisions(faceRef, 5));

            Autodesk.DesignScript.Geometry.Curve surface = null;
            Assert.Throws(typeof(ArgumentNullException), () => DividedPath.ByCurveAndDivisions(surface, 5));

            Revit.Elements.Element element = null;
            Assert.Throws(typeof(ArgumentNullException), () => DividedPath.ByCurveAndDivisions(element, 5));
        }
示例#28
0
        public static DividedPath ByCurveAndDivisions(Autodesk.DesignScript.Geometry.Curve curve, int divisions)
        {
            if (curve == null)
            {
                throw new ArgumentNullException("curve");
            }

            if (divisions < 2)
            {
                throw new Exception("The number of divisions must be greater than 2!");
            }

            return(new DividedPath(new[] { ElementCurveReference.TryGetCurveReference(curve) }, divisions));
        }
示例#29
0
 /// <summary>
 /// creates slices using a curve as the spine
 /// </summary>
 /// <param name="solid">Solid: geometry that is to be parsed</param>
 /// <param name="curve">Curve: defines the normal used to create cut planes perpendicular to parameter "plane".
 /// If curve is too short, it will be extended using built-in extend function</param>
 /// <param name="thickness">Thickness: the thickness of the slices, or the thickness of the material to be used for the assembly</param>
 /// <param name="spacing">Spacing: the distance between each slice</param>
 /// <returns>A newly-constructed Slicer object</returns>
 internal Slicer(Solid solid, Curve curve, double thickness, double spacing, double origin)
 {
     Solid = solid;
     Thickness = thickness;
     Spacing = spacing;
     Plane plane = Plane.ByOriginNormal(curve.StartPoint, curve.Normal);
     Curve curvePlanar = curve;
     if(!curve.IsPlanar)
     {
         plane = Plane.ByBestFitThroughPoints(curve.ToNurbsCurve().ControlPoints());
         curvePlanar = curve.PullOntoPlane(plane);
     }
     CutPlanesPrimary.AddRange(GenerateCutPlanes(plane));
     CutPlanesSecondary.AddRange(GenerateCutPlanes(curvePlanar, origin));
     InitialGeometry = new List<Geometry>(1){curvePlanar};
 }
示例#30
0
        public static Autodesk.Revit.DB.Curve ToRevitType(this Autodesk.DesignScript.Geometry.Curve crv,
                                                          bool performHostUnitConversion = true)
        {
            crv = performHostUnitConversion ? crv.InHostUnits() : crv;

            dynamic dyCrv = crv;

            Autodesk.Revit.DB.Curve converted = ProtoToRevitCurve.Convert(dyCrv);

            if (converted == null)
            {
                throw new Exception("An unexpected failure occurred when attempting to convert the curve");
            }

            return(converted);
        }
示例#31
0
        internal List <Dyn.PolyCurve> SplitSegmentizeCurveByCurves(Dyn.Curve c, List <Dyn.Curve> crvs, double intTol, double segTol, out List <Dyn.PolyCurve> segCrvs, out List <Dyn.Point> associatedPts, List <Dyn.Point> pts = null)
        {
            List <Dyn.Geometry>  disposeGeo = new List <Dyn.Geometry>();
            List <Dyn.PolyCurve> pls        = new List <Dyn.PolyCurve>();
            List <Dyn.PolyCurve> segcrvs    = new List <Dyn.PolyCurve>();
            List <Dyn.Point>     assPts     = new List <Dyn.Point>();

            foreach (Dyn.Curve spc in SplitCurveByCurves(c, crvs, intTol, out assPts, pts))
            {
                int segCount = (int)(spc.Length / segTol);
                ////////////
                //Do not segmentize if spc is straight line.... How????
                //How to deal with nurbsCurve?
                ////////////
                if (IsLineCurve(spc))
                {
                    segCount = 0;
                }

                List <Dyn.Point> segPts = new List <Dyn.Point>();
                if (segCount < 1)
                {
                    segPts.Add(spc.StartPoint);
                    segPts.Add(spc.EndPoint);
                }
                else
                {
                    segPts.Add(spc.StartPoint);
                    foreach (Dyn.Point sp in spc.PointsAtEqualSegmentLength(segCount))
                    {
                        segPts.Add(sp);
                        disposeGeo.Add(sp);
                    }
                    segPts.Add(spc.EndPoint);
                }

                segcrvs.Add(Dyn.PolyCurve.ByJoinedCurves(new Dyn.Curve[] { spc }));

                Dyn.PolyCurve pl = Dyn.PolyCurve.ByPoints(segPts);
                pls.Add(pl);
            }
            segCrvs       = segcrvs;
            associatedPts = assPts;

            DisposeGeometries(disposeGeo);
            return(pls);
        }
        public static global::Revit.Elements.Element ByLine(Curve curve, bool drawInPlan = true)
        {
            Document doc    = DocumentManager.Instance.CurrentDBDocument;
            Vector   normal = Vector.ZAxis();

            if (!drawInPlan)
            {
                normal = curve.NormalAtParameter(0.5);
            }

            TransactionManager.Instance.EnsureInTransaction(doc);
            var refPlane = doc.Create.NewReferencePlane(curve.StartPoint.ToRevitType(), curve.EndPoint.ToRevitType(), normal.ToRevitType(), doc.ActiveView);

            TransactionManager.Instance.TransactionTaskDone();

            return(refPlane.ToDSType(true));
        }
示例#33
0
 internal Dyn.Curve ToDynamoCurve(sCurve sc)
 {
     Dyn.Curve rc = null;
     if (sc.curveType == eCurveType.LINE)
     {
         rc = ToDynamoLine(sc as sLine) as Dyn.Curve;
     }
     else if (sc.curveType == eCurveType.POLYLINE)
     {
         rc = ToDynamoPolyCurve(sc as sPolyLine) as Dyn.Curve;
     }
     else if (sc.curveType == eCurveType.NURBSCURVE)
     {
         //rc = ToRhinoNurbsCurve(sc as sNurbsCurve);
     }
     return(rc);
 }
示例#34
0
        internal bool IsLineCurve(Dyn.Curve c)
        {
            double lenC = c.Length;

            Dyn.Line ln   = Dyn.Line.ByStartPointEndPoint(c.StartPoint, c.EndPoint);
            double   lenL = ln.Length;

            ln.Dispose();
            if (Math.Abs(lenC - lenL) < 0.001)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#35
0
        public static bool IsLinear(this DS.Curve curve)
        {
            try
            {
                if (curve.IsClosed)
                {
                    return(false);
                }

                //Dynamo cannot be trusted when less than 1e-6
                var extremesDistance = curve.StartPoint.DistanceTo(curve.EndPoint);
                return(Threshold(curve.Length, extremesDistance));
            }
            catch (Exception e)
            {
                return(false);
            }
        }
示例#36
0
        public static DS.Circle GetAsCircle(this DS.Curve curve)
        {
            if (!curve.IsClosed)
            {
                throw new ArgumentException("Curve is not closed, cannot be a Circle");
            }

            DS.Point start = curve.StartPoint;
            using (DS.Point midPoint = curve.PointAtParameter(0.5))
                using (DS.Point centre = DS.Point.ByCoordinates(Median(start.X, midPoint.X), Median(start.Y, midPoint.Y),
                                                                Median(start.Z, midPoint.Z)))
                {
                    return(DS.Circle.ByCenterPointRadiusNormal(
                               centre,
                               centre.DistanceTo(start),
                               curve.Normal
                               ));
                }
        }
示例#37
0
        /// <summary>
        /// Creates a simplified version of the curve by creating lines with a maximum length defined.
        /// </summary>
        /// <param name="curve">Curve to polygonize</param>
        /// <param name="maxLength">Maximum length of subdivisions</param>
        /// <param name="asPolycurve">If true returns a Polycurve or a list of lines otherwise.</param>
        /// <returns></returns>
        public static object Polygonize(DSCurve curve, double maxLength, bool asPolycurve = false)
        {
            //TODO : Look into http://www.antigrain.com/research/adaptive_bezier/index.html
            if (curve == null)
            {
                throw new ArgumentNullException("curve");
            }
            List <DSCurve> lines      = new List <DSCurve>();
            bool           isStraight = curve.Length.AlmostEqualTo(curve.StartPoint.DistanceTo(curve.EndPoint));

            if (isStraight)
            {
                lines.Add(curve);
            }
            else
            {
                int divisions = (int)Math.Ceiling(curve.Length / maxLength);
                if (divisions > 1)
                {
                    var points = curve.PointsAtEqualSegmentLength(divisions);
                    lines.Add(Line.ByStartPointEndPoint(curve.StartPoint, points.First()));
                    for (var i = 0; i < points.Count() - 1; i++)
                    {
                        lines.Add(Line.ByStartPointEndPoint(points[i], points[i + 1]));
                    }
                    lines.Add(Line.ByStartPointEndPoint(points.Last(), curve.EndPoint));
                }
                else
                {
                    lines.Add(Line.ByStartPointEndPoint(curve.StartPoint, curve.EndPoint));
                }
            }

            if (asPolycurve)
            {
                return(PolyCurve.ByJoinedCurves(lines));
            }
            else
            {
                return(lines);
            }
        }
示例#38
0
        public static bool IsCircle(this DS.Curve curve)
        {
            try
            {
                if (!curve.IsClosed)
                {
                    return(false);
                }

                using (DS.Point midPoint = curve.PointAtParameter(0.5))
                {
                    double radius = curve.StartPoint.DistanceTo(midPoint) * 0.5;
                    return(Threshold(radius, (curve.Length) / (2 * Math.PI)));
                }
            }
            catch (Exception e)
            {
                return(false);
            }
        }
        protected override void AssignInputNodes()
        {
            curve = null;
            NodeModel curveNode;
            CanManipulateInputNode(0, out curveNode);
            if (null == curveNode)
                return; //Not enough input to manipulate

            if (!CanManipulateInputNode(1, out inputNode))
                return;

            try
            {
                curve = GetFirstValueFromNode(curveNode) as Curve;
                if (null == curve)
                    return;
            }
            catch (Exception ex) 
            { 
                return; 
            }
        }
示例#40
0
 /// <summary>
 /// Construct a Surface by revolving the profile curve about an axis 
 /// defined by axisOrigin point and axisDirection Vector. startAngle 
 /// determines where the curve starts to revolve, sweepAngle determines 
 /// the extent of the revolve.
 /// </summary>
 /// <param name="profile">Profile Curve for revolve surface.</param>
 /// <param name="axisOrigin">Origin Point for axis of revolution.</param>
 /// <param name="axisDirection">Direction Vector for axis of revolution.</param>
 /// <param name="startAngle">Start Angle in degreee at which curve starts to revolve.</param>
 /// <param name="sweepAngle">Sweep Angle in degree to define the extent of revolve.</param>
 /// <returns>RevolvedSurface</returns>
 public static RevolvedSurface ByProfileAxisOriginDirectionAngle(Curve profile, Point axisOrigin, Vector axisDirection, double startAngle, double sweepAngle)
 {
     return new RevolvedSurface(profile, axisOrigin, axisDirection, startAngle, sweepAngle, true);
 }
示例#41
0
 private static ISurfaceEntity ByProfileAxisAngleCore(Curve profile, Line axis, double startAngle, double sweepAngle)
 {
     if (null == axis)
         throw new System.ArgumentNullException("axis");
     ISurfaceEntity surf = ByProfileAxisOriginDirectionAngleCore(profile, axis.StartPoint, axis.Direction, startAngle, sweepAngle);
     if (null == surf)
         throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "RevolvedSurface.ByProfileAxisAngle"));
     return surf;
 }
示例#42
0
 /// <summary>
 /// Construct a Surface by revolving  curve about a line axis. startAngle 
 /// determines where the curve starts to revolve, sweepAngle determines 
 /// the revolving angle.
 /// </summary>
 /// <param name="profile">Profile Curve for revolve surface.</param>
 /// <param name="axis">Line to define axis of revolution.</param>
 /// <param name="startAngle">Start Angle in degreee at which curve starts to revolve.</param>
 /// <param name="sweepAngle">Sweep Angle in degree to define the extent of revolve.</param>
 /// <returns>RevolvedSurface</returns>
 public static RevolvedSurface ByProfileAxisAngle(Curve profile, Line axis, double startAngle, double sweepAngle)
 {
     return new RevolvedSurface(profile, axis, startAngle, sweepAngle, true);
 }
示例#43
0
 /// <summary>
 /// Construct a Surface by revolving the profile curve about an axis
 /// defined by axisOrigin point and axisDirection Vector.
 /// Assuming sweep angle = 360 and start angle = 0.
 /// </summary>
 /// <param name="profile">Profile Curve for revolve surface.</param>
 /// <param name="axisOrigin">Origin Point for axis of revolution.</param>
 /// <param name="axisDirection">Direction Vector for axis of revolution.</param>
 /// <returns>RevolvedSurface</returns>
 public static RevolvedSurface ByProfileAxisOriginDirection(Curve profile, Point axisOrigin, Vector axisDirection)
 {
     return new RevolvedSurface(profile, axisOrigin, axisDirection, 0, 360, true);
 }
示例#44
0
 protected PatchSurface(Curve profile,bool persist)
     : base(FromCurveCore(profile), persist)
 {
     InitializeGuaranteedProperties();
     Profile = profile;
 }
示例#45
0
 /// <summary>
 /// Construct a LoftedSurface by lofting an array of curve cross sections and 
 /// using curve(s) as the guide to control the lofting shape.
 /// </summary>
 /// <remarks>
 /// If the cross-section curves do not intersect with the guide curves, 
 /// then these cross-section are ignored.
 /// </remarks>
 /// <param name="crossSections">crossSections (curves) needs to be all closed or all open.</param>
 /// <param name="guides">The guides needs to intersect with all crossSections.</param>
 /// <returns>LoftedSurface</returns>
 public static LoftedSurface FromCrossSectionsGuides(Curve[] crossSections, Curve[] guides)
 {
     return new LoftedSurface(crossSections, guides, true);
 }
示例#46
0
        private static ISurfaceEntity FromCrossSectionsPathCore(Curve[] crossSections, Curve path)
        {
            if (null == path)
                throw new System.ArgumentException(string.Format(Properties.Resources.NullArgument, "path"), "path");

            bool isClosed = crossSections[0].IsClosed;
            //Validation
            ICurveEntity[] hostXCurves = crossSections.ConvertAll((Curve c) => GeometryExtension.GetCurveEntity(c, isClosed));
            if (hostXCurves == null || hostXCurves.Length < 2)
                throw new System.ArgumentException(string.Format(Properties.Resources.InvalidArguments, "cross sections"), "crossSections");

            ISurfaceEntity entity = HostFactory.Factory.SurfaceByLoftCrossSectionsPath(hostXCurves, path.CurveEntity);
            if (entity == null)
                throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "Surface.LoftFromCrossSectionsPath"));
            return entity;
        }
示例#47
0
        /// <summary>
        /// Constructors a plane on a curve by given distance. 
        /// </summary>
        /// <param name="contextCurve"></param>
        /// <param name="distance">Curvilinear distance.</param>
        /// <returns></returns>
        public static Plane AtDistance(Curve contextCurve, double distance)
        {
            if (null == contextCurve)
                throw new ArgumentNullException("contextCurve");

            return contextCurve.PlaneAtDistance(distance);
        }
示例#48
0
 /// <summary>
 /// Construct a LoftedSurface by lofting an array of curve cross sections and 
 /// using a curve as lofting path to control the lofting direction.
 /// </summary>
 /// <param name="crossSections">crossSections (curves) needs to be all closed or all open.</param>
 /// <param name="path">lofting path curve.</param>
 /// <returns>Loftedsurface</returns>
 public static LoftedSurface FromCrossSectionsPath(Curve[] crossSections, Curve path)
 {
     return new LoftedSurface(crossSections, path, true);
 }
示例#49
0
        private static ISurfaceEntity FromCrossSectionsGuidesCore(Curve[] crossSections, Curve[] guides)
        {
            bool isClosed = crossSections[0].IsClosed;
            //Validation
            ICurveEntity[] hostXCurves = crossSections.ConvertAll((Curve c) => GeometryExtension.GetCurveEntity(c, isClosed));
            if (hostXCurves == null || hostXCurves.Length < 2)
                throw new System.ArgumentException(string.Format(Properties.Resources.InvalidArguments, "cross sections"), "crossSections");

            ICurveEntity[] hostGuides = guides.ConvertAll(GeometryExtension.ToEntity<Curve, ICurveEntity>);
            if (hostGuides == null || hostGuides.Length < 1)
                throw new System.ArgumentException(string.Format(Properties.Resources.InvalidArguments, "guides"), "guides");

            ISurfaceEntity entity = HostFactory.Factory.SurfaceByLoftCrossSectionsGuides(hostXCurves, hostGuides);
            if (entity == null)
                throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "Surface.LoftFromCrossSectionsGuides"));
            return entity;
        }
示例#50
0
        /// <summary>
        /// Constructor that does the same as CoordinateSystem.AtParameter but that it checks if the z-axis is
        /// in the same general direction as the given upVector. If not, it flips the z-axis to make it point 
        /// in the same overall direction as the upVector and also flips the y-axis accordingly to preserve 
        /// the right-handed CoordinateSystem rule.
        /// </summary>
        /// <param name="contextCurve"></param>
        /// <param name="t"></param>
        /// <param name="upVector"></param>
        /// <returns></returns>
        public static CoordinateSystem AtParameter(Curve contextCurve, double t, Vector upVector)
        {
            if (contextCurve == null)
                throw new System.ArgumentNullException("contextCurve");
            else if (upVector == null)
                throw new System.ArgumentNullException("upVector");
            else if (upVector.IsZeroVector())
                throw new System.ArgumentException(string.Format(Properties.Resources.IsZeroVector, "up vector"), "upVector");

            var cs = contextCurve.CoordinateSystemAtParameterCore(t, upVector);
            if (null == cs)
                throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "CoordinateSystem.AtParameter"));

            //  property assigments
            //
            cs.ContextCurve = contextCurve;
            cs.T = t;
            cs.Distance = contextCurve.DistanceAtParameter(t);
            cs.UpVector = upVector;

            return cs;
        }
示例#51
0
        /// <summary>
        /// Constructs a a CoordinateSystem with its origin at the given parameter on the given curve. Its x-axis is tangential to the curve, 
        /// y-axis is along the normal and z-axis is along bi-normal at that point. This method is complementary to the 
        /// CoordinateSystemAtParameterAlongCurve() method in Curve class and has consistent behavior.
        /// </summary>
        /// <param name="contextCurve"></param>
        /// <param name="t"></param>
        /// <returns></returns>
        public static CoordinateSystem AtParameter(Curve contextCurve, double t)
        {
            if (contextCurve == null)
                throw new System.ArgumentNullException("contextCurve");

            var cs = contextCurve.CoordinateSystemAtParameterCore(t, null);
            if (null == cs)
                throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "CoordinateSystem.AtParameter"));

            cs.ContextCurve = contextCurve;
            cs.T = t;
            cs.Distance = contextCurve.DistanceAtParameter(t);

            return cs;
        }
示例#52
0
 public TwoCurves(Curve curve1) { this.Curve1 = curve1; this.Curve2 = null; Undefined = new List<Curve>(); }
示例#53
0
        private static ISurfaceEntity ByProfileAxisOriginDirectionAngleCore(Curve profile, Point axisOrigin, Vector axisDirection, double startAngle, double sweepAngle)
        {
            if (null == profile)
                throw new System.ArgumentException(string.Format(Properties.Resources.NullArgument, "profile"), "profile");

            if (null == axisOrigin)
                throw new System.ArgumentException(string.Format(Properties.Resources.NullArgument, "axis origin"), "axisOrigin");

            if (null == axisDirection)
                throw new System.ArgumentException(string.Format(Properties.Resources.NullArgument, "axis direction"), "axisDirection");

            ISurfaceEntity entity = HostFactory.Factory.SurfaceByRevolve(profile.CurveEntity, axisOrigin.PointEntity, axisDirection.IVector, startAngle, sweepAngle);
            if (entity == null)
                throw new System.Exception(string.Format(Properties.Resources.OperationFailed, "Surface.Revolve"));
            return entity;
        }
示例#54
0
 /// <summary>
 /// Construct a Surface by sweeping a profile curve along a path curve.
 /// </summary>
 /// <param name="profile">Profile curve for sweep.</param>
 /// <param name="path">Path curve to sweep along.</param>
 /// <returns>Sweep Surface.</returns>
 public static SweptSurface ByProfilePath(Curve profile, Curve path)
 {
     return new SweptSurface(profile, path, true);
 }
示例#55
0
        /// <summary>
        /// Constructors a plane at a point on the curve by given paramater and 
        /// use the tangent at the point as Normal of the plane
        /// </summary>
        /// <param name="contextCurve"></param>
        /// <param name="t"></param>
        /// <returns></returns>
        public static Plane AtParameter(Curve contextCurve, double t)
        {
            if (null == contextCurve)
                throw new ArgumentNullException("contextCurve");

            return contextCurve.PlaneAtParameter(t);
        }
示例#56
0
 internal override IGeometryEntity[] IntersectWithCurve(Curve curve)
 {
     return curve.CurveEntity.IntersectWith(PlaneEntity);
 }
示例#57
0
 /// <summary>
 /// Construct a Surface by revolving curve about a line axis. Assuming 
 /// sweep angle = 360 and start angle = 0.
 /// </summary>
 /// <param name="profile">Profile Curve for revolve surface.</param>
 /// <param name="axis">Line to define axis of revolution.</param>
 /// <returns>Surface of revolution.</returns>
 public static RevolvedSurface ByProfileAxis(Curve profile, Line axis)
 {
     return new RevolvedSurface(profile, axis, 0, 360, true);
 }
示例#58
0
 /// <summary>
 /// Constructs a patch surface from the give closed non-self intersecting 
 /// profile curve.
 /// </summary>
 /// <param name="profile">Profile curve for patch surface</param>
 /// <returns>Patch Surface</returns>
 public static PatchSurface FromCurve(Curve profile)
 {
     return new PatchSurface(profile, true);
 }
示例#59
0
        public void AddToMatchingCurve(Curve curve)
        {
            // Prepare a curve list to create a polycurve from
            List<Curve> curvesTojoin = new List<Curve>();
            curvesTojoin.Add(curve);

            // If the curve is connected to Curve 1
            if (Curve1.StartPoint.IsAlmostEqualTo(curve.EndPoint) || Curve1.EndPoint.IsAlmostEqualTo(curve.StartPoint))
            {
                // Add curve1 to the list and create a polycurve
                curvesTojoin.Add(Curve1);
                Curve newCurve = PolyCurve.ByJoinedCurves(curvesTojoin);
                this.Curve1 = newCurve;
            }
            // If the curve is connected to curve 2
            else if (Curve2 != null && (Curve2.StartPoint.IsAlmostEqualTo(curve.EndPoint) || Curve2.EndPoint.IsAlmostEqualTo(curve.StartPoint)))
            {
                // Add curve 2 to the list and create a polycurve from them
                curvesTojoin.Add(Curve2);
                Curve newCurve = PolyCurve.ByJoinedCurves(curvesTojoin);
                this.Curve2 = newCurve;
            }
            else
            {
                // If the curve doesnt connect and curve 2 hasnt been defined yet
                // take is as curve 2 otherwise add the unconnectable curve to the undefined list and throw an error
                if (this.Curve2 == null)
                    this.Curve2 = curve;
                else
                {
                    Undefined.Add(curve);
                    throw new ArgumentNullException("Cannot parametrize surface, try increasing the tolerance.");
                }
            }
        }
示例#60
0
文件: Floor.cs 项目: RobertiF/Dynamo
        /// <summary>
        /// Create a Revit Floor given it's curve outline and Level
        /// </summary>
        /// <param name="outlineCurves"></param>
        /// <param name="floorType"></param>
        /// <param name="level"></param>
        /// <returns>The floor</returns>
        public static Floor ByOutlineTypeAndLevel(Curve[] outlineCurves, FloorType floorType, Level level)
        {
            if (outlineCurves == null)
            {
                throw new ArgumentNullException("outlineCurves");
            }

            return ByOutlineTypeAndLevel(PolyCurve.ByJoinedCurves(outlineCurves), floorType, level);
        }