public VectorNd add(VectorNd v) { return add(v.vec); }
public double distance(VectorNd v) { return distance(v.vec); }
/** * Attempts to normalize a vector. If this fails, the method catches the exception and return a zero vector of the same dimension instead. * * @param v The vector to attempt to normalize * @return The normalized vector, or the zero vector if it couldn't be normalized. */ public static VectorNd normalizeSafe(VectorNd v) { try { return v.normalize(); } catch (ArithmeticException ex) { return new VectorNd(v.size()); } } }
public VectorNd transform(double... vec) { final int size = size(); if (size != vec.length) { throw new IllegalArgumentException("Matrix and vector sizes must be the same"); } final VectorNd d = new VectorNd(size); for (int row = 0; row < size; row++) { double dot = 0; for (int col = 0; col < size; col++) { dot += mat[row][col] * vec[col]; } d.set(row, dot); } return d; }
@Override public VectorNd normalize() { final double length = length(); if (Math.abs(length) < GenericMath.DBL_EPSILON) { throw new ArithmeticException("Cannot normalize the zero vector"); } final int size = size(); final VectorNd d = new VectorNd(size); for (int comp = 0; comp < size; comp++) { d.vec[comp] = (double) (vec[comp] / length); } return d; }
public VectorNd project(double... v) { final int size = size(); if (size != v.length) { throw new IllegalArgumentException("Vector sizes must be the same"); } double lengthSquared = 0; for (int comp = 0; comp < size; comp++) { lengthSquared += v[comp] * v[comp]; } if (Math.abs(lengthSquared) < GenericMath.DBL_EPSILON) { throw new ArithmeticException("Cannot project onto the zero vector"); } final double a = dot(v) / lengthSquared; final VectorNd d = new VectorNd(size); for (int comp = 0; comp < size; comp++) { d.vec[comp] = a * v[comp]; } return d; }
@Override public VectorNd clone() { return new VectorNd(this); }
@Override public int compareTo(VectorNd v) { return (int) Math.signum(lengthSquared() - v.lengthSquared()); }
public double distanceSquared(VectorNd v) { return distanceSquared(v.vec); }
public VectorNd div(float a) { return div((double) a); }
public double dot(VectorNd v) { return dot(v.vec); }
public VectorNd max(VectorNd v) { return max(v.vec); }
public VectorNd transform(double... vec) { final int size = size(); if (size != vec.length) { throw new IllegalArgumentException("Matrix and vector sizes must be the same"); } final VectorNd d = new VectorNd(size); for (int row = 0; row < size; row++) { double dot = 0; for (int col = 0; col < size; col++) { dot += mat[row][col] * vec[col]; } d.set(row, dot); } return d; }
@Override public VectorNd normalize() { final double length = length(); if (Math.abs(length) < GenericMath.DBL_EPSILON) { throw new ArithmeticException("Cannot normalize the zero vector"); } final int size = size(); final VectorNd d = new VectorNd(size); for (int comp = 0; comp < size; comp++) { d.vec[comp] = (double) (vec[comp] / length); } return d; }
/** * Attempts to normalize a vector. If this fails, the method catches the exception and return a zero vector of the same dimension instead. * * @param v The vector to attempt to normalize * @return The normalized vector, or the zero vector if it couldn't be normalized. */ public static VectorNd normalizeSafe(VectorNd v) { try { return v.normalize(); } catch (ArithmeticException ex) { return new VectorNd(v.size()); } } }
public VectorNd project(double... v) { final int size = size(); if (size != v.length) { throw new IllegalArgumentException("Vector sizes must be the same"); } double lengthSquared = 0; for (int comp = 0; comp < size; comp++) { lengthSquared += v[comp] * v[comp]; } if (Math.abs(lengthSquared) < GenericMath.DBL_EPSILON) { throw new ArithmeticException("Cannot project onto the zero vector"); } final double a = dot(v) / lengthSquared; final VectorNd d = new VectorNd(size); for (int comp = 0; comp < size; comp++) { d.vec[comp] = a * v[comp]; } return d; }