Пример #1
0
void test_rotate()
{
    QVector<Vector> axis(MultiVector::count()), vec(MultiVector::count());
    QVector<double> angle(MultiVector::count());
    QVector<Vector> result(MultiVector::count());

    for (int i=0; i<MultiVector::count(); ++i)
    {
        axis[i] = rangen.vectorOnSphere(1);
        vec[i] = rangen.vectorOnSphere(5);
        angle[i] = rangen.rand(-2.0*SireMaths::pi, 2.0*SireMaths::pi);
        result[i] = Quaternion(Angle(angle[i]),axis[i]).rotate(vec[i]);
    }

    MultiVector maxis(axis);
    MultiVector mvec(vec);
    MultiDouble mangle(angle);

    MultiVector mresult = MultiQuaternion(mangle, maxis).rotate(mvec);

    for (int i=0; i<MultiVector::count(); ++i)
    {
        for (int j=0; j<3; ++j)
        {
            assert_nearly_equal( mresult.at(i)[j], result[i][j], 1e-5 );
        }
    }
}
Пример #2
0
void test_cross()
{
    QVector<Vector> v0(MultiVector::count()), v1(MultiVector::count());
    QVector<Vector> cross(MultiVector::count());

    for (int i=0; i<MultiVector::count(); ++i)
    {
        v0[i] = rangen.vectorOnSphere(5);
        v1[i] = rangen.vectorOnSphere(5);
        cross[i] = Vector::cross(v0[i], v1[i]);
    }

    MultiVector mv0(v0);
    MultiVector mv1(v1);
    MultiVector mcross = MultiVector::cross(mv0, mv1);

    for (int i=0; i<MultiVector::count(); ++i)
    {
        assert_equal( mcross.at(i), cross.at(i) );
    }
}