1
2
3
4
5
6
7 package net.sourceforge.kamiwaai.geometricalgebra;
8 import junit.framework.TestCase;
9 /***
10 * @author Administrator
11 *
12 * TODO To change the template for this generated type comment go to Window -
13 * Preferences - Java - Code Generation - Code and Comments
14 */
15 public class CircleTest extends TestCase {
16 MultiVector CM;
17 Circle circle1;
18 Circle circle2;
19 public void testEquals() {
20 assertEquals(circle1, circle2);
21 }
22 public void testCtrivector() {
23 assertEquals(circle1.getMultiVector(), CM);
24 }
25 public void testRadius() {
26 assertEquals(circle1.radius(), 1.4142135623730951, 0.00000001);
27 }
28 public void testCenter() {
29 ComplexNumber[] carrays = {ComplexNumber.ZERO,
30 new ComplexNumber(0.0, -2.0), new ComplexNumber(0.0, -2.0),
31 new ComplexNumber(0.0, -2.0)};
32 ComplexQuat cqnhnb = new ComplexQuat(carrays);
33 ComplexNumber[] cn = {new ComplexNumber(6.000000000000001, 0.0),
34 ComplexNumber.ZERO, ComplexNumber.ZERO, ComplexNumber.ZERO};
35 ComplexQuat cqn = new ComplexQuat(cn);
36 ComplexQuat[] cqarrays = {ComplexQuat.ZERO, cqn, ComplexQuat.ONE,
37 cqnhnb};
38 MultiVector expectedMV = new MultiVector(cqarrays);
39 assertEquals(circle1.Center(), expectedMV);
40 }
41 public void testcenter() {
42 assertEquals(circle1.center()[0], 2.0, 0.000000001);
43 assertEquals(circle1.center()[1], 2.0, 0.000000001);
44 assertEquals(circle1.center()[2], 2.0, 0.000000001);
45 }
46 public void testCplane() {
47 ComplexNumber[] csc = {ComplexNumber.ZERO,
48 new ComplexNumber(-0.5773502691896258, 0.0),
49 new ComplexNumber(-0.5773502691896258, 0.0),
50 new ComplexNumber(-0.5773502691896258, 0.0)};
51 ComplexQuat cqsc = new ComplexQuat(csc);
52 ComplexQuat[] cqarrays = {cqsc, ComplexQuat.ZERO, ComplexQuat.ZERO,
53 ComplexQuat.ZERO};
54 MultiVector expectedMV = new MultiVector(cqarrays);
55 assertEquals(circle1.Cplane(), expectedMV);
56 }
57 public void testGenerator() {
58 ComplexNumber[] csc = {new ComplexNumber(6.123233995736766E-17, 0.0),
59 new ComplexNumber(-0.5773502691896258, 0.0),
60 new ComplexNumber(-0.5773502691896258, 0.0),
61 new ComplexNumber(-0.5773502691896258, 0.0)};
62 ComplexQuat cqsc = new ComplexQuat(csc);
63 ComplexNumber[] cn = {ComplexNumber.ZERO, ComplexNumber.ZERO,
64 ComplexNumber.ZERO,
65 new ComplexNumber(0.0, 4.9789962505147994E-17)};
66 ComplexQuat cqn = new ComplexQuat(cn);
67 ComplexQuat[] cqarrays = {cqsc, cqn, ComplexQuat.ZERO, ComplexQuat.ZERO};
68 MultiVector expectedMV = new MultiVector(cqarrays);
69 assertEquals(circle1.generator(2), expectedMV);
70 }
71 public void testPonC() {
72 ComplexNumber[] cnhnb = {new ComplexNumber(0.0, 0.0),
73 new ComplexNumber(0.0, -3.0),
74 new ComplexNumber(0.0, -1.0),
75 new ComplexNumber(0.0, -2.0)};
76 ComplexQuat cqnhnb = new ComplexQuat(cnhnb);
77 ComplexNumber[] cn = {new ComplexNumber(7.000000000000001, 0.0),
78 ComplexNumber.ZERO, ComplexNumber.ZERO, ComplexNumber.ZERO};
79 ComplexQuat cqn = new ComplexQuat(cn);
80 ComplexQuat[] cqarrays = {ComplexQuat.ZERO, cqn, ComplexQuat.ONE,
81 cqnhnb};
82 MultiVector expectedMV = new MultiVector(cqarrays);
83 assertEquals(circle1.PonC(), expectedMV);
84 }
85 public void testCpoints(){
86 double[][] results = circle1.cpoints(2);
87 assertEquals(results[0][0], 3.0, 0.000000000001);
88 assertEquals(results[0][1], 1.0, 0.000000000001);
89 assertEquals(results[0][2], 2.0, 0.000000000001);
90 assertEquals(results[1][0], 1.0, 0.000000000001);
91 assertEquals(results[1][1], 3.000000000000001, 0.000000000001);
92 assertEquals(results[1][2], 2.0000000000000004, 0.000000000001);
93 }
94 protected void setUp() throws Exception {
95 PointC point1 = new PointC();
96 point1.sete1(1.0);
97 point1.sete2(2.0);
98 point1.sete3(3.0);
99 PointC point2 = new PointC();
100 point2.sete1(2.0);
101 point2.sete2(1.0);
102 point2.sete3(3.0);
103 PointC point3 = new PointC();
104 point3.sete1(3.0);
105 point3.sete2(2.0);
106 point3.sete3(1.0);
107 CM = point1.getMultiVector().OutProd(point2.getMultiVector()).OutProd(
108 point3.getMultiVector());
109 circle1 = new Circle(CM);
110 circle2 = new Circle(point1, point2, point3);
111 }
112 public static void main(String[] args) {
113 CircleTest test = new CircleTest();
114 try {
115 test.setUp();
116 } catch (Exception e) {
117
118 e.printStackTrace();
119 }
120
121
122 double[] result = test.circle1.center();
123 for (int i = 0; i < result.length; i++) {
124
125 }
126
127
128
129 double[][] results = test.circle1.cpoints(2);
130 for (int i = 0; i < results.length; i++) {
131 for (int j = 0; j < results[i].length; j++) {
132 System.out.println("[" + i+ "][" + j + "] = " + results[i][j]);
133 }
134 }
135 }
136 }