1 package net.sf.openrocket.util;
3 public class QuaternionMultiply {
5 private static class Value {
9 public Value multiply(Value other) {
10 Value result = new Value();
11 result.sign = this.sign * other.sign;
12 if (this.value.compareTo(other.value) < 0)
13 result.value = this.value + "*" + other.value;
15 result.value = other.value + "*" + this.value;
19 public String toString() {
38 private static Value[] multiply(Value[] first, Value[] second) {
43 public static void main(String[] arg) {
44 if (arg.length % 4 != 0 || arg.length < 4) {
45 System.out.println("Must have modulo 4 args, at least 4");
49 Value[][] values = new Value[arg.length/4][4];
51 for (int i=0; i<arg.length; i++) {
52 Value value = new Value();
54 if (arg[i].equals("")) {
57 if (arg[i].startsWith("-")) {
59 value.value = arg[i].substring(1);
60 } else if (arg[i].startsWith("+")) {
62 value.value = arg[i].substring(1);
69 values[i/4][i%4] = value;
72 System.out.println("Multiplying:");
73 for (int i=0; i < values.length; i++) {
76 System.out.println("Result:");
78 Value[] result = values[0];
79 for (int i=1; i < values.length; i++) {
80 result = multiply(result, values[i]);
85 private static void print(Value[] q) {
86 System.out.println(" " + q[0] + " " + q[1] + " i " + q[2] + " j " + q[3] + " k");