当前位置: 首页>>代码示例>>C#>>正文


C# Curve.Clone方法代码示例

本文整理汇总了C#中Curve.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# Curve.Clone方法的具体用法?C# Curve.Clone怎么用?C# Curve.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Curve的用法示例。


在下文中一共展示了Curve.Clone方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetPlaneFromCurve

        public static Plane GetPlaneFromCurve(Curve c, bool planarOnly)
        {
            //find the plane of the curve and generate a sketch plane
            double period = c.IsBound ? 0.0 : (c.IsCyclic ? c.Period : 1.0);

            var p0 = c.IsBound ? c.Evaluate(0.0, true) : c.Evaluate(0.0, false);
            var p1 = c.IsBound ? c.Evaluate(0.5, true) : c.Evaluate(0.25 * period, false);
            var p2 = c.IsBound ? c.Evaluate(1.0, true) : c.Evaluate(0.5 * period, false);

            if (IsLineLike(c))
            {
                XYZ norm = null;

                //keep old plane computations
                if (System.Math.Abs(p0.Z - p2.Z) < Tolerance)
                {
                    norm = XYZ.BasisZ;
                }
                else
                {
                    var v1 = p1 - p0;
                    var v2 = p2 - p0;

                    var p3 = new XYZ(p2.X, p2.Y, p0.Z);
                    var v3 = p3 - p0;
                    norm = v1.CrossProduct(v3);
                    if (norm.IsZeroLength())
                    {
                        norm = v2.CrossProduct(XYZ.BasisY);
                    }
                    norm = norm.Normalize();
                }

                return new Plane(norm, p0);

            }

            var cLoop = new CurveLoop();
            cLoop.Append(c.Clone());
            if (cLoop.HasPlane())
            {
                return cLoop.GetPlane();
            }
            if (planarOnly)
                return null;

            // Get best fit plane using tesselation
            var points = c.Tessellate().Select(x => x.ToPoint(false));

            var bestFitPlane =
                Autodesk.DesignScript.Geometry.Plane.ByBestFitThroughPoints(points);

            return bestFitPlane.ToPlane(false);
        }
开发者ID:RobertiF,项目名称:Dynamo,代码行数:54,代码来源:CurveUtils.cs

示例2: SafeCreateViaThicken

        private static CurveLoop SafeCreateViaThicken(Curve axisCurve, double width)
        {
            CurveLoop newLoop = null;
            try
            {
                if (axisCurve.IsReadOnly)
                    axisCurve = axisCurve.Clone();
                newLoop = CurveLoop.CreateViaThicken(axisCurve, width, XYZ.BasisZ);
            }
            catch
            {
            }

            if (newLoop == null)
                return null;

            if (!newLoop.IsCounterclockwise(XYZ.BasisZ))
                newLoop = GeometryUtil.ReverseOrientation(newLoop);

            return newLoop;
        }
开发者ID:whztt07,项目名称:RevitCustomIFCexporter,代码行数:21,代码来源:WallExporter.cs

示例3: MaybeStretchBaseCurve

        private static Curve MaybeStretchBaseCurve(Curve baseCurve, Curve trimmedCurve)
        {
            // Only works for bound curves.
            if (!baseCurve.IsBound || !trimmedCurve.IsBound)
                return null;

            // The original end parameters.
            double baseCurveParam0 = baseCurve.GetEndParameter(0);
            double baseCurveParam1 = baseCurve.GetEndParameter(1);

            // The trimmed curve may actually extend beyond the base curve at one end - make sure we extend the base curve.
            XYZ trimmedEndPt0 = trimmedCurve.GetEndPoint(0);
            XYZ trimmedEndPt1 = trimmedCurve.GetEndPoint(1);

            Curve axisCurve = baseCurve.Clone();
            if (axisCurve == null)
                return null;

            // We need to make the curve unbound before we find the trimmed end parameters, because Project finds the closest point
            // on the bounded curve, whereas we want to find the closest point on the unbounded curve.
            axisCurve.MakeUnbound();

            IntersectionResult result0 = axisCurve.Project(trimmedEndPt0);
            IntersectionResult result1 = axisCurve.Project(trimmedEndPt1);

            // One of the intersection points is not on the unbound curve - abort.
            if (!MathUtil.IsAlmostZero(result0.Distance) || !MathUtil.IsAlmostZero(result1.Distance))
                return null;

            double projectedEndParam0 = result0.Parameter;
            double projectedEndParam1 = result1.Parameter;

            double minParam = baseCurveParam0;
            double maxParam = baseCurveParam1;

            // Check that the orientation is correct.
            if (axisCurve.IsCyclic)
            {
                XYZ midTrimmedPtXYZ = (trimmedCurve.Evaluate(0.5, true));
                IntersectionResult result2 = axisCurve.Project(midTrimmedPtXYZ);
                if (!MathUtil.IsAlmostZero(result2.Distance))
                    return null;

                double projectedEndParamMid = (projectedEndParam0 + projectedEndParam1) / 2.0;
                bool parametersAreNotFlipped = MathUtil.IsAlmostEqual(projectedEndParamMid, result2.Parameter);
                bool trimmedCurveIsCCW = ((projectedEndParam0 < projectedEndParam1) == parametersAreNotFlipped);

                if (!trimmedCurveIsCCW)
                {
                    double tmp = projectedEndParam0; projectedEndParam0 = projectedEndParam1; projectedEndParam1 = tmp;
                }

                // While this looks inefficient, in practice we expect to do each while loop 0 or 1 times.
                double period = axisCurve.Period;
                while (projectedEndParam0 > baseCurveParam1) projectedEndParam0 -= period;
                while (projectedEndParam1 < baseCurveParam0) projectedEndParam1 += period;

                minParam = Math.Min(minParam, projectedEndParam0);
                maxParam = Math.Max(maxParam, projectedEndParam1);
            }
            else
            {
                minParam = Math.Min(minParam, Math.Min(projectedEndParam0, projectedEndParam1));
                maxParam = Math.Max(maxParam, Math.Max(projectedEndParam0, projectedEndParam1));
            }

            axisCurve.MakeBound(minParam, maxParam);
            return axisCurve;
        }
开发者ID:whztt07,项目名称:RevitCustomIFCexporter,代码行数:69,代码来源:WallExporter.cs

示例4: CreateCurveLoopFromUnboundedCyclicCurve

        // In certain cases, Revit can't handle unbounded circles and ellipses.  Create a CurveLoop with the curve split into two segments.
        private CurveLoop CreateCurveLoopFromUnboundedCyclicCurve(Curve innerCurve)
        {
            if (innerCurve == null)
                return null;

            if (!innerCurve.IsCyclic)
                return null;

            // We don't know how to handle anything other than circles or ellipses with a period of 2PI.
            double period = innerCurve.Period;
            if (!MathUtil.IsAlmostEqual(period, Math.PI * 2.0))
                return null;

            double startParam = innerCurve.IsBound ? innerCurve.GetEndParameter(0) : 0.0;
            double endParam = innerCurve.IsBound ? innerCurve.GetEndParameter(1) : period;

            // Not a closed curve.
            if (!MathUtil.IsAlmostEqual(endParam - startParam, period))
                return null;

            Curve firstCurve = innerCurve.Clone();
            if (firstCurve == null)
                return null;

            Curve secondCurve = innerCurve.Clone();
            if (secondCurve == null)
                return null;

            firstCurve.MakeBound(0, period / 2.0);
            secondCurve.MakeBound(period / 2.0, period);

            CurveLoop innerCurveLoop = new CurveLoop();
            innerCurveLoop.Append(firstCurve);
            innerCurveLoop.Append(secondCurve);
            return innerCurveLoop;
        }
开发者ID:whztt07,项目名称:RevitIFC,代码行数:37,代码来源:IFCProfileDef.cs

示例5: GetPlaneFromCurve

        public static Plane GetPlaneFromCurve(Curve c, bool planarOnly)
        {
            //cases to handle
            //straight line - normal will be inconclusive

            //find the plane of the curve and generate a sketch plane
            double period = c.IsBound ? 0.0 : (c.IsCyclic ? c.Period : 1.0);

            var p0 = c.IsBound ? c.Evaluate(0.0, true) : c.Evaluate(0.0, false);
            var p1 = c.IsBound ? c.Evaluate(0.5, true) : c.Evaluate(0.25 * period, false);
            var p2 = c.IsBound ? c.Evaluate(1.0, true) : c.Evaluate(0.5 * period, false);

            if (c is Line)
            {
                var v1 = p1 - p0;
                var v2 = p2 - p0;
                XYZ norm = null;

                //keep old plane computations
                if (Math.Abs(p0.Z - p2.Z) < 0.0001)
                {
                    norm = XYZ.BasisZ;
                }
                else
                {
                    var p3 = new XYZ(p2.X, p2.Y, p0.Z);
                    var v3 = p3 - p0;
                    norm = v1.CrossProduct(v3);
                    if (norm.IsZeroLength())
                    {
                        norm = v2.CrossProduct(XYZ.BasisY);
                    }
                    norm = norm.Normalize();
                }

                return new Plane(norm, p0);

            }

            Autodesk.Revit.DB.CurveLoop cLoop = new Autodesk.Revit.DB.CurveLoop();
            cLoop.Append(c.Clone());
            if (cLoop.HasPlane())
            {
                return cLoop.GetPlane();
            }
            if (planarOnly)
                return null;

            IList<XYZ> points = c.Tessellate();
            List<XYZ> xyzs = new List<XYZ>();
            for (int iPoint = 0; iPoint < points.Count; iPoint++)
                xyzs.Add(points[iPoint]);

            //var v1 = p1 - p0;
            //var v2 = p2 - p0;
            //var norm = v1.CrossProduct(v2).Normalize();

            ////Normal can be zero length in the case of a straight line
            ////or a curve whose three parameter points as measured above
            ////happen to lie along the same line. In this case, project
            ////the last point down to a plane and use the projected vector
            ////and one of the vectors from above to calculate a normal.
            //if (norm.IsZeroLength())
            //{
            //    if (p0.Z == p2.Z)
            //    {
            //        norm = XYZ.BasisZ;
            //    }
            //    else
            //    {
            //        var p3 = new XYZ(p2.X, p2.Y, p0.Z);
            //        var v3 = p3 - p0;
            //        norm = v1.CrossProduct(v3);
            //    }
            //}

            //var curvePlane = new Plane(norm, p0);

            XYZ meanPt;
            List<XYZ> orderedEigenvectors;
            BestFitLine.PrincipalComponentsAnalysis(xyzs, out meanPt, out orderedEigenvectors);
            var normal = orderedEigenvectors[0].CrossProduct(orderedEigenvectors[1]);
            var plane = dynRevitSettings.Doc.Application.Application.Create.NewPlane(normal, meanPt);
            return plane;
        }
开发者ID:kscalvin,项目名称:Dynamo,代码行数:85,代码来源:RevitUtils.cs

示例6: handleJoinsRight

        /// <summary>
        /// Get the Insulation Layer of Right hand joined Walls
        /// </summary>
        public Tuple<Curve, Curve> handleJoinsRight(Document doc, LocationCurve wallLocCurve, Curve lower, Curve upper, ref List<int> bannedWalls)
        {
            Tuple<Curve, Curve> existing = new Tuple<Curve, Curve>(upper, lower);

            if (lower.GetType() == typeof(Arc) || lower.GetType() == typeof(NurbSpline)) return existing;
            if (upper.GetType() == typeof(Arc) || upper.GetType() == typeof(NurbSpline)) return existing;

            XYZ IntersectionPointLower = null;
            XYZ IntersectionPointUpper = null;

            ElementArray elems = wallLocCurve.get_ElementsAtJoin(1);

            if (elems == null || elems.Size == 0) return existing;

            foreach (Element elem in elems)
            {
                if (elem.GetType() == typeof(Wall))
                {
                    Wall wnext = (Wall)elem;

                    if (!bannedWalls.Contains(wnext.Id.IntegerValue))
                    {

                        Tuple<Curve, Curve> curves = getInsulationLayer(doc, wnext);
                        Curve lowerunbound = lower.Clone();
                        lowerunbound.MakeUnbound();
                        Curve upperunbound = upper.Clone();
                        upperunbound.MakeUnbound();
                        Curve lowernext = curves.Item2.Clone();
                        lowernext.MakeUnbound();

                        IntersectionResultArray result = new IntersectionResultArray();

                        lowerunbound.Intersect(lowernext, out result);
                        if (result != null && result.Size == 1)
                        {
                            IntersectionPointLower = result.get_Item(0).XYZPoint;
                        }

                        upperunbound.Intersect(lowernext, out result);
                        if (result != null && result.Size == 1)
                        {
                            IntersectionPointUpper = result.get_Item(0).XYZPoint;
                        }

                    }

                }
            }

            if (IntersectionPointLower == null || IntersectionPointUpper == null) return existing;

            return new Tuple<Curve, Curve>(Line.CreateBound(upper.GetEndPoint(0), IntersectionPointUpper), Line.CreateBound(lower.GetEndPoint(0), IntersectionPointLower));
        }
开发者ID:moethu,项目名称:Insulator,代码行数:57,代码来源:Insulator.cs

示例7: handleJoinsLeft

        /// <summary>
        /// Get the Insulation Layer of Left hand joined Walls
        /// </summary>
        public Curve handleJoinsLeft(Document doc, LocationCurve wallLocCurve, Curve lower, ref List<int> bannedWalls)
        {
            if (lower.GetType() == typeof(Arc) || lower.GetType() == typeof(NurbSpline)) return lower;

            XYZ IntersectionPoint = null;
            ElementArray elems = wallLocCurve.get_ElementsAtJoin(0);

            if (elems == null || elems.Size == 0) return lower;

            foreach (Element elem in elems)
            {
                if (elem.GetType() == typeof(Wall))
                {
                    Wall wnext = (Wall)elem;

                    if (!bannedWalls.Contains(wnext.Id.IntegerValue))
                    {

                        Tuple<Curve, Curve> curves = getInsulationLayer(doc, wnext);
                        Curve lowerunbound = lower.Clone();
                        lowerunbound.MakeUnbound();
                        Curve upper = curves.Item1.Clone();
                        upper.MakeUnbound();

                        IntersectionResultArray result = new IntersectionResultArray();

                        lowerunbound.Intersect(upper, out result);
                        if (result != null && result.Size == 1)
                        {
                            IntersectionPoint = result.get_Item(0).XYZPoint;
                        }

                    }

                }
            }

            if (IntersectionPoint == null) return lower;

            Line l = Line.CreateBound(IntersectionPoint, lower.GetEndPoint(1));

            return l;
        }
开发者ID:moethu,项目名称:Insulator,代码行数:46,代码来源:Insulator.cs

示例8: drawInsulation

        /// <summary>
        /// DrawInsulation
        /// </summary>
        public double drawInsulation(List<ElementId> grp, Document doc, Curve lower, double distance, Curve upper, ref bool leftwing, List<Interruption> Breaks, bool zigzag)
        {
            double dist = distance / lower.Length;
            if (dist > 1) return 100;

            XYZ P1 = lower.Evaluate(dist, true);
            IntersectionResultArray result = new IntersectionResultArray();
            XYZ normal = lower.GetCurveTangentToEndPoint(P1);

            SetComparisonResult scr = Line.CreateUnbound(P1, normal).Intersect(upper, out result);
            if (result == null || result.Size == 0)
            {
                if (dist > 0.5) return 100;
                else
                {
                    upper = upper.Clone();
                    upper.MakeUnbound();
                    scr = Line.CreateUnbound(P1, normal).Intersect(upper, out result);
                }

            }

            XYZ P3 = result.get_Item(0).XYZPoint;
            double height = P1.DistanceTo(P3);
            double r = height / 4;
            double distr = (distance + r) / lower.Length;
            if (distr > 1) return 100;

            foreach (Interruption interrupt in Breaks)
            {
                if (distr > lower.ComputeNormalizedParameter(interrupt.from) && distr < lower.ComputeNormalizedParameter(interrupt.to)) return r;
            }

            XYZ P2 = (distr < 1) ? lower.Evaluate(distr, true) : P1;

            double disth = (distance + height) / lower.Length;

            SetComparisonResult scr2 = Line.CreateUnbound(P2, lower.GetCurveTangentToEndPoint(P2)).Intersect(upper, out result);
            if (result == null || result.Size == 0) return 100;
            XYZ P4 = (P1 != P2) ? result.get_Item(0).XYZPoint : upper.GetEndPoint(1);

            if (zigzag)
                drawZigZag(grp, doc, P1, P2, P3, P4, leftwing);
            else
                drawSoftLoop(grp, doc, P1, P2, P3, P4, leftwing);

            if (leftwing) leftwing = false; else leftwing = true;

            return r;
        }
开发者ID:moethu,项目名称:Insulator,代码行数:53,代码来源:Insulator.cs


注:本文中的Curve.Clone方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。