Java Code Examples for org.apache.commons.math.util.MathUtils#linearCombination()

The following examples show how to use org.apache.commons.math.util.MathUtils#linearCombination() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Vector3D.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Compute the cross-product of the instance with another vector.
 * @param v other vector
 * @return the cross product this ^ v as a new Vector3D
 */
public Vector3D crossProduct(final Vector<Euclidean3D> v) {
    final Vector3D v3 = (Vector3D) v;
    return new Vector3D(MathUtils.linearCombination(y, v3.z, -z, v3.y),
                        MathUtils.linearCombination(z, v3.x, -x, v3.z),
                        MathUtils.linearCombination(x, v3.y, -y, v3.x));
}
 
Example 2
Source File: Vector3D.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Compute the cross-product of the instance with another vector.
 * @param v other vector
 * @return the cross product this ^ v as a new Vector3D
 */
public Vector3D crossProduct(final Vector<Euclidean3D> v) {
    final Vector3D v3 = (Vector3D) v;
    return new Vector3D(MathUtils.linearCombination(y, v3.z, -z, v3.y),
                        MathUtils.linearCombination(z, v3.x, -x, v3.z),
                        MathUtils.linearCombination(x, v3.y, -y, v3.x));
}
 
Example 3
Source File: Vector3D.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/** Linear constructor
 * Build a vector from three other ones and corresponding scale factors.
 * The vector built will be a1 * u1 + a2 * u2 + a3 * u3
 * @param a1 first scale factor
 * @param u1 first base (unscaled) vector
 * @param a2 second scale factor
 * @param u2 second base (unscaled) vector
 * @param a3 third scale factor
 * @param u3 third base (unscaled) vector
 */
public Vector3D(double a1, Vector3D u1, double a2, Vector3D u2,
                double a3, Vector3D u3) {
    this.x = MathUtils.linearCombination(a1, u1.x, a2, u2.x, a3, u3.x);
    this.y = MathUtils.linearCombination(a1, u1.y, a2, u2.y, a3, u3.y);
    this.z = MathUtils.linearCombination(a1, u1.z, a2, u2.z, a3, u3.z);
}
 
Example 4
Source File: Vector3D.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/** Linear constructor
 * Build a vector from four other ones and corresponding scale factors.
 * The vector built will be a1 * u1 + a2 * u2 + a3 * u3 + a4 * u4
 * @param a1 first scale factor
 * @param u1 first base (unscaled) vector
 * @param a2 second scale factor
 * @param u2 second base (unscaled) vector
 * @param a3 third scale factor
 * @param u3 third base (unscaled) vector
 * @param a4 fourth scale factor
 * @param u4 fourth base (unscaled) vector
 */
public Vector3D(double a1, Vector3D u1, double a2, Vector3D u2,
                double a3, Vector3D u3, double a4, Vector3D u4) {
    this.x = MathUtils.linearCombination(a1, u1.x, a2, u2.x, a3, u3.x, a4, u4.x);
    this.y = MathUtils.linearCombination(a1, u1.y, a2, u2.y, a3, u3.y, a4, u4.y);
    this.z = MathUtils.linearCombination(a1, u1.z, a2, u2.z, a3, u3.z, a4, u4.z);
}
 
Example 5
Source File: Vector3D.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/** Linear constructor
 * Build a vector from three other ones and corresponding scale factors.
 * The vector built will be a1 * u1 + a2 * u2 + a3 * u3
 * @param a1 first scale factor
 * @param u1 first base (unscaled) vector
 * @param a2 second scale factor
 * @param u2 second base (unscaled) vector
 * @param a3 third scale factor
 * @param u3 third base (unscaled) vector
 */
public Vector3D(double a1, Vector3D u1, double a2, Vector3D u2,
                double a3, Vector3D u3) {
    this.x = MathUtils.linearCombination(a1, u1.x, a2, u2.x, a3, u3.x);
    this.y = MathUtils.linearCombination(a1, u1.y, a2, u2.y, a3, u3.y);
    this.z = MathUtils.linearCombination(a1, u1.z, a2, u2.z, a3, u3.z);
}
 
Example 6
Source File: Vector3D.java    From astor with GNU General Public License v2.0 3 votes vote down vote up
/** Linear constructor
 * Build a vector from four other ones and corresponding scale factors.
 * The vector built will be a1 * u1 + a2 * u2 + a3 * u3 + a4 * u4
 * @param a1 first scale factor
 * @param u1 first base (unscaled) vector
 * @param a2 second scale factor
 * @param u2 second base (unscaled) vector
 * @param a3 third scale factor
 * @param u3 third base (unscaled) vector
 * @param a4 fourth scale factor
 * @param u4 fourth base (unscaled) vector
 */
public Vector3D(double a1, Vector3D u1, double a2, Vector3D u2,
                double a3, Vector3D u3, double a4, Vector3D u4) {
    this.x = MathUtils.linearCombination(a1, u1.x, a2, u2.x, a3, u3.x, a4, u4.x);
    this.y = MathUtils.linearCombination(a1, u1.y, a2, u2.y, a3, u3.y, a4, u4.y);
    this.z = MathUtils.linearCombination(a1, u1.z, a2, u2.z, a3, u3.z, a4, u4.z);
}
 
Example 7
Source File: Vector3D.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/** Linear constructor
 * Build a vector from two other ones and corresponding scale factors.
 * The vector built will be a1 * u1 + a2 * u2
 * @param a1 first scale factor
 * @param u1 first base (unscaled) vector
 * @param a2 second scale factor
 * @param u2 second base (unscaled) vector
 */
public Vector3D(double a1, Vector3D u1, double a2, Vector3D u2) {
    this.x = MathUtils.linearCombination(a1, u1.x, a2, u2.x);
    this.y = MathUtils.linearCombination(a1, u1.y, a2, u2.y);
    this.z = MathUtils.linearCombination(a1, u1.z, a2, u2.z);
}
 
Example 8
Source File: Vector3D.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/** {@inheritDoc}
 * <p>
 * The implementation uses specific multiplication and addition
 * algorithms to preserve accuracy and reduce cancellation effects.
 * It should be very accurate even for nearly orthogonal vectors.
 * </p>
 * @see MathUtils#linearCombination(double, double, double, double, double, double)
 */
public double dotProduct(final Vector<Euclidean3D> v) {
    final Vector3D v3 = (Vector3D) v;
    return MathUtils.linearCombination(x, v3.x, y, v3.y, z, v3.z);
}
 
Example 9
Source File: Vector3D.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/** Linear constructor
 * Build a vector from two other ones and corresponding scale factors.
 * The vector built will be a1 * u1 + a2 * u2
 * @param a1 first scale factor
 * @param u1 first base (unscaled) vector
 * @param a2 second scale factor
 * @param u2 second base (unscaled) vector
 */
public Vector3D(double a1, Vector3D u1, double a2, Vector3D u2) {
    this.x = MathUtils.linearCombination(a1, u1.x, a2, u2.x);
    this.y = MathUtils.linearCombination(a1, u1.y, a2, u2.y);
    this.z = MathUtils.linearCombination(a1, u1.z, a2, u2.z);
}
 
Example 10
Source File: Vector3D.java    From astor with GNU General Public License v2.0 2 votes vote down vote up
/** {@inheritDoc}
 * <p>
 * The implementation uses specific multiplication and addition
 * algorithms to preserve accuracy and reduce cancellation effects.
 * It should be very accurate even for nearly orthogonal vectors.
 * </p>
 * @see MathUtils#linearCombination(double, double, double, double, double, double)
 */
public double dotProduct(final Vector<Euclidean3D> v) {
    final Vector3D v3 = (Vector3D) v;
    return MathUtils.linearCombination(x, v3.x, y, v3.y, z, v3.z);
}