Extract Quaternion.main to junit test.
This commit is contained in:
parent
f08ad83e5f
commit
310e35293a
@ -318,39 +318,4 @@ public class Quaternion {
|
||||
return String.format("Quaternion[%f,%f,%f,%f,norm=%f]", w, x, y, z, this.norm());
|
||||
}
|
||||
|
||||
public static void main(String[] arg) {
|
||||
|
||||
Quaternion q = new Quaternion(Math.random() - 0.5, Math.random() - 0.5,
|
||||
Math.random() - 0.5, Math.random() - 0.5);
|
||||
q.normalize();
|
||||
|
||||
q = new Quaternion(-0.998717, 0.000000, 0.050649, -0.000000);
|
||||
|
||||
Coordinate coord = new Coordinate(10 * (Math.random() - 0.5),
|
||||
10 * (Math.random() - 0.5), 10 * (Math.random() - 0.5));
|
||||
|
||||
System.out.println("Quaternion: " + q);
|
||||
System.out.println("Coordinate: " + coord);
|
||||
coord = q.invRotate(coord);
|
||||
System.out.println("Rotated: " + coord);
|
||||
coord = q.rotate(coord);
|
||||
System.out.println("Back: " + coord);
|
||||
|
||||
|
||||
q = new Quaternion(0.237188, 0.570190, -0.514542, 0.594872);
|
||||
q.normalize();
|
||||
Coordinate c = new Coordinate(148578428.914, 8126778.954, -607.741);
|
||||
|
||||
System.out.println("Rotated: " + q.rotate(c));
|
||||
|
||||
// Coordinate c = new Coordinate(0,1,0);
|
||||
// Coordinate rot = new Coordinate(Math.PI/4,0,0);
|
||||
//
|
||||
// System.out.println("Before: "+c);
|
||||
// c = rotation(rot).invRotate(c);
|
||||
// System.out.println("After: "+c);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
48
core/test/net/sf/openrocket/util/QuaternionTest.java
Normal file
48
core/test/net/sf/openrocket/util/QuaternionTest.java
Normal file
@ -0,0 +1,48 @@
|
||||
package net.sf.openrocket.util;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
|
||||
public class QuaternionTest {
|
||||
|
||||
@Test
|
||||
public void oldMainTest() {
|
||||
|
||||
// This is normalized already
|
||||
Quaternion q = new Quaternion(0.237188, 0.570190, -0.514542, 0.594872);
|
||||
assertEquals( 1.0, q.norm(), 0.01);
|
||||
|
||||
q.normalize();
|
||||
assertEquals( 0.237188, q.getW(), 0.00001);
|
||||
assertEquals( 0.570190, q.getX(), 0.00001);
|
||||
assertEquals( -0.514542, q.getY(), 0.00001);
|
||||
assertEquals( 0.594872, q.getZ(), 0.00001);
|
||||
assertEquals( 1.0, q.norm(), 0.01);
|
||||
|
||||
Coordinate c = new Coordinate(148578428.914, 8126778.954, -607.741);
|
||||
|
||||
Coordinate r = q.rotate(c);
|
||||
|
||||
System.out.println("Rotated: " + q.rotate(c));
|
||||
|
||||
assertEquals( -42312599.537, r.x, 0.001);
|
||||
assertEquals( -48162747.551, r.y, 0.001);
|
||||
assertEquals( 134281904.197, r.z, 0.001);
|
||||
|
||||
c = new Coordinate(0,1,0);
|
||||
Coordinate rot = new Coordinate(Math.PI/4,0,0);
|
||||
|
||||
System.out.println("Before: "+c);
|
||||
c = Quaternion.rotation(rot).invRotate(c);
|
||||
System.out.println("After: "+c);
|
||||
|
||||
assertEquals( 0.0, c.x, 0.001);
|
||||
assertEquals( 0.707, c.y, 0.001);
|
||||
assertEquals( -0.707, c.z, 0.001);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user