1
2
3
4
5
6
7 package net.sourceforge.kamiwaai.geometricalgebra;
8 import java.util.Iterator;
9 import java.util.Vector;
10
11 import junit.framework.TestCase;
12 /***
13 * @author Administrator
14 *
15 * TODO To change the template for this generated type comment go to Window -
16 * Preferences - Java - Code Generation - Code and Comments
17 */
18 public class SphereTest extends TestCase {
19 MultiVector SM;
20 Sphere sphere1;
21 Sphere sphere2;
22 public void testEquals() {
23 assertEquals(sphere1, sphere2);
24 }
25 public void testRadius() {
26 assertEquals(sphere1.radius(), 3.423448553724738, 0.000000001);
27 }
28 public void testS4vector() {
29 assertEquals(sphere1.getMultiVector(), SM);
30 }
31 public void testCenter() {
32 ComplexNumber[] cn = {new ComplexNumber(21.66, 0.0),
33 ComplexNumber.ZERO, ComplexNumber.ZERO, ComplexNumber.ZERO};
34 ComplexQuat cqn = new ComplexQuat(cn);
35 ComplexNumber[] cnhnb = {ComplexNumber.ZERO,
36 new ComplexNumber(0.0, -3.8000000000000003),
37 new ComplexNumber(0.0, -3.8000000000000003),
38 new ComplexNumber(0.0, -3.8000000000000003)};
39 ComplexQuat cqnhnb = new ComplexQuat(cnhnb);
40 ComplexQuat[] cqarrays = {ComplexQuat.ZERO, cqn, ComplexQuat.ONE,
41 cqnhnb};
42 MultiVector expectedMV = new MultiVector(cqarrays);
43 assertEquals(sphere1.Center(), expectedMV);
44 }
45 public void testcenter() {
46 double[] result = sphere1.center();
47 assertEquals(result[0], 3.8000000000000003, 0.00000000001);
48 assertEquals(result[1], 3.8000000000000003, 0.00000000001);
49 assertEquals(result[2], 3.8000000000000003, 0.00000000001);
50 }
51 public void testGenerator() {
52 ComplexNumber[] cn = {ComplexNumber.ZERO,
53 new ComplexNumber(0.0, 4.440892098500626E-16),
54 new ComplexNumber(0.0, 2.687005768508881),
55 new ComplexNumber(0.0, -2.6870057685088815)};
56 ComplexQuat cqn = new ComplexQuat(cn);
57 ComplexNumber[] csc = {new ComplexNumber(6.123233995736766E-17, 0.0),
58 new ComplexNumber(0.0, 0.0),
59 new ComplexNumber(-0.7071067811865477, 0.0),
60 new ComplexNumber(-0.7071067811865476, 0.0)};
61 ComplexQuat cqsc = new ComplexQuat(csc);
62 ComplexQuat[] cqarrays = {cqsc, cqn, ComplexQuat.ZERO, ComplexQuat.ZERO};
63 MultiVector expectedMV = new MultiVector(cqarrays);
64 MultiVector pole = sphere1.PonS().OutProd(MultiVectors.N()).mult(
65 MultiVectors.N());
66 MultiVector center = sphere1.Center().OutProd(MultiVectors.N()).mult(
67 MultiVectors.N());
68 MultiVector plane = pole.sub(center).OutProd(MultiVectors.e1());
69 assertEquals(sphere1.generator(2, plane), expectedMV);
70 }
71 public void testPointOnSphere(){
72 ComplexNumber[] cn = {new ComplexNumber(35.03080998738929, 0.0),
73 ComplexNumber.ZERO, ComplexNumber.ZERO, ComplexNumber.ZERO};
74 ComplexQuat cqn = new ComplexQuat(cn);
75 ComplexNumber[] cnhnb = {ComplexNumber.ZERO,
76 new ComplexNumber(0.0, -5.776528944049812),
77 new ComplexNumber(0.0, -5.776528944049812),
78 new ComplexNumber(0.0, -1.8234710559501877)};
79 ComplexQuat cqnhnb = new ComplexQuat(cnhnb);
80 ComplexQuat[] cqarrays = {ComplexQuat.ZERO, cqn, ComplexQuat.ONE,
81 cqnhnb};
82 MultiVector expectedMV = new MultiVector(cqarrays);
83 assertEquals(sphere1.PonS(), expectedMV);
84 }
85 public void testAnotherPointOnSphere(){
86 ComplexNumber[] cn = {new ComplexNumber(20.009190012610713, 0.0),
87 ComplexNumber.ZERO, ComplexNumber.ZERO, ComplexNumber.ZERO};
88 ComplexQuat cqn = new ComplexQuat(cn);
89 ComplexNumber[] cnhnb = {ComplexNumber.ZERO,
90 new ComplexNumber(0.0, -1.8234710559501877),
91 new ComplexNumber(0.0, -1.8234710559501877),
92 new ComplexNumber(0.0, -5.776528944049812)};
93 ComplexQuat cqnhnb = new ComplexQuat(cnhnb);
94 ComplexQuat[] cqarrays = {ComplexQuat.ZERO, cqn, ComplexQuat.ONE,
95 cqnhnb};
96 MultiVector expectedMV = new MultiVector(cqarrays);
97 assertEquals(sphere1.PonSsouth(), expectedMV);
98 }
99 public void testSnet(){
100 ComplexNumber c12 = new ComplexNumber(0.0, -1.4210854715202004E-14);
101 ComplexNumber c23 = new ComplexNumber(0.0, 72.72698345639441);
102 ComplexNumber c34 = new ComplexNumber(0.0, 36.363491728197275);
103 ComplexNumber c41 = new ComplexNumber(0.0, -109.09047518459167);
104 ComplexNumber[] c12341 = { c12, c23, c34, c41 };
105 ComplexQuat cq12341 = new ComplexQuat(c12341);
106
107 ComplexNumber c45 = new ComplexNumber(-7.105427357601002E-15, 0.0);
108 ComplexNumber c56 = new ComplexNumber(26.02860460544656, 0.0);
109 ComplexNumber c67 = new ComplexNumber(-427.55810800417134, 0.0);
110 ComplexNumber c74 = new ComplexNumber(-125.16696626442602, 0.0);
111 ComplexNumber[] c45675 = { c45, c56, c67, c74 };
112 ComplexQuat cq45675 = new ComplexQuat(c45675);
113
114 ComplexNumber c78 = new ComplexNumber(1.5477758515907475E-15, 0.0);
115 ComplexNumber c89 = new ComplexNumber(-19.138679856945906, 0.0);
116 ComplexNumber c90 = new ComplexNumber(9.569339928472953, 0.0);
117 ComplexNumber c07 = new ComplexNumber(-9.569339928472939, 0.0);
118 ComplexNumber[] c78907 = { c78, c89, c90, c07 };
119 ComplexQuat cq78907 = new ComplexQuat(c78907);
120
121 ComplexNumber c01 = new ComplexNumber(0.0, -72.72698345639436);
122 ComplexNumber c02 = new ComplexNumber(0.0, -1.7763568394002505E-15);
123 ComplexNumber c03 = new ComplexNumber(0.0, 5.329070518200751E-15);
124 ComplexNumber c04 = new ComplexNumber(0.0, -1.7763568394002505E-15);
125 ComplexNumber[] c01234 = { c01, c02, c03, c04 };
126 ComplexQuat cq01235 = new ComplexQuat(c01234);
127
128 ComplexQuat[] cqarray = { cq12341, cq45675, cq78907, cq01235 };
129
130 MultiVector mv3 = new MultiVector(cqarray);
131 assertEquals((Circle)sphere1.snet(2).get(2), new Circle(mv3));
132 }
133 protected void setUp() throws Exception {
134 PointC point1 = new PointC();
135 point1.sete1(1.0);
136 point1.sete2(2.0);
137 point1.sete3(3.0);
138 PointC point2 = new PointC();
139 point2.sete1(2.0);
140 point2.sete2(1.0);
141 point2.sete3(3.0);
142 PointC point3 = new PointC();
143 point3.sete1(3.0);
144 point3.sete2(2.0);
145 point3.sete3(1.0);
146 PointC point4 = new PointC();
147 point4.sete1(7.0);
148 point4.sete2(5.0);
149 point4.sete3(4.0);
150 SM = point1.getMultiVector().OutProd(point2.getMultiVector()).OutProd(
151 point3.getMultiVector().OutProd(point4.getMultiVector()));
152 sphere1 = new Sphere(SM);
153 sphere2 = new Sphere(point1, point2, point3, point4);
154 }
155 public static void main(String[] args) {
156 SphereTest test = new SphereTest();
157 try {
158 test.setUp();
159 } catch (Exception e) {
160 e.printStackTrace();
161 }
162
163
164 MultiVector pole = test.sphere1.PonS().OutProd(MultiVectors.N()).mult(
165 MultiVectors.N());
166 MultiVector center = test.sphere1.Center().OutProd(MultiVectors.N()).mult(
167 MultiVectors.N());
168
169
170
171
172 Vector grid = test.sphere1.snet(2);
173 for (Iterator iter = grid.iterator(); iter.hasNext();) {
174 Circle circle = (Circle) iter.next();
175 System.out.println(circle);
176 }
177 }
178 }