@Test public void testNormalize() throws Exception { final double x1 = 3d; final double y1 = 4d; final double z1 = 5d; final double length = Math.sqrt(50); Vec3 u = new Vec3(x1, y1, z1); Vec3 v = u.normalize(); double magnitude = u.magnitude(); assertEquals("u.x", (1 / length) * x1, u.x, 0d); assertEquals("u.y", (1 / length) * y1, u.y, 0d); assertEquals("u.z", (1 / length) * z1, u.z, 0d); assertEquals("unit length", 1.0, magnitude, TOLERANCE); assertSame("v == u", u, v); }
public Vec3 normalize() { double magnitude = this.magnitude(); if (magnitude != 0) { this.x /= magnitude; this.y /= magnitude; this.z /= magnitude; } return this; }
Vec3 { public Vec3 normalize() { double magnitude = this.magnitude(); if (magnitude != 0) { this.x /= magnitude; this.y /= magnitude; this.z /= magnitude; } return this; } }
Vec3 { public Vec3 normalize() { double magnitude = this.magnitude(); if (magnitude != 0) { this.x /= magnitude; this.y /= magnitude; this.z /= magnitude; } return this; } Vec3();  Vec3(double x, double y, double z);  Vec3(Vec3 vector); }
Vec3 { public Vec3 normalize() { double magnitude = this.magnitude(); if (magnitude != 0) { this.x /= magnitude; this.y /= magnitude; this.z /= magnitude; } return this; } Vec3();  Vec3(double x, double y, double z);  Vec3(Vec3 vector); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); float[] toArray(float[] result, int offset); double magnitude(); double magnitudeSquared(); double distanceTo(Vec3 vector); double distanceToSquared(Vec3 vector); Vec3 set(double x, double y, double z); Vec3 set(Vec3 vector); Vec3 swap(Vec3 vector); Vec3 add(Vec3 vector); Vec3 subtract(Vec3 vector); Vec3 multiply(double scalar); Vec3 multiplyByMatrix(Matrix4 matrix); Vec3 divide(double divisor); Vec3 negate(); Vec3 normalize(); double dot(Vec3 vector); Vec3 cross(Vec3 vector); Vec3 cross(Vec3 a, Vec3 b); Vec3 mix(Vec3 vector, double weight); }
Vec3 { public Vec3 normalize() { double magnitude = this.magnitude(); if (magnitude != 0) { this.x /= magnitude; this.y /= magnitude; this.z /= magnitude; } return this; } Vec3();  Vec3(double x, double y, double z);  Vec3(Vec3 vector); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); float[] toArray(float[] result, int offset); double magnitude(); double magnitudeSquared(); double distanceTo(Vec3 vector); double distanceToSquared(Vec3 vector); Vec3 set(double x, double y, double z); Vec3 set(Vec3 vector); Vec3 swap(Vec3 vector); Vec3 add(Vec3 vector); Vec3 subtract(Vec3 vector); Vec3 multiply(double scalar); Vec3 multiplyByMatrix(Matrix4 matrix); Vec3 divide(double divisor); Vec3 negate(); Vec3 normalize(); double dot(Vec3 vector); Vec3 cross(Vec3 vector); Vec3 cross(Vec3 a, Vec3 b); Vec3 mix(Vec3 vector, double weight); public double x; public double y; public double z; }