コード例 #1
0
        public bool Intersects(LineF2D line)
        {
            PointF2D[]        corners           = this.Corners;
            LinePointPosition linePointPosition = line.PositionOfPoint(corners[0]);

            for (int index = 1; index <= corners.Length; ++index)
            {
                if (line.PositionOfPoint(corners[index]) != linePointPosition)
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #2
0
        public bool Intersects(PointF2D point1, PointF2D point2)
        {
            PointF2D[]        corners           = this.Corners;
            LineF2D           lineF2D           = new LineF2D(point1, point2, true);
            LinePointPosition linePointPosition = lineF2D.PositionOfPoint(corners[0]);

            for (int index = 1; index < corners.Length; ++index)
            {
                if (lineF2D.PositionOfPoint(corners[index]) != linePointPosition)
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #3
0
ファイル: BoxF2D.cs プロジェクト: teleavtomatika/core
        /// <summary>
        /// Returns true if the line intersects with this bounding box.
        /// </summary>
        /// <param name="line"></param>
        /// <returns></returns>
        public bool Intersects(LineF2D line)
        {
            // if all points have the same relative position with respect to the line
            // there is no intersection. In the other case there is.

            PointF2D[]        corners        = this.Corners;
            LinePointPosition first_position = line.PositionOfPoint(corners[0]);

            for (int idx = 1; idx <= corners.Length; idx++)
            {
                if (line.PositionOfPoint(corners[idx]) != first_position)
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #4
0
        /// <summary>
        /// Projects on to a given shape and returns data about projection point.
        /// </summary>
        public static bool ProjectOn(this IEnumerable <Coordinate> shape, float latitude, float longitude,
                                     out float projectedLatitude, out float projectedLongitude, out float projectedDistanceFromFirst,
                                     out int projectedShapeIndex, out float distanceToProjected, out float totalLength, out LinePointPosition position)
        {
            distanceToProjected        = float.MaxValue;
            projectedDistanceFromFirst = 0;
            projectedLatitude          = float.MaxValue;
            projectedLongitude         = float.MaxValue;
            projectedShapeIndex        = -1;
            position = LinePointPosition.On;

            var        previousShapeDistance = 0.0f;
            var        previousShapeIndex    = -1;
            var        shapeEnumerator       = shape.GetEnumerator();
            Coordinate?previous = null;

            while (true)
            {
                // make sure there is a previous.
                if (previous == null)
                {
                    if (!shapeEnumerator.MoveNext())
                    {
                        break;
                    }
                    previous = shapeEnumerator.Current;
                }

                // get next point.
                Coordinate?current = null;
                if (!shapeEnumerator.MoveNext())
                {
                    break;
                }
                current = shapeEnumerator.Current;

                var line           = new Line(previous.Value, current.Value);
                var coordinate     = new Coordinate(latitude, longitude);
                var projectedPoint = line.ProjectOn(coordinate);
                if (projectedPoint != null)
                { // ok, projection succeeded.
                    var distance = Coordinate.DistanceEstimateInMeter(
                        projectedPoint.Value.Latitude, projectedPoint.Value.Longitude,
                        latitude, longitude);
                    if (distance < distanceToProjected)
                    { // ok, new best edge yay!
                        distanceToProjected        = distance;
                        projectedLatitude          = projectedPoint.Value.Latitude;
                        projectedLongitude         = projectedPoint.Value.Longitude;
                        projectedDistanceFromFirst = (previousShapeDistance +
                                                      Coordinate.DistanceEstimateInMeter(
                                                          projectedLatitude, projectedLongitude,
                                                          previous.Value.Latitude, previous.Value.Longitude));
                        projectedShapeIndex = previousShapeIndex + 1;
                        position            = line.PositionOfPoint(projectedPoint.Value);
                    }
                }

                // add up the current shape distance.
                previousShapeDistance += Coordinate.DistanceEstimateInMeter(
                    previous.Value.Latitude, previous.Value.Longitude,
                    current.Value.Latitude, current.Value.Longitude);
                previousShapeIndex++;

                previous = current.Value;
            }
            totalLength = previousShapeDistance;

            return(distanceToProjected != float.MaxValue);
        }