예제 #1
0
        /// <summary>
        /// Returns the center point of the specified <paramref name="line"/>.
        ///
        /// The center point is calculated by travelling half of the line's total length.
        /// </summary>
        /// <param name="line">The line.</param>
        /// <returns>An instance of <see cref="IPoint"/> representing the center point.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="line"/> is <c>null</c>.</exception>
        public static IPoint GetCenter(ILineString line)
        {
            if (line == null)
            {
                throw new ArgumentNullException(nameof(line));
            }

            double distance = GetLength(line.Points) / 2d;

            for (int i = 1; i < line.Points.Length; i++)
            {
                IPoint a = line.Points[i - 1];
                IPoint b = line.Points[i];

                double d = DistanceUtils.GetDistance(a, b);

                if (d > distance)
                {
                    // Caculate the heading between "a" and "b" (the center is on that line)
                    double heading = ComputeHeading(a, b);

                    // Calculate the offset/center based on the remaining distance
                    return(ComputeOffset(a, distance, heading));
                }

                distance -= d;
            }

            return(line.GetBoundingBox().GetCenter());
        }
예제 #2
0
        /// <summary>
        /// Returns the length of the line or line string represented by the specified <paramref name="points"/>.
        /// </summary>
        /// <param name="points">The points making up the line.</param>
        /// <returns>The length in metres.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="points"/> is <c>null</c>.</exception>
        public static double GetLength(IPoint[] points)
        {
            if (points == null)
            {
                throw new ArgumentNullException(nameof(points));
            }

            double sum = 0;

            // Iterate through each point in the path (skip the first point)
            for (int i = 1; i < points.Length; i++)
            {
                // Calculate the distance between the two points
                sum += DistanceUtils.GetDistance(points[i - 1], points[i]);
            }

            return(sum);
        }
예제 #3
0
        /// <summary>
        /// Returns the circumference of the closed path represented by the specified <paramref name="points"/>.
        /// </summary>
        /// <param name="points">The points making up the closed path.</param>
        /// <param name="radius">The radius of the spheroid.</param>
        /// <returns>The circumference in metres.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="points"/> is <c>null</c>.</exception>
        public static double GetCircumference(IPoint[] points, double radius)
        {
            if (points == null)
            {
                throw new ArgumentNullException(nameof(points));
            }

            double sum = 0;

            // Iterate through each point in the path
            for (int i = 0; i < points.Length; i++)
            {
                // While "i" is the index of the first point and "j" is the second point
                int j = i == 0 ? points.Length - 1 : i - 1;

                // Calculate the distance between the two points
                sum += DistanceUtils.GetDistance(points[i], points[j], radius);
            }

            return(sum);
        }