Sharpex2D.Math.Vector2.Normalize C# (CSharp) Method

Normalize() public static method

Normalizes the specified vector.
public static Normalize ( Vector2 a ) : Vector2
a Vector2 The vector.
return Vector2
        public static Vector2 Normalize(Vector2 a)
        {
            if (a.LengthSquared == 0)
                return Zero;

            float divider = 1.0f/a.Length;
            return new Vector2(
                a.X*divider,
                a.Y*divider);
        }

Same methods

Vector2::Normalize ( ) : void

Usage Example

コード例 #1
0
ファイル: Polygon.cs プロジェクト: ThuCommix/Sharpex2D
        /// <summary>
        ///     A value indicating whether the Polygon has a seperating axis.
        /// </summary>
        /// <param name="other">The other Polygon.</param>
        /// <param name="minOverlap">The MinimumOverlap.</param>
        /// <param name="axis">The Axis.</param>
        /// <returns>True of seperating axis.</returns>
        private bool HasSeparatingAxisTo(Polygon other, ref float minOverlap, ref Vector2 axis)
        {
            int prev = Points.Length - 1;
            for (int i = 0; i < Points.Length; i++)
            {
                Vector2 edge = Points[i] - Points[prev];

                var v = new Vector2(edge.X, edge.Y);
                v = v.CrossProduct();
                v.Normalize();

                float aMin, aMax, bMin, bMax;
                ProjectTo(v, out aMin, out aMax);
                other.ProjectTo(v, out bMin, out bMax);

                if ((aMax < bMin) || (bMax < aMin))
                    return true;

                float overlapping = aMax < bMax ? aMax - bMin : bMax - aMin;
                if (overlapping < minOverlap)
                {
                    minOverlap = overlapping;
                    axis = v;
                }

                prev = i;
            }

            return false;
        }