本文整理汇总了Java中org.apache.commons.math3.exception.util.LocalizedFormats.ZERO_NORM属性的典型用法代码示例。如果您正苦于以下问题:Java LocalizedFormats.ZERO_NORM属性的具体用法?Java LocalizedFormats.ZERO_NORM怎么用?Java LocalizedFormats.ZERO_NORM使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.commons.math3.exception.util.LocalizedFormats
的用法示例。
在下文中一共展示了LocalizedFormats.ZERO_NORM属性的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: angle
/** Compute the angular separation between two vectors.
* <p>This method computes the angular separation between two
* vectors using the dot product for well separated vectors and the
* cross product for almost aligned vectors. This allows to have a
* good accuracy in all cases, even for vectors very close to each
* other.</p>
* @param v1 first vector
* @param v2 second vector
* @param <T> the type of the field elements
* @return angular separation between v1 and v2
* @exception MathArithmeticException if either vector has a null norm
*/
public static <T extends RealFieldElement<T>> T angle(final FieldVector3D<T> v1, final FieldVector3D<T> v2)
throws MathArithmeticException {
final T normProduct = v1.getNorm().multiply(v2.getNorm());
if (normProduct.getReal() == 0) {
throw new MathArithmeticException(LocalizedFormats.ZERO_NORM);
}
final T dot = dotProduct(v1, v2);
final double threshold = normProduct.getReal() * 0.9999;
if ((dot.getReal() < -threshold) || (dot.getReal() > threshold)) {
// the vectors are almost aligned, compute using the sine
FieldVector3D<T> v3 = crossProduct(v1, v2);
if (dot.getReal() >= 0) {
return v3.getNorm().divide(normProduct).asin();
}
return v3.getNorm().divide(normProduct).asin().subtract(FastMath.PI).negate();
}
// the vectors are sufficiently separated to use the cosine
return dot.divide(normProduct).acos();
}
示例2: angle
/** Compute the angular separation between two vectors.
* <p>This method computes the angular separation between two
* vectors using the dot product for well separated vectors and the
* cross product for almost aligned vectors. This allows to have a
* good accuracy in all cases, even for vectors very close to each
* other.</p>
* @param v1 first vector
* @param v2 second vector
* @return angular separation between v1 and v2
* @exception MathArithmeticException if either vector has a null norm
*/
public static double angle(Vector3D v1, Vector3D v2) throws MathArithmeticException {
double normProduct = v1.getNorm() * v2.getNorm();
if (normProduct == 0) {
throw new MathArithmeticException(LocalizedFormats.ZERO_NORM);
}
double dot = v1.dotProduct(v2);
double threshold = normProduct * 0.9999;
if ((dot < -threshold) || (dot > threshold)) {
// the vectors are almost aligned, compute using the sine
Vector3D v3 = crossProduct(v1, v2);
if (dot >= 0) {
return FastMath.asin(v3.getNorm() / normProduct);
}
return FastMath.PI - FastMath.asin(v3.getNorm() / normProduct);
}
// the vectors are sufficiently separated to use the cosine
return FastMath.acos(dot / normProduct);
}
示例3: angle
/** Compute the angular separation between two vectors.
* <p>This method computes the angular separation between two
* vectors using the dot product for well separated vectors and the
* cross product for almost aligned vectors. This allows to have a
* good accuracy in all cases, even for vectors very close to each
* other.</p>
* @param v1 first vector
* @param v2 second vector
* @return angular separation between v1 and v2
* @exception MathArithmeticException if either vector has a null norm
*/
public static double angle(Vector2D v1, Vector2D v2) throws MathArithmeticException {
double normProduct = v1.getNorm() * v2.getNorm();
if (normProduct == 0) {
throw new MathArithmeticException(LocalizedFormats.ZERO_NORM);
}
double dot = v1.dotProduct(v2);
double threshold = normProduct * 0.9999;
if ((dot < -threshold) || (dot > threshold)) {
// the vectors are almost aligned, compute using the sine
final double n = FastMath.abs(MathArrays.linearCombination(v1.x, v2.y, -v1.y, v2.x));
if (dot >= 0) {
return FastMath.asin(n / normProduct);
}
return FastMath.PI - FastMath.asin(n / normProduct);
}
// the vectors are sufficiently separated to use the cosine
return FastMath.acos(dot / normProduct);
}
示例4: reset
/** Reset the instance as if built from two points.
* @param p1 first point belonging to the line (this can be any point)
* @param p2 second point belonging to the line (this can be any point, different from p1)
* @exception MathIllegalArgumentException if the points are equal
*/
public void reset(final Vector3D p1, final Vector3D p2) throws MathIllegalArgumentException {
final Vector3D delta = p2.subtract(p1);
final double norm2 = delta.getNormSq();
if (norm2 == 0.0) {
throw new MathIllegalArgumentException(LocalizedFormats.ZERO_NORM);
}
this.direction = new Vector3D(1.0 / FastMath.sqrt(norm2), delta);
zero = new Vector3D(1.0, p1, -p1.dotProduct(delta) / norm2, delta);
}
示例5: setNormal
/** Set the normal vactor.
* @param normal normal direction to the plane (will be copied)
* @exception MathArithmeticException if the normal norm is too small
*/
private void setNormal(final Vector3D normal) throws MathArithmeticException {
final double norm = normal.getNorm();
if (norm < 1.0e-10) {
throw new MathArithmeticException(LocalizedFormats.ZERO_NORM);
}
w = new Vector3D(1.0 / norm, normal);
}
示例6: cosine
/**
* Computes the cosine of the angle between this vector and the
* argument.
*
* @param v Vector.
* @return the cosine of the angle between this vector and {@code v}.
* @throws MathArithmeticException if {@code this} or {@code v} is the null
* vector
* @throws DimensionMismatchException if the dimensions of {@code this} and
* {@code v} do not match
*/
public double cosine(RealVector v) throws DimensionMismatchException,
MathArithmeticException {
final double norm = getNorm();
final double vNorm = v.getNorm();
if (norm == 0 ||
vNorm == 0) {
throw new MathArithmeticException(LocalizedFormats.ZERO_NORM);
}
return dotProduct(v) / (norm * vNorm);
}
示例7: unitVector
/**
* Creates a unit vector pointing in the direction of this vector.
* The instance is not changed by this method.
*
* @return a unit vector pointing in direction of this vector.
* @throws MathArithmeticException if the norm is zero.
*/
public RealVector unitVector() throws MathArithmeticException {
final double norm = getNorm();
if (norm == 0) {
throw new MathArithmeticException(LocalizedFormats.ZERO_NORM);
}
return mapDivide(norm);
}
示例8: unitize
/**
* Converts this vector into a unit vector.
* The instance itself is changed by this method.
*
* @throws MathArithmeticException if the norm is zero.
*/
public void unitize() throws MathArithmeticException {
final double norm = getNorm();
if (norm == 0) {
throw new MathArithmeticException(LocalizedFormats.ZERO_NORM);
}
mapDivideToSelf(getNorm());
}
示例9: unitize
/** {@inheritDoc} */
@Override
public void unitize() throws MathArithmeticException {
double norm = getNorm();
if (isDefaultValue(norm)) {
throw new MathArithmeticException(LocalizedFormats.ZERO_NORM);
}
Iterator iter = entries.iterator();
while (iter.hasNext()) {
iter.advance();
entries.put(iter.key(), iter.value() / norm);
}
}
示例10: unitVector
/** {@inheritDoc} */
@Override
public RealVector unitVector() {
final double norm = getNorm();
if (norm == 0) {
throw new MathArithmeticException(LocalizedFormats.ZERO_NORM);
}
return mapDivide(norm);
}
示例11: unitize
/** {@inheritDoc} */
@Override
public void unitize() {
final double norm = getNorm();
if (norm == 0) {
throw new MathArithmeticException(LocalizedFormats.ZERO_NORM);
}
mapDivideToSelf(norm);
}
示例12: cosine
/**
* Computes the cosine of the angle between this vector and the
* argument.
*
* @param v Vector.
* @return the cosine of the angle between this vector and {@code v}.
*/
public double cosine(RealVector v) {
final double norm = getNorm();
final double vNorm = v.getNorm();
if (norm == 0 ||
vNorm == 0) {
throw new MathArithmeticException(LocalizedFormats.ZERO_NORM);
}
return dotProduct(v) / (norm * vNorm);
}
示例13: unitize
/** {@inheritDoc} */
@Override
public void unitize() {
double norm = getNorm();
if (isDefaultValue(norm)) {
throw new MathArithmeticException(LocalizedFormats.ZERO_NORM);
}
Iterator iter = entries.iterator();
while (iter.hasNext()) {
iter.advance();
entries.put(iter.key(), iter.value() / norm);
}
}
示例14: projection
/**
* Find the orthogonal projection of this vector onto another vector.
*
* @param v vector onto which instance must be projected.
* @return projection of the instance onto {@code v}.
* @throws DimensionMismatchException if {@code v} is not the same size as
* {@code this} vector.
* @throws MathArithmeticException if {@code this} or {@code v} is the null
* vector
*/
public RealVector projection(final RealVector v)
throws DimensionMismatchException, MathArithmeticException {
final double norm2 = v.dotProduct(v);
if (norm2 == 0.0) {
throw new MathArithmeticException(LocalizedFormats.ZERO_NORM);
}
return v.mapMultiply(dotProduct(v) / v.dotProduct(v));
}