create changelog entry
[debian/openrocket] / core / src / net / sf / openrocket / util / QuaternionMultiply.java
1 package net.sf.openrocket.util;
2
3 public class QuaternionMultiply {
4
5         private static class Value {
6                 public int sign = 1;
7                 public String value;
8                 
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;
14                         else
15                                 result.value = other.value + "*" + this.value;
16                         return result;
17                 }
18                 @Override
19                 public String toString() {
20                         String s;
21                         
22                         if (sign < 0)
23                                 s = "-";
24                         else
25                                 s = "+";
26                         
27                         if (sign == 0)
28                                 s += " 0";
29                         else
30                                 s += " " + value;
31                         
32                         return s;
33                 }
34         }
35         
36         
37         
38         private static Value[] multiply(Value[] first, Value[] second) {
39                 return null;
40         }
41         
42         
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");
46                         return;
47                 }
48                 
49                 Value[][] values = new Value[arg.length/4][4];
50                 
51                 for (int i=0; i<arg.length; i++) {
52                         Value value = new Value();
53                         
54                         if (arg[i].equals("")) {
55                                 value.sign = 0;
56                         } else {
57                                 if (arg[i].startsWith("-")) {
58                                         value.sign = -1;
59                                         value.value = arg[i].substring(1);
60                                 } else if (arg[i].startsWith("+")) {
61                                         value.sign = 1;
62                                         value.value = arg[i].substring(1);
63                                 } else {
64                                         value.sign = 1;
65                                         value.value = arg[i];
66                                 }
67                         }
68                         
69                         values[i/4][i%4] = value;
70                 }
71
72                 System.out.println("Multiplying:");
73                 for (int i=0; i < values.length; i++) {
74                         print(values[i]);
75                 }
76                 System.out.println("Result:");
77                 
78                 Value[] result = values[0];
79                 for (int i=1; i < values.length; i++) {
80                         result = multiply(result, values[i]);
81                 }
82                 print(result);
83         }
84         
85         private static void print(Value[] q) {
86                 System.out.println("   " + q[0] + " " + q[1] + " i " + q[2] + " j " + q[3] + " k");
87         }
88         
89 }
90