public override float MapPointToPathDistance(Vector3 point) { if (_points.Count < 2) { return(0); } float d; float minDistance = float.MaxValue; float segmentLengthTotal = 0; float pathDistance = 0; for (int i = 1; i < _points.Count; i++) { float segmentProjection = 0; float segmentLength = _lengths[i]; Vector3 segmentNormal = _normals[i]; d = OpenSteerUtility.PointToSegmentDistance(point, _points[i - 1], _points[i], segmentNormal, segmentLength, ref segmentProjection); if (d < minDistance) { minDistance = d; pathDistance = segmentLengthTotal + segmentProjection; } segmentLengthTotal += segmentLength; } // return distance along path of onPath point return(pathDistance); }
/// <summary> /// Maps the reference point to a distance along the path. /// </summary> /// <param name="point">Reference point.</param> /// <returns>The distance along the path for the point.</returns> public virtual float MapPointToPathDistance(Vector3 point) { if (Path.Count < 2) { return(0); } var minDistance = float.MaxValue; float segmentLengthTotal = 0; float pathDistance = 0; for (var i = 1; i < Path.Count; i++) { var segmentProjection = 0f; var segmentLength = Lengths[i]; var segmentNormal = Normals[i]; var d = OpenSteerUtility.PointToSegmentDistance(point, Path[i - 1], Path[i], segmentNormal, segmentLength, ref segmentProjection); segmentLengthTotal += segmentLength; if (!(d < minDistance)) { continue; } minDistance = d; pathDistance = segmentLengthTotal + segmentProjection; } // return distance along path of onPath point return(pathDistance); }
public override Vector3 MapPointToPath(Vector3 point, ref PathRelativePosition pathRelative) { float d; float minDistance = float.MaxValue; Vector3 onPath = Vector3.zero; pathRelative.segmentIndex = -1; // loop over all segments, find the one nearest to the given point for (int i = 1; i < _points.Count; i++) { float segmentLength = _lengths[i]; Vector3 segmentNormal = _normals[i]; Vector3 chosenPoint = Vector3.zero; d = OpenSteerUtility.PointToSegmentDistance(point, _points[i - 1], _points[i], segmentNormal, segmentLength, ref chosenPoint); if (d < minDistance) { 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 virtual Vector3 MapPointToPath(Vector3 point, ref PathRelativePosition pathRelative) { var minDistance = float.MaxValue; var onPath = Vector3.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 = Vector3.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); }
public override Vector3 mapPointToPath(Vector3 point, ref mapReturnStruct tStruct) { float d; float minDistance = float.MaxValue; Vector3 onPath = Vector3.zero; // loop over all segments, find the one nearest to the given point for (int i = 1; i < points.Length; i++) { float segmentLength = lengths[i]; Vector3 segmentNormal = normals[i]; Vector3 chosenPoint = Vector3.zero; d = OpenSteerUtility.PointToSegmentDistance(point, points[i - 1], points[i], segmentNormal, segmentLength, ref chosenPoint); if (d < minDistance) { minDistance = d; onPath = chosenPoint; tStruct.tangent = segmentNormal; } } // measure how far original point is outside the Pathway's "tube" tStruct.outside = (onPath - point).magnitude - radius; // return point on path return(onPath); }
public static float PointToSegmentDistance(Vector3 point, Vector3 ep0, Vector3 ep1, ref Vector3 chosenPoint, ref float segmentProjection) { Vector3 vector = ep1 - ep0; float magnitude = vector.get_magnitude(); vector *= 1f / magnitude; return(OpenSteerUtility.PointToSegmentDistance(point, ep0, ep1, vector, magnitude, ref chosenPoint, ref segmentProjection)); }
public static float PointToSegmentDistance(Vector3 point, Vector3 ep0, Vector3 ep1, Vector3 segmentNormal, float segmentLength, ref Vector3 chosenPoint) { float num = 0f; return(OpenSteerUtility.PointToSegmentDistance(point, ep0, ep1, segmentNormal, segmentLength, ref chosenPoint, ref num)); }
public static float PointToSegmentDistance(Vector3 point, Vector3 ep0, Vector3 ep1, Vector3 segmentNormal, float segmentLength, ref float segmentProjection) { Vector3 zero = Vector3.get_zero(); return(OpenSteerUtility.PointToSegmentDistance(point, ep0, ep1, segmentNormal, segmentLength, ref zero, ref segmentProjection)); }