normalize method

Quaternion normalize()

Normalize the quaternion. Note that this changes the values of the quaternion.

Implementation

Quaternion normalize(){
  double l = math.sqrt(x * x + y *y + z *z + w * w);
  if (l == 0) {
    x = 0;
    y = 0;
    z = 0;
    w = 0;
  } else {
    l = 1 / l;
    x *= l;
    y *= l;
    z *= l;
    w *= l;
  }
  return this;
}