View Javadoc

1   // GeometricAlgebra Java package file
2   // Current version
3   // Go to ... http://sinai.mech.fukui-u.ac.jp/gcj/software/KamiWaAi/index.html
4   // Copyright (C) 2003, Eckhard M.S. Hitzer
5   //
6   // This library is free software; you can redistribute it and/or
7   // modify it under the terms of the GNU Lesser General Public
8   // License as published by the Free Software Foundation; either
9   // version 2.1 of the License, or any later version.
10  //
11  // This library is distributed in the hope that it will be useful,
12  // but WITHOUT ANY WARRANTY; without even the implied warranty of
13  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  // Lesser General Public License for more details.
15  //
16  // You should have received a copy of the GNU Lesser General Public
17  // License along with this library; if not, write to the Free Software
18  // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  // Go to ... http://www.gnu.org/copyleft/lesser.html
20  // 
21  // hitzer@mech.fukui-u.ac.jp
22  // 
23  // Department of Mechanical Engineering, Fukui University
24  // 3-9-1 Bunkyo, 910-8507 Fukui, Japan
25  // 
26  //
27  //
28  // It the personal wish of E.M.S. Hitzer,
29  // that you never use this software for infringing human dignity:
30  //
31  // "God created man in his own image,
32  // in the image of God he created him;
33  // male and female he created them.
34  // [The Bible, Genesis chapter 1 verse 27]
35  //
36  //
37  //
38  // 
39  // File ComplexQuat.java
40  // 2003-5-1
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  	// should be immutable
70  	//    void setScPart(ComplexNumber sp)
71  	//       {
72  	//       CQuat[0]=sp;
73  	//       }
74  	//
75  	//    void setBvPart(ComplexNumber[] bp)
76  	//       {
77  	//       CQuat[1] = bp[0];
78  	//       CQuat[2] = bp[1];
79  	//       CQuat[3] = bp[2];
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 //		CQprod[2] =
128 //		((p0.mult(q2)).add(p2.mult(q0)).sub(p3.mult(q1))).add(p1.mult(q3));
129 //		CQprod[3] =
130 //		((p0.mult(q3)).add(p3.mult(q0)).sub(p1.mult(q2))).add(p2.mult(q1));
131 //		
132 		return new ComplexQuat(CQprod);
133 	}
134 
135 	/*
136 	 * (non-Javadoc)
137 	 * 
138 	 * @see java.lang.Object#equals(java.lang.Object)
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 	 * (non-Javadoc)
155 	 * 
156 	 * @see java.lang.Object#hashCode()
157 	 */
158 	public int hashCode() {
159 		// TODO Auto-generated method stub
160 		return super.hashCode();
161 	}
162 
163 	/*
164 	 * (non-Javadoc)
165 	 * 
166 	 * @see java.lang.Object#toString()
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 }