Пример #1
0
        /// <summary>
        /// Returns the normalized vector that is perpendicular to line AB. (Costly method!)
        /// </summary>
        /// <remarks>
        /// <para>
        /// The direction of the vector will be to the right when viewed from point A to point B
        /// along the line.
        /// </para>
        /// <para>
        /// Special Case: A zero length vector will be returned if the points are collocated.
        /// </para>
        /// </remarks>
        /// <param name="a">Point A on line AB.</param>
        /// <param name="b">Point B on line AB.</param>
        /// <returns>
        /// The normalized vector that is perpendicular to line AB, or a zero length vector if the
        /// points are collocated.
        /// </returns>
        public static Vector2 GetNormalAB(Vector2 a, Vector2 b)
        {
            if (Vector2Util.SloppyEquals(a, b, MathUtil.Tolerance))
            {
                // Points do not form a line.
                return(new Vector2());
            }

            Vector2 result = Vector2Util.GetDirectionAB(a, b);

            float origX = result.x;

            result.x = result.y;
            result.y = -origX;

            return(result);
        }