示例#1
0
        /// <summary>
        /// Calculates how far Outside the path is the reference point.
        /// </summary>
        /// <param name="point">Reference point.</param>
        /// <returns>How far Outside the path is the reference point.</returns>
        public float HowFarOutsidePath(Vector2 point)
        {
            var tStruct = new PathRelativePosition();

            MapPointToPath(point, ref tStruct);
            return(tStruct.Outside);
        }
示例#2
0
        /// <summary>
        /// Given an arbitrary point ("A"), returns the nearest point ("P") on
        /// this path.  Also returns, via output arguments, the path Tangent at
        /// P and a measure of how far A is Outside the Pathway's "tube".  Note
        /// that a negative distance indicates A is inside the Pathway.
        /// </summary>
        /// <param name="point">Reference point.</param>
        /// <param name="pathRelative">Structure indicating the relative path position.</param>
        /// <returns>The closest point to the received reference point.</returns>
        public virtual Vector2 MapPointToPath(Vector2 point, ref PathRelativePosition pathRelative)
        {
            var minDistance = float.MaxValue;
            var onPath      = Vector2.zero;

            pathRelative.SegmentIndex = -1;
            // loop over all segments, find the one nearest to the given point
            for (var i = 1; i < Path.Count; i++)
            {
                var segmentLength = Lengths[i];
                var segmentNormal = Normals[i];
                var chosenPoint   = Vector2.zero;
                var d             = OpenSteerUtility.PointToSegmentDistance(point, Path[i - 1], Path[i],
                                                                            segmentNormal, segmentLength,
                                                                            ref chosenPoint);
                if (!(d < minDistance))
                {
                    continue;
                }
                minDistance               = d;
                onPath                    = chosenPoint;
                pathRelative.Tangent      = segmentNormal;
                pathRelative.SegmentIndex = i;
            }

            // measure how far original point is Outside the Pathway's "tube"
            pathRelative.Outside = (onPath - point).magnitude - Radius;

            // return point on path
            return(onPath);
        }
示例#3
0
        /// <summary>
        /// Determines whether the received point is inside the path.
        /// </summary>
        /// <param name="point">Point to evaluate.</param>
        /// <returns><c>true</c> if the point is inside the path; otherwise, <c>false</c>.</returns>
        public bool IsInsidePath(Vector2 point)
        {
            var tStruct = new PathRelativePosition();

            MapPointToPath(point, ref tStruct);
            return(tStruct.Outside < 0);
        }
示例#4
0
        /// <summary>
        /// Given an arbitrary point ("A"), returns the nearest point ("P") on
        /// this path.  Also returns, via output arguments, the path Tangent at
        /// P and a measure of how far A is Outside the Pathway's "tube".  Note
        /// that a negative distance indicates A is inside the Pathway.
        /// </summary>
        /// <param name="point">Reference point.</param>
        /// <param name="pathRelative">Structure indicating the relative path position.</param>
        /// <returns>The closest point to the received reference point.</returns>
        public override Vector2 MapPointToPath(Vector2 point, ref PathRelativePosition pathRelative)
        {
            // Approximate the closest path point on a linear path
            var onPath = base.MapPointToPath(point, ref pathRelative);

            var distance    = MapPointToPathDistance(onPath) / TotalPathLength;
            var splinePoint = CalculateCatmullRomPoint(1, distance);

            // return point on path
            return(splinePoint);
        }
        /// <summary>
        /// Calculates how far Outside the path is the reference point.
        /// </summary>
        /// <param name="point">Reference point.</param>
        /// <returns>How far Outside the path is the reference point.</returns>
        public float HowFarOutsidePath(Vector2 point)
        {
            var tStruct = new PathRelativePosition();

            MapPointToPath(point, ref tStruct);
            return tStruct.Outside;
        }
        /// <summary>
        /// Determines whether the received point is inside the path.
        /// </summary>
        /// <param name="point">Point to evaluate.</param>
        /// <returns><c>true</c> if the point is inside the path; otherwise, <c>false</c>.</returns>
        public bool IsInsidePath(Vector2 point)
        {
            var tStruct = new PathRelativePosition();

            MapPointToPath(point, ref tStruct);
            return tStruct.Outside < 0;
        }
        /// <summary>
        /// Given an arbitrary point ("A"), returns the nearest point ("P") on
        /// this path.  Also returns, via output arguments, the path Tangent at
        /// P and a measure of how far A is Outside the Pathway's "tube".  Note
        /// that a negative distance indicates A is inside the Pathway.
        /// </summary>
        /// <param name="point">Reference point.</param>
        /// <param name="pathRelative">Structure indicating the relative path position.</param>
        /// <returns>The closest point to the received reference point.</returns>
        public virtual Vector2 MapPointToPath(Vector2 point, ref PathRelativePosition pathRelative)
        {
            var minDistance = float.MaxValue;
            var onPath = Vector2.zero;

            pathRelative.SegmentIndex = -1;
            // loop over all segments, find the one nearest to the given point
            for (var i = 1; i < Path.Count; i++)
            {
                var segmentLength = Lengths[i];
                var segmentNormal = Normals[i];
                var chosenPoint = Vector2.zero;
                var d = OpenSteerUtility.PointToSegmentDistance(point, Path[i - 1], Path[i],
                    segmentNormal, segmentLength,
                    ref chosenPoint);
                if (!(d < minDistance)) continue;
                minDistance = d;
                onPath = chosenPoint;
                pathRelative.Tangent = segmentNormal;
                pathRelative.SegmentIndex = i;
            }

            // measure how far original point is Outside the Pathway's "tube"
            pathRelative.Outside = (onPath - point).magnitude - Radius;

            // return point on path
            return onPath;
        }
        /// <summary>
        /// Given an arbitrary point ("A"), returns the nearest point ("P") on
        /// this path.  Also returns, via output arguments, the path Tangent at
        /// P and a measure of how far A is Outside the Pathway's "tube".  Note
        /// that a negative distance indicates A is inside the Pathway.
        /// </summary>
        /// <param name="point">Reference point.</param>
        /// <param name="pathRelative">Structure indicating the relative path position.</param>
        /// <returns>The closest point to the received reference point.</returns>
        public override Vector2 MapPointToPath(Vector2 point, ref PathRelativePosition pathRelative)
        {
            // Approximate the closest path point on a linear path
            var onPath = base.MapPointToPath(point, ref pathRelative);

            var distance = MapPointToPathDistance(onPath) / TotalPathLength;
            var splinePoint = CalculateCatmullRomPoint(1, distance);

            // return point on path
            return splinePoint;
        }