Programming Language: C# (CSharp)

Namespace/Package Name: System

Class/Type: Vector3

Method/Function: normalize

Examples at hotexamples.com: 17

The System Vector3 Normalize method normalizes a given Vector3 object to have a unit length of 1. This means that the magnitude (or length) of the vector becomes 1, while its direction remains unchanged.

Code**example 1:**

In this example, we create a Vector3 object with the values x=2, y=3, z=4. We then apply the Normalize method to it, which returns a normalized vector with the values x=0.37139, y=0.55708, z=0.74278.

Code**example 2:**

Code

Vector3 vector = new Vector3(2, 3, 4); Vector3 normalized = Vector3.Normalize(vector); // normalized = (0.37139, 0.55708, 0.74278)

In this example, we create a Vector3 object with the values x=2, y=3, z=4. We then apply the Normalize method to it, which returns a normalized vector with the values x=0.37139, y=0.55708, z=0.74278.

Code

Vector3[] vectors = new Vector3[] { new Vector3(1, 0, 0), new Vector3(0, 1, 0), new Vector3(0, 0, 1) }; foreach (Vector3 v in vectors) { Vector3 normalized = Vector3.Normalize(v); // normalized = (1, 0, 0), (0, 1, 0), (0, 0, 1) }In this example, we create an array of three Vector3 objects representing the x, y, and z axes. We iterate over each of them and apply the Normalize method, which returns the same vector since they already have a length of 1. The System Vector3 Normalize method belongs to the C# Math library and is part of the System.Numerics namespace.

Frequently Used Methods

Frequently Used Methods

Frequently Used Methods

Related in langs

Frequently Used Methods

Related