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 LineTest extends TestCase {
16 Line line1;
17 Line line2;
18 Line line3;
19 PointC point1;
20 PointC point2;
21 MultiVector mv;
22 double[] picked = {3.0, 4.0, 5.0};
23 public void testEquals() {
24 assertEquals(line1, line2);
25 assertEquals(line1, line3);
26 }
27 public void testLtrivector() {
28 assertEquals(line1.getMultiVector(), mv);
29 }
30 public void testGetMoment() {
31 ComplexNumber[] carrays = {ComplexNumber.ZERO,
32 new ComplexNumber(-60.0, 0.0), new ComplexNumber(90.0, 0.0),
33 new ComplexNumber(-30.0, 0.0)};
34 ComplexQuat cqn = new ComplexQuat(carrays);
35 ComplexQuat[] cqarrays = {cqn, ComplexQuat.ZERO, ComplexQuat.ZERO,
36 ComplexQuat.ZERO};
37 MultiVector expectedMV = new MultiVector(cqarrays);
38 assertEquals(line1.getMoment(), expectedMV);
39 assertEquals(line1.getMoment(), mv.OutProd(MultiVectors.nbar()).mult(
40 MultiVectors.N()));
41 }
42 public void testGetLineVector() {
43 ComplexNumber[] carrays = {ComplexNumber.ZERO,
44 new ComplexNumber(0.0, -1.0), new ComplexNumber(0.0, 3.0),
45 new ComplexNumber(0.0, 11.0)};
46 ComplexQuat cqnhnb = new ComplexQuat(carrays);
47 ComplexQuat[] cqarrays = {ComplexQuat.ZERO, ComplexQuat.ZERO,
48 ComplexQuat.ZERO, cqnhnb};
49 MultiVector expectedMV = new MultiVector(cqarrays);
50 assertEquals(line1.getLineVector(), expectedMV);
51 assertEquals(line1.getLineVector(), mv.Rcontract(MultiVectors.N()));
52 }
53 public void testLinePoint() {
54 ComplexNumber[] carrays = {ComplexNumber.ZERO,
55 new ComplexNumber(0.0, -11.244274809160306),
56 new ComplexNumber(0.0, 3.7328244274809164),
57 new ComplexNumber(0.0, 33.68702290076336)};
58 ComplexQuat cqnhnb = new ComplexQuat(carrays);
59 ComplexQuat[] cqarrays = {ComplexQuat.ZERO, ComplexQuat.ZERO,
60 ComplexQuat.ZERO, cqnhnb};
61 MultiVector expectedMV = new MultiVector(cqarrays);
62 assertEquals(line1.LinePoint(3.0), expectedMV);
63 }
64 public void testLinepoint3d() {
65 assertEquals(line1.linepoint3D(3.0)[0], 11.244274809160306,
66 0.0000000001);
67 assertEquals(line1.linepoint3D(3.0)[1], -3.7328244274809164,
68 0.0000000001);
69 assertEquals(line1.linepoint3D(3.0)[2], -33.68702290076336,
70 0.0000000001);
71 }
72 public void testPDistance2D() {
73 MultiVector xyplane = MultiVectors.e1().OutProd(MultiVectors.e2())
74 .mult(MultiVectors.N());
75 MultiVector yzplane = MultiVectors.e2().OutProd(MultiVectors.e3())
76 .mult(MultiVectors.N());
77 ComplexNumber[] carraysxy = {ComplexNumber.ZERO,
78 new ComplexNumber(0.0, 5.099999999999997),
79 new ComplexNumber(0.0, 1.6999999999999988), ComplexNumber.ZERO};
80 ComplexQuat cqnhnbxy = new ComplexQuat(carraysxy);
81 ComplexQuat[] cqarraysxy = {ComplexQuat.ZERO, ComplexQuat.ZERO,
82 ComplexQuat.ZERO, cqnhnbxy};
83 MultiVector expectedMVxy = new MultiVector(cqarraysxy);
84 assertEquals(line1.PDistance2D(picked, xyplane), expectedMVxy);
85 ComplexNumber[] carraysyz = {ComplexNumber.ZERO, ComplexNumber.ZERO,
86 new ComplexNumber(0.0, 2.623076923076924),
87 new ComplexNumber(0.0, -0.7153846153846156)};
88 ComplexQuat cqnhnbyz = new ComplexQuat(carraysyz);
89 ComplexQuat[] cqarraysyz = {ComplexQuat.ZERO, ComplexQuat.ZERO,
90 ComplexQuat.ZERO, cqnhnbyz};
91 MultiVector expectedMVyz = new MultiVector(cqarraysyz);
92 assertEquals(line1.PDistance2D(picked, yzplane), expectedMVyz);
93 }
94 public void testDistanceXY() {
95 assertEquals(line1.distanceXY(picked), 5.3758720222862415, 0.000001);
96 }
97 public void testDistanceYZ() {
98 assertEquals(line1.distanceYZ(picked), 2.7188798598517914, 0.000001);
99 }
100
101
102
103
104
105 protected void setUp() throws Exception {
106 point1 = new PointC();
107 point1.sete1(7.0);
108 point1.sete2(9.0);
109 point1.sete3(13.0);
110 point2 = new PointC();
111 point2.sete1(8.0);
112 point2.sete2(6.0);
113 point2.sete3(2.0);
114 MultiVector point1MV = point1.getMultiVector();
115 MultiVector point2MV = point2.getMultiVector();
116 mv = point1MV.OutProd(point2MV).OutProd(MultiVectors.n());
117 line1 = new Line(mv);
118 line2 = new Line(mv);
119 line3 = new Line(point1, point2);
120 }
121
122
123
124
125
126 protected void tearDown() throws Exception {
127
128 super.tearDown();
129 }
130 public static void main(String[] args) {
131 LineTest test = new LineTest();
132 try {
133 test.setUp();
134 } catch (Exception e) {
135
136 e.printStackTrace();
137 }
138
139
140
141 PointC point3 = new PointC();
142 point3.sete1(3.0);
143 point3.sete2(4.0);
144 point3.sete3(5.0);
145 Line line4 = new Line(test.point1, point3);
146 Line line5 = new Line(point3, test.point2);
147
148
149 System.out.println(test.line1);
150
151
152
153
154
155
156 double[] picked = {3.0, 4.0, 5.0};
157
158 MultiVector xyplane = MultiVectors.e1().OutProd(MultiVectors.e2())
159 .mult(MultiVectors.N());
160
161 MultiVector yzplane = MultiVectors.e2().OutProd(MultiVectors.e3())
162 .mult(MultiVectors.N());
163
164
165
166 System.out.println(test.line1.distanceXY(picked));
167 System.out.println(test.line1.distanceYZ(picked));
168 }
169 }