/** Compute the linear magnitude of the point. * @return the magnitude. */ @Override public double magnitude() { double mag = this.magnitude;//volatile-read once if (mag == Double.NEGATIVE_INFINITY) { this.magnitude = mag = super.magnitude(); } return mag; }
/** * Compute the magnitude of this vector. * * @return the magnitude. */ public double magnitude() { return magnitude(x,y,z); }
/** * Compute a normalized unit vector based on the current vector. * * @return the normalized vector, or null if the current vector has * a magnitude of zero. */ public Vector normalize() { double denom = magnitude(); if (denom < MINIMUM_RESOLUTION) // Degenerate, can't normalize return null; double normFactor = 1.0 / denom; return new Vector(x * normFactor, y * normFactor, z * normFactor); }
final double thisZ = A.x * B.y - A.y * B.x; final double magnitude = magnitude(thisX, thisY, thisZ); if (magnitude == 0.0) { return true; normalizeZ = normalizeZ - currentDotProd * currentVectorZ; final double correctedMagnitude = magnitude(normalizeX, normalizeY, normalizeZ); final double inverseCorrectedMagnitude = 1.0 / correctedMagnitude; normalizeX = normalizeX * inverseCorrectedMagnitude;
final double thisZ = AX * BY - AY * BX; final double magnitude = magnitude(thisX, thisY, thisZ); if (magnitude == 0.0) { throw new IllegalArgumentException("Degenerate/parallel vector constructed"); normalizeZ = normalizeZ - currentDotProd * currentVectorZ; final double correctedMagnitude = magnitude(normalizeX, normalizeY, normalizeZ); final double inverseCorrectedMagnitude = 1.0 / correctedMagnitude; normalizeX = normalizeX * inverseCorrectedMagnitude;
/** Compute an arc distance between two points. * Note: this is an angular distance, and not a surface distance, and is therefore independent of planet model. * For surface distance, see {@link PlanetModel#surfaceDistance(GeoPoint, GeoPoint)} * @param v is the second point. * @return the angle, in radians, between the two points. */ public double arcDistance(final Vector v) { return Tools.safeAcos(dotProduct(v)/(magnitude() * v.magnitude())); }
/** Compute an arc distance between two points. * @param x is the x part of the second point. * @param y is the y part of the second point. * @param z is the z part of the second point. * @return the angle, in radians, between the two points. */ public double arcDistance(final double x, final double y, final double z) { return Tools.safeAcos(dotProduct(x,y,z)/(magnitude() * Vector.magnitude(x,y,z))); }