DistancePointLine() public static method

Calculate distance between a point and a line.

public static DistancePointLine ( Vector3 point, Vector3 lineStart, Vector3 lineEnd ) : float
point Vector3
lineStart Vector3
lineEnd Vector3
return float
Beispiel #1
0
		public static float DistanceToLine(Vector3 p1, Vector3 p2)
		{
			p1 = HandleUtility.WorldToGUIPoint(p1);
			p2 = HandleUtility.WorldToGUIPoint(p2);
			Vector2 mousePosition = Event.current.mousePosition;
			float num = HandleUtility.DistancePointLine(mousePosition, p1, p2);
			if (num < 0f)
			{
				num = 0f;
			}
			return num;
		}
        /// <summary>
        ///   <para>Pixel distance from mouse pointer to line.</para>
        /// </summary>
        /// <param name="p1"></param>
        /// <param name="p2"></param>
        public static float DistanceToLine(Vector3 p1, Vector3 p2)
        {
            p1 = (Vector3)HandleUtility.WorldToGUIPoint(p1);
            p2 = (Vector3)HandleUtility.WorldToGUIPoint(p2);
            float num = HandleUtility.DistancePointLine((Vector3)Event.current.mousePosition, p1, p2);

            if ((double)num < 0.0)
            {
                num = 0.0f;
            }
            return(num);
        }
        float DistancePointEdge(Vector3 point, Vector3[] edge)
        {
            float result = float.MaxValue;
            int   index  = edge.Length - 1;

            for (int nextIndex = 0; nextIndex < edge.Length; index = nextIndex, nextIndex++)
            {
                float dist = HandleUtility.DistancePointLine(point, edge[index], edge[nextIndex]);
                if (dist < result)
                {
                    result = dist;
                }
            }
            return(result);
        }