Example #1
0
        /// <summary>
        ///     TODO
        /// </summary>
        /// <param name="nat"></param>
        /// <param name="axis"></param>
        /// <returns></returns>
        private Vector3d GetTangent(Curve3d nat, Axis axis)
        {
            var vec = new Vector3d();

            try
            {
                if (nat is LinearEntity3d || nat.IsClosed())
                {
                    vec = axis.ToVector();
                }
                else if (nat.StartPoint == axis.Start || nat.EndPoint == axis.Start)
                {
                    using (var curved = nat.GetClosestPointTo(axis.Start))
                    {
                        vec = curved.GetDerivative(1).GetNormal() * axis.Length;
                    }

                    using (var curved2 = nat.GetClosestPointTo(axis.Start + vec))
                    {
                        if (curved2.Point.IsEqualTo(axis.Start))
                        {
                            vec = vec.Negate();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                MailAgent.Report(e.Message);
            }

            return(vec);
        }
        public static IEnumerable <DistanceBetween2PolylinesSectionResult> CalculateDistanceBetween3dPolylines(Database database, ObjectId pl1Id, ObjectId pl2Id)
        {
            Curve3d curve1, curve2 = null;
            int     polyline1EndParam;

            Point3d[] parameterListPoints = null;
            double[]  parameterListLength = null;
            using (Transaction transAction = database.TransactionManager.StartTransaction())
            {
                object objectX1 = transAction.GetObject(pl1Id, OpenMode.ForRead);
                object objectX2 = transAction.GetObject(pl2Id, OpenMode.ForRead);

                //Get a list of 3D points in parameter order
                using (Polyline3d pl1 = (Polyline3d)objectX1)
                    using (Polyline3d pl2 = (Polyline3d)objectX2)
                    {
                        // We get curve here, its faster to get the parameters and
                        // point on a non database object
                        curve1              = pl1.GetGeCurve(new Tolerance(1e-10, 1e-10));
                        curve2              = pl2.GetGeCurve(new Tolerance(1e-10, 1e-10));
                        polyline1EndParam   = (int)pl1.EndParam;
                        parameterListPoints = new Point3d[polyline1EndParam + 1];
                        parameterListLength = new double[polyline1EndParam + 1];
                        for (int y = 0; y <= polyline1EndParam; y++)
                        {
                            parameterListPoints[y] = pl1.GetPointAtParameter(y);
                            parameterListLength[y] = pl1.GetDistanceAtParameter(y);
                        }
                    }

                // Initialize list with dimensions specified (speed)
                DistanceBetween2PolylinesSectionResult[] arrRes = new DistanceBetween2PolylinesSectionResult[polyline1EndParam + 1];

                //for (int i = 0; i <= polyline1EndParam; i++)
                Parallel.For(0, polyline1EndParam + 1, (i) =>
                {
                    Point3d pointOnCurve1, pointOnCurve2;
                    lock (_curveLock)
                    {
                        pointOnCurve1 = parameterListPoints[i];
                        pointOnCurve2 = curve2.GetClosestPointTo(pointOnCurve1).Point;
                    }

                    // Add result to array
                    lock (_arrayLock)
                        arrRes[i] = new DistanceBetween2PolylinesSectionResult(
                            parameterListLength[i],
                            pointOnCurve1.Z - pointOnCurve2.Z,
                            pointOnCurve1.T2d().GetDistanceTo(pointOnCurve2.T2d()),
                            pointOnCurve1.DistanceTo(pointOnCurve2),
                            pointOnCurve1, pointOnCurve2);
                });
                transAction.Commit();
                return(arrRes);
            }
        }