Example usage for org.apache.commons.math3.complex Quaternion dotProduct

List of usage examples for org.apache.commons.math3.complex Quaternion dotProduct

Introduction

In this page you can find the example usage for org.apache.commons.math3.complex Quaternion dotProduct.

Prototype

public double dotProduct(final Quaternion q) 

Source Link

Document

Computes the dot-product of the instance by a quaternion.

Usage

From source file:sceneGraph.Rot.java

public Quaternion slerp(double amount, Quaternion value1, Quaternion value2) {
    if (amount < 0.0)
        return value1;
    else if (amount > 1.0)
        return value2;

    double dot = value1.dotProduct(value2);
    double x2, y2, z2, w2;
    if (dot < 0.0) {
        dot = 0.0 - dot;//from ww w . j  a  v a2  s  .  c  o  m
        x2 = 0.0 - value2.getQ1();
        y2 = 0.0 - value2.getQ2();
        z2 = 0.0 - value2.getQ3();
        w2 = 0.0 - value2.getQ0();
    } else {
        x2 = value2.getQ1();
        y2 = value2.getQ2();
        z2 = value2.getQ3();
        w2 = value2.getQ0();
    }

    double t1, t2;

    final double EPSILON = 0.0001;
    if ((1.0 - dot) > EPSILON) // standard case (slerp)
    {
        double angle = Math.acos(dot);
        double sinAngle = Math.sin(angle);
        t1 = Math.sin((1.0 - amount) * angle) / sinAngle;
        t2 = Math.sin(amount * angle) / sinAngle;
    } else // just lerp
    {
        t1 = 1.0 - amount;
        t2 = amount;
    }

    return new Quaternion((value1.getQ1() * t1) + (x2 * t2), (value1.getQ2() * t1) + (y2 * t2),
            (value1.getQ3() * t1) + (z2 * t2), (value1.getQ0() * t1) + (w2 * t2));
}