Here you can find the source of normalize(long[] v, float[] target)
Parameter | Description |
---|---|
v | the Long array to normalize (Long) |
public static void normalize(long[] v, float[] target)
//package com.java2s; public class Main { /**// w w w. ja v a 2 s . co m * Returns a normalized vector * * @param v the Long array to normalize (Float) * @return a normalized vector */ public static float[] normalize(float[] v) { float len = length(v); v[0] /= len; v[1] /= len; return v; } /** * Returns a normalized vector * * @param v the Long array to normalize (Long) * @return a normalized vector * * @deprecated for performance use normalize(long[], float[] instead) */ public static float[] normalize(long[] v) { float[] target = new float[2]; normalize(v, target); return target; } /** * Returns a normalized vector (in R^2) * * @param v the Long array to normalize (Long) * @return a normalized vector */ public static void normalize(long[] v, float[] target) { // FIXME: is double precision really needed here? Faster if // len is a float instead of a double double len = length(v); target[0] = (float) (v[0] / len); target[1] = (float) (v[1] / len); } /** * Returns a normalized vector * * @param v the array to normalize (Integer) * @return a normalized vector */ public static float[] normalize(int[] v) { float len = length(v); return new float[] { v[0] / len, v[1] / len }; } /** * Returns the length of a vector * * @param v the vector (Long) * @return the length of the vector (Double) */ public static double length(long[] v) { return Math.sqrt(v[0] * v[0] + v[1] * v[1]); } /** * Returns the length of a vector * * @param v the vector (Float) * @return the length of the vector (Float) */ public static float length(float[] v) { return (float) Math.sqrt(v[0] * v[0] + v[1] * v[1]); } /** * Returns the length of a vector * * @param v the vector (Integer) * @return the length of the vector (Float) */ public static float length(int[] v) { return (float) Math.sqrt(v[0] * v[0] + v[1] * v[1]); } }