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
43
44
45 package net.sourceforge.kamiwaai;
46 import java.awt.FlowLayout;
47 import java.awt.Font;
48 import java.awt.GridLayout;
49 import java.awt.Label;
50 import java.awt.event.ActionEvent;
51 import java.awt.event.ActionListener;
52 import java.awt.event.WindowAdapter;
53 import java.awt.event.WindowEvent;
54
55 import javax.swing.JButton;
56 import javax.swing.JFrame;
57 import javax.swing.JLabel;
58 import javax.swing.JPanel;
59 import javax.swing.JTextField;
60 import javax.swing.SwingConstants;
61
62 import net.sourceforge.kamiwaai.geometricalgebra.MultiVector;
63 import net.sourceforge.kamiwaai.geometricalgebra.MultiVectors;
64 import net.sourceforge.kamiwaai.geometricalgebra.PointC;
65
66
67 public class Dihed extends JFrame
68 {
69 public static MultiVector N = MultiVectors.N();
70 public static MultiVector n = MultiVectors.n();
71 public static MultiVector nbar = MultiVectors.nbar();
72 public static MultiVector One = MultiVectors.One();
73 public static MultiVector I = MultiVectors.I();
74 public static MultiVector e1 = MultiVectors.e1();
75 public static MultiVector e2 = MultiVectors.e2();
76 public static MultiVector e3 = MultiVectors.e3();
77 JButton doitswitch;
78 JTextField A1x_F, A1y_F, A1z_F, A2x_F, A2y_F, A2z_F, A3x_F, A3y_F, A3z_F;
79 JTextField B1x_F, B1y_F, B1z_F, B2x_F, B2y_F, B2z_F, B3x_F, B3y_F, B3z_F;
80 JTextField angled_F, angler_F, cos_F, sin_F, mx_F, my_F, mz_F;
81
82
83 Dihed(String titel)
84 {
85 super(titel);
86
87 getContentPane().setLayout(new GridLayout(12,3,5,5));
88
89 JPanel panel1 = new JPanel();
90 panel1.setLayout(new FlowLayout());
91
92 JPanel panel2 = new JPanel();
93 panel2.setLayout(new FlowLayout());
94
95 JPanel panel3 = new JPanel();
96 panel3.setLayout(new FlowLayout());
97
98 JPanel panel4 = new JPanel();
99 panel1.setLayout(new FlowLayout());
100
101 JPanel panel5 = new JPanel();
102 panel2.setLayout(new FlowLayout());
103
104 JPanel panel6 = new JPanel();
105 panel3.setLayout(new FlowLayout());
106
107 JPanel panel7 = new JPanel();
108 panel3.setLayout(new FlowLayout());
109
110 JPanel panel8 = new JPanel();
111 panel3.setLayout(new FlowLayout());
112
113 JPanel panel9 = new JPanel();
114 panel3.setLayout(new FlowLayout());
115
116
117
118 JLabel A1x_L = new JLabel("A1x", SwingConstants.RIGHT);
119 A1x_F = new JTextField(10);
120 A1x_F.setText("0.0");
121 panel1.add(A1x_L);
122 panel1.add(A1x_F);
123
124 JLabel A2x_L = new JLabel("A2x", SwingConstants.RIGHT);
125 A2x_F = new JTextField(10);
126 A2x_F.setText("0.0");
127 panel1.add(A2x_L);
128 panel1.add(A2x_F);
129
130 JLabel A3x_L = new JLabel("A3x", SwingConstants.RIGHT);
131 A3x_F = new JTextField(10);
132 A3x_F.setText("0.0");
133 panel1.add(A3x_L);
134 panel1.add(A3x_F);
135
136
137 JLabel A1y_L = new JLabel("A1y", SwingConstants.RIGHT);
138 A1y_F = new JTextField(10);
139 A1y_F.setText("0.0");
140 panel2.add(A1y_L);
141 panel2.add(A1y_F);
142
143 JLabel A2y_L = new JLabel("A2y", SwingConstants.RIGHT);
144 A2y_F = new JTextField(10);
145 A2y_F.setText("0.0");
146 panel2.add(A2y_L);
147 panel2.add(A2y_F);
148
149 JLabel A3y_L = new JLabel("A3y", SwingConstants.RIGHT);
150 A3y_F = new JTextField(10);
151 A3y_F.setText("0.0");
152 panel2.add(A3y_L);
153 panel2.add(A3y_F);
154
155
156 JLabel A1z_L = new JLabel("A1z", SwingConstants.RIGHT);
157 A1z_F = new JTextField(10);
158 A1z_F.setText("0.0");
159 panel3.add(A1z_L);
160 panel3.add(A1z_F);
161
162 JLabel A2z_L = new JLabel("A2z", SwingConstants.RIGHT);
163 A2z_F = new JTextField(10);
164 A2z_F.setText("0.0");
165 panel3.add(A2z_L);
166 panel3.add(A2z_F);
167
168 JLabel A3z_L = new JLabel("A3z", SwingConstants.RIGHT);
169 A3z_F = new JTextField(10);
170 A3z_F.setText("0.0");
171 panel3.add(A3z_L);
172 panel3.add(A3z_F);
173
174
175
176 JLabel B1x_L = new JLabel("B1x", SwingConstants.RIGHT);
177 B1x_F = new JTextField(10);
178 B1x_F.setText("0.0");
179 panel4.add(B1x_L);
180 panel4.add(B1x_F);
181
182 JLabel B2x_L = new JLabel("B2x", SwingConstants.RIGHT);
183 B2x_F = new JTextField(10);
184 B2x_F.setText("0.0");
185 panel4.add(B2x_L);
186 panel4.add(B2x_F);
187
188 JLabel B3x_L = new JLabel("B3x", SwingConstants.RIGHT);
189 B3x_F = new JTextField(10);
190 B3x_F.setText("0.0");
191 panel4.add(B3x_L);
192 panel4.add(B3x_F);
193
194
195 JLabel B1y_L = new JLabel("B1y", SwingConstants.RIGHT);
196 B1y_F = new JTextField(10);
197 B1y_F.setText("0.0");
198 panel5.add(B1y_L);
199 panel5.add(B1y_F);
200
201 JLabel B2y_L = new JLabel("B2y", SwingConstants.RIGHT);
202 B2y_F = new JTextField(10);
203 B2y_F.setText("0.0");
204 panel5.add(B2y_L);
205 panel5.add(B2y_F);
206
207 JLabel B3y_L = new JLabel("B3y", SwingConstants.RIGHT);
208 B3y_F = new JTextField(10);
209 B3y_F.setText("0.0");
210 panel5.add(B3y_L);
211 panel5.add(B3y_F);
212
213
214 JLabel B1z_L = new JLabel("B1z", SwingConstants.RIGHT);
215 B1z_F = new JTextField(10);
216 B1z_F.setText("0.0");
217 panel6.add(B1z_L);
218 panel6.add(B1z_F);
219
220 JLabel B2z_L = new JLabel("B2z", SwingConstants.RIGHT);
221 B2z_F = new JTextField(10);
222 B2z_F.setText("0.0");
223 panel6.add(B2z_L);
224 panel6.add(B2z_F);
225
226 JLabel B3z_L = new JLabel("B3z", SwingConstants.RIGHT);
227 B3z_F = new JTextField(10);
228 B3z_F.setText("0.0");
229 panel6.add(B3z_L);
230 panel6.add(B3z_F);
231
232 doitswitch = new JButton("Get angle!");
233
234 JLabel angled_L = new JLabel("Dihedral angle [deg]", SwingConstants.RIGHT);
235 angled_F = new JTextField(5);
236
237 panel7.add(angled_L);
238 panel7.add(angled_F);
239
240 JLabel angler_L = new JLabel("dh. angle [rad]", SwingConstants.RIGHT);
241 angler_F = new JTextField(5);
242
243 panel7.add(angler_L);
244 panel7.add(angler_F);
245
246 JLabel cos_L = new JLabel("cos", SwingConstants.RIGHT);
247 cos_F = new JTextField(5);
248
249 panel8.add(cos_L);
250 panel8.add(cos_F);
251
252 JLabel sin_L = new JLabel("sin", SwingConstants.RIGHT);
253 sin_F = new JTextField(5);
254
255 panel8.add(sin_L);
256 panel8.add(sin_F);
257
258 JLabel mx_L = new JLabel("Dir. of intsec. mx", SwingConstants.RIGHT);
259 mx_F = new JTextField(5);
260
261 panel9.add(mx_L);
262 panel9.add(mx_F);
263
264 JLabel my_L = new JLabel("my", SwingConstants.RIGHT);
265 my_F = new JTextField(5);
266
267 panel9.add(my_L);
268 panel9.add(my_F);
269
270 JLabel mz_L = new JLabel("mz", SwingConstants.RIGHT);
271 mz_F = new JTextField(5);
272
273 panel9.add(mz_L);
274 panel9.add(mz_F);
275
276 Label plane1_L = new Label("Coordinates of three points on plane 1");
277 plane1_L.setFont(new Font("SansSerif",Font.BOLD,14));
278 getContentPane().add(plane1_L);
279 getContentPane().add(panel1);
280 getContentPane().add(panel2);
281 getContentPane().add(panel3);
282
283 Label plane2_L = new Label("Coordinates of three points on plane 2");
284 plane2_L.setFont(new Font("SansSerif",Font.BOLD,14));
285 getContentPane().add(plane2_L);
286 getContentPane().add(panel4);
287 getContentPane().add(panel5);
288 getContentPane().add(panel6);
289
290 getContentPane().add(doitswitch);
291
292 getContentPane().add(panel7);
293 getContentPane().add(panel8);
294 getContentPane().add(panel9);
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314 doitswitch.addActionListener(new CMyActionListener());
315 addWindowListener(new CMeinWindowLauscher());
316 }
317
318
319
320 class CMeinWindowLauscher extends WindowAdapter
321 {
322 public void windowClosing(WindowEvent e)
323 {
324 System.exit(0);
325 }
326 }
327
328
329 class CMyActionListener implements ActionListener
330 {
331 public void actionPerformed(ActionEvent e)
332 {
333 double a11,a12,a13, a21,a22,a23, a31,a32,a33;
334 double b11,b12,b13, b21,b22,b23, b31,b32,b33;
335 double m1, m2, m3;
336 double angler, angled, cos, sin;
337 doitswitch.setText("Evaluate again!");
338 a11 = Double.parseDouble(A1x_F.getText());
339 a12 = Double.parseDouble(A1y_F.getText());
340 a13 = Double.parseDouble(A1z_F.getText());
341
342 a21 = Double.parseDouble(A2x_F.getText());
343 a22 = Double.parseDouble(A2y_F.getText());
344 a23 = Double.parseDouble(A2z_F.getText());
345
346 a31 = Double.parseDouble(A3x_F.getText());
347 a32 = Double.parseDouble(A3y_F.getText());
348 a33 = Double.parseDouble(A3z_F.getText());
349
350 b11 = Double.parseDouble(B1x_F.getText());
351 b12 = Double.parseDouble(B1y_F.getText());
352 b13 = Double.parseDouble(B1z_F.getText());
353
354 b21 = Double.parseDouble(B2x_F.getText());
355 b22 = Double.parseDouble(B2y_F.getText());
356 b23 = Double.parseDouble(B2z_F.getText());
357
358 b31 = Double.parseDouble(B3x_F.getText());
359 b32 = Double.parseDouble(B3y_F.getText());
360 b33 = Double.parseDouble(B3z_F.getText());
361
362 PointC A1 = new PointC();
363 A1.sete1(a11);
364 A1.sete2(a12);
365 A1.sete3(a13);
366
367 PointC A2 = new PointC();
368 A2.sete1(a21);
369 A2.sete2(a22);
370 A2.sete3(a23);
371
372 PointC A3 = new PointC();
373 A3.sete1(a31);
374 A3.sete2(a32);
375 A3.sete3(a33);
376
377 PointC B1 = new PointC();
378 B1.sete1(b11);
379 B1.sete2(b12);
380 B1.sete3(b13);
381
382 PointC B2 = new PointC();
383 B2.sete1(b21);
384 B2.sete2(b22);
385 B2.sete3(b23);
386
387 PointC B3 = new PointC();
388 B3.sete1(b31);
389 B3.sete2(b32);
390 B3.sete3(b33);
391
392
393
394 MultiVector plane1 = A1.getMultiVector().OutProd(A2.getMultiVector()).OutProd(A3.getMultiVector()).OutProd(n);
395 MultiVector plane2 = B1.getMultiVector().OutProd(B2.getMultiVector()).OutProd(B3.getMultiVector()).OutProd(n);
396 MultiVector p1p2 = plane1.mult(plane2);
397
398
399 MultiVector DA = p1p2.OutProd(N).mult(N);
400 double DA0 = DA.ScProd(One);
401 MultiVector DA2 = DA.getGrade(2);
402 double DA2mag = DA2.magnitude();
403 MultiVector meet = DA2.mult(I).mult(N).multSc(-1.0);
404 MultiVector meet1 = meet.multSc(1.0/DA2mag);
405 m1 = meet1.ScProd(e1);
406 m2 = meet1.ScProd(e2);
407 m3 = meet1.ScProd(e3);
408
409 cos = Math.abs(DA0/Math.sqrt(DA0*DA0+DA2mag*DA2mag));
410 sin = DA2mag/Math.sqrt(DA0*DA0+DA2mag*DA2mag);
411 angler = (double) Math.atan2(sin,cos);
412 angled = (double) angler/(Math.PI)*180.0;
413
414
415
416 angled_F.setText(Double.toString(angled).substring(0,Math.min( 7, Double.toString(angled).length() )));
417 angler_F.setText(Double.toString(angler).substring(0,Math.min(7, Double.toString(angler).length() )));
418 cos_F.setText(Double.toString(cos).substring(0,Math.min(7,Double.toString(cos).length())));
419 sin_F.setText(Double.toString(sin).substring(0,Math.min(7,Double.toString(sin).length())));
420 mx_F.setText(Double.toString(m1).substring(0,Math.min(7,Double.toString(m1).length())));
421 my_F.setText(Double.toString(m2).substring(0,Math.min(7,Double.toString(m2).length())));
422 mz_F.setText(Double.toString(m3).substring(0,Math.min(7,Double.toString(m3).length())));
423 }
424 }
425
426 public static void main(String[] args)
427 {
428 Dihed fenster = new Dihed("Dihedral Angle 0.1");
429 fenster.pack();
430 fenster.setSize(500,500);
431 fenster.setResizable(false);
432 fenster.show();
433 }
434 }