Axiom.Math.Vector2.Normalize C# (CSharp) Метод

Normalize() публичный Метод

Normalizes the vector.
This method normalises the vector such that it's length / magnitude is 1. The result is called a unit vector.

This function will not crash for zero-sized vectors, but there will be no changes made to their components.

public Normalize ( ) : Real
Результат Real
		public Real Normalize()
		{
			Real length = Utility.Sqrt( this.x * this.x + this.y * this.y );

			// Will also work for zero-sized vectors, but will change nothing
			if ( length > Real.Epsilon )
			{
				Real inverseLength = 1.0f / length;

				this.x *= inverseLength;
				this.y *= inverseLength;
			}

			return length;
		}