Package toxi.geom

Examples of toxi.geom.Quaternion


public class QuaternionTest extends TestCase {

    public void testCreateFromAxisAngle() {
        ReadonlyVec3D axis = new Vec3D(100, 100, 100);
        float angle = MathUtils.PI * 1.5f;
        Quaternion a = Quaternion.createFromAxisAngle(axis, angle);
        assertEquals(MathUtils.sin(-MathUtils.QUARTER_PI), a.w);
        float[] reverse = a.toAxisAngle();
        Vec3D revAxis = new Vec3D(reverse[1], reverse[2], reverse[3]);
        assertTrue(axis.getNormalized().equalsWithTolerance(revAxis, 0.01f));
        assertTrue(MathUtils.abs(angle - reverse[0]) < 0.01);
    }
View Full Code Here


        assertTrue(axis.getNormalized().equalsWithTolerance(revAxis, 0.01f));
        assertTrue(MathUtils.abs(angle - reverse[0]) < 0.01);
    }

    public void testEuler() {
        Quaternion q = Quaternion.createFromEuler(MathUtils.QUARTER_PI,
                MathUtils.QUARTER_PI, 0);
        System.out.println(q);
        float[] reverse = q.toAxisAngle();
        System.out.println("toAxisAngle():");
        for (float f : reverse) {
            System.out.println(f);
        }
    }
View Full Code Here

        }
    }

    public void testMatrixRoundtrip() {
        for (int i = 0; i < 1000; i++) {
            Quaternion q = Quaternion.createFromAxisAngle(Vec3D.randomVector(),
                    MathUtils.random(MathUtils.TWO_PI)).normalize();
            Matrix4x4 m = q.toMatrix4x4();
            Quaternion q2 = Quaternion.createFromMatrix(m);
            Vec3D p = Vec3D.randomVector();
            Vec3D p2 = p.copy();
            q.applyTo(p);
            q2.applyTo(p2);
            // floats are not very kind to round tripping
            // hence quite large epsilon
            assertTrue(p.equalsWithTolerance(p2, 0.0001f));
        }
    }
View Full Code Here

            assertTrue(p.equalsWithTolerance(p2, 0.0001f));
        }
    }

    public void testSlerp() {
        Quaternion a = new Quaternion(0, new Vec3D(0, 0, -1));
        Quaternion b = new Quaternion(0, new Vec3D(0, 0, 1));
        Quaternion c = a.interpolateTo(b, 0.05f);
        System.out.println(c);
    }
View Full Code Here

    private static void save() {
        try {
            JAXBGeomTest test = new JAXBGeomTest();
            test.box = new AABB();
            test.plane = new Plane();
            test.quat = new Quaternion(0, Vec3D.X_AXIS);
            test.ray = new Ray3D();
            test.rect = new Rect(0, 0, 100, 200);
            test.sphere = new Sphere();
            test.tri = new Triangle3D(new Vec3D(), new Vec3D(), new Vec3D());
            List<Vec2D> points2d = new ArrayList<Vec2D>();
View Full Code Here

TOP

Related Classes of toxi.geom.Quaternion

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.