1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 package net.sourceforge.kamiwaai.geometricalgebra;
43
44 class ComplexQuat {
45 private static final ComplexNumber[] czeros = {ComplexNumber.ZERO, ComplexNumber.ZERO,ComplexNumber.ZERO,ComplexNumber.ZERO};
46 private static final ComplexNumber[] oneSc = {new ComplexNumber(1.0, 0.0), ComplexNumber.ZERO, ComplexNumber.ZERO, ComplexNumber.ZERO};
47 public static final ComplexQuat ZERO = new ComplexQuat(czeros);
48 public static final ComplexQuat ONE = new ComplexQuat(oneSc);
49 private ComplexNumber[] CQuat = new ComplexNumber[4];
50
51 public ComplexQuat(ComplexNumber[] cq) {
52 CQuat[0] = cq[0];
53 CQuat[1] = cq[1];
54 CQuat[2] = cq[2];
55 CQuat[3] = cq[3];
56 }
57
58 public ComplexNumber getScPart() {
59 return CQuat[0];
60 }
61
62 public ComplexNumber[] getBvPart() {
63 ComplexNumber[] bvp = new ComplexNumber[3];
64 bvp[0] = CQuat[1];
65 bvp[1] = CQuat[2];
66 bvp[2] = CQuat[3];
67 return bvp;
68 }
69
70
71
72
73
74
75
76
77
78
79
80
81
82 public ComplexQuat add(ComplexQuat cq2) {
83 ComplexNumber[] CQsum = new ComplexNumber[4];
84
85 CQsum[0] = CQuat[0].add(cq2.getScPart());
86 CQsum[1] = CQuat[1].add(cq2.getBvPart()[0]);
87 CQsum[2] = CQuat[2].add(cq2.getBvPart()[1]);
88 CQsum[3] = CQuat[3].add(cq2.getBvPart()[2]);
89
90 return new ComplexQuat(CQsum);
91 }
92
93 public ComplexQuat sub(ComplexQuat cq2) {
94 ComplexNumber[] CQdif = new ComplexNumber[4];
95
96 CQdif[0] = CQuat[0].sub(cq2.getScPart());
97 CQdif[1] = CQuat[1].sub(cq2.getBvPart()[0]);
98 CQdif[2] = CQuat[2].sub(cq2.getBvPart()[1]);
99 CQdif[3] = CQuat[3].sub(cq2.getBvPart()[2]);
100
101 return new ComplexQuat(CQdif);
102 }
103
104 public ComplexQuat mult(ComplexQuat cq2) {
105 ComplexNumber p0, p1, p2, p3;
106 ComplexNumber q0, q1, q2, q3;
107 ComplexNumber[] CQprod = new ComplexNumber[4];
108
109 p0 = CQuat[0];
110 p1 = CQuat[1];
111 p2 = CQuat[2];
112 p3 = CQuat[3];
113
114 q0 = cq2.getScPart();
115 q1 = cq2.getBvPart()[0];
116 q2 = cq2.getBvPart()[1];
117 q3 = cq2.getBvPart()[2];
118
119 CQprod[0] =
120 (p0.mult(q0)).sub((p1.mult(q1)).add(p2.mult(q2)).add(p3.mult(q3)));
121 CQprod[1] =
122 ((p0.mult(q1)).add(p1.mult(q0)).sub(p2.mult(q3))).add(p3.mult(q2));
123 CQprod[2] =
124 ((p0.mult(q2)).add(p1.mult(q3)).add(p2.mult(q0)).sub(p3.mult(q1)));
125 CQprod[3] =
126 ((p0.mult(q3)).sub(p1.mult(q2))).add(p2.mult(q1)).add(p3.mult(q0));
127
128
129
130
131
132 return new ComplexQuat(CQprod);
133 }
134
135
136
137
138
139
140 public boolean equals(Object obj) {
141 if (obj == null)
142 throw new NullPointerException("obj is null");
143 if (!(obj instanceof ComplexQuat))
144 return false;
145 ComplexQuat complexquat = (ComplexQuat) obj;
146 return (
147 (complexquat.getScPart().equals(getScPart()))
148 && (complexquat.getBvPart()[0].equals(getBvPart()[0]))
149 && (complexquat.getBvPart()[1].equals(getBvPart()[1]))
150 && (complexquat.getBvPart()[2].equals(getBvPart()[2])));
151 }
152
153
154
155
156
157
158 public int hashCode() {
159
160 return super.hashCode();
161 }
162
163
164
165
166
167
168 public String toString() {
169 return "["
170 + CQuat[0]
171 + ", "
172 + CQuat[1]
173 + ", "
174 + CQuat[2]
175 + ","
176 + CQuat[3]
177 + "]";
178 }
179
180 }