1
2
3
4
5
6
7 package net.sourceforge.kamiwaai;
8
9 import java.awt.Graphics;
10 import java.awt.Graphics2D;
11 import java.awt.Point;
12 import java.awt.event.MouseEvent;
13 import java.util.StringTokenizer;
14
15 import net.sourceforge.kamiwaai.geometricalgebra.Line;
16 import net.sourceforge.kamiwaai.geometricalgebra.MultiVector;
17 import net.sourceforge.kamiwaai.geometricalgebra.PointC;
18 import net.sourceforge.kamiwaai.geometricalgebra.SwingDrawable;
19
20 class CMeineCanvasZ extends KamiWaAiCanvas {
21 public CMeineCanvasZ(KamiWaAi ai) {
22 super(ai);
23 }
24
25 public void mousePressed(MouseEvent e) {
26
27
28 aktuell = kamiwaai.ModeChoice.getSelection();
29
30
31
32
33 if (aktuell == null)
34 return;
35
36 label = aktuell.getActionCommand();
37
38
39
40 if (label.equals("point")) {
41 pointMode(e);
42 }
43
44 if (label.equals("move")) {
45 moveMode(e);
46 }
47
48 if (label.equals("circle")) {
49 circleMode(e);
50
51 }
52
53 if (label.equals("sphere")) {
54 sphereMode(e);
55
56 }
57
58 if (label.equals("sphere C,r")) {
59 sphereRadiusMode(e);
60 }
61
62 if (label.equals("line")) {
63 lineMode(e);
64
65 }
66
67 if (label.equals("S int l")) {
68 sphereIntersectLine(e);
69 }
70
71 if (label.equals("S int S")) {
72 sphereIntersectSphere(e);
73 }
74
75 }
76
77 /***
78 * @param e
79 */
80 private void moveMode(MouseEvent e) {
81 Point pt = e.getPoint();
82 this.kamiwaai.selectedPoint = pickPoint(pt);
83 }
84
85 /***
86 * @param e
87 */
88 private void pointMode(MouseEvent e) {
89 if (kamiwaai.sideview == true) {
90 k = 0;
91
92 String key = "P" + String.valueOf(this.kamiwaai.pnum);
93 PointC ptc3 = (PointC) this.kamiwaai.ENames.get(key);
94
95
96
97
98 ptc3.sete3(e.getX());
99 ptc3.drawZ(this.kamiwaai.m_malflaecheZ.getGraphics());
100 this.kamiwaai.ENames.put(key, ptc3);
101
102
103
104
105
106 this.kamiwaai.Clist.add(key);
107 kamiwaai.sideview = false;
108 }
109 }
110
111 public void mouseDragged(MouseEvent e) {
112
113
114 aktuell = kamiwaai.ModeChoice.getSelection();
115
116
117
118
119 if (aktuell == null)
120 return;
121
122 label = aktuell.getActionCommand();
123
124
125
126 if (label.equals("move")) {
127 if (this.kamiwaai.selectedPoint != " ") {
128
129 PointC movingPt = (PointC) this.kamiwaai.ENames
130 .get(this.kamiwaai.selectedPoint);
131 movingPt.erase(this.kamiwaai.m_malflaeche.getGraphics());
132 movingPt.eraseZ(this.kamiwaai.m_malflaecheZ.getGraphics());
133 movingPt.sete3(e.getX());
134 movingPt.sete2(e.getY());
135 this.kamiwaai.ENames.put(this.kamiwaai.selectedPoint, movingPt);
136 this.kamiwaai.mvdPoint = this.kamiwaai.selectedPoint;
137 this.kamiwaai.rdlist.add(this.kamiwaai.mvdPoint);
138
139 redrawPoints();
140 }
141
142 }
143
144 }
145
146 public void paint(Graphics gS) {
147
148
149
150 Graphics2D gZ = (Graphics2D) gS;
151 gZ.clearRect(0, 0, 300, 300);
152
153
154 for (int i = 0; i < this.kamiwaai.Clist.size(); i++) {
155 StringTokenizer st = new StringTokenizer(
156 (String) this.kamiwaai.Clist.get(i), ",");
157 String element = st.nextToken();
158 SwingDrawable renewObject = (SwingDrawable) this.kamiwaai.ENames
159 .get(element);
160 renewObject.drawZ(gZ);
161 }
162 }
163
164 String pickPoint(Point pt) {
165 double z = getXCoordinate(pt);
166 double y = getYCoordinate(pt);
167
168 for (int i = 0; i < this.kamiwaai.Clist.size(); i++) {
169 StringTokenizer st = new StringTokenizer(
170 (String) this.kamiwaai.Clist.get(i), ",");
171 String element = st.nextToken();
172 if (element.startsWith("P")) {
173 if (((PointC) this.kamiwaai.ENames.get(element))
174 .isYZpoint(y, z))
175 return element;
176 }
177 }
178 return " ";
179 }
180
181 /***
182 * Return key of the line that contains pt, if any, or " " otherwise.
183 *
184 */
185 protected String pickLine(Point pt) {
186 double[] picker = new double[3];
187 double delta = 3.0;
188 String linekey = " ";
189 picker[0] = 0.0;
190 picker[1] = getYCoordinate(pt);
191 picker[2] = pt.getX();
192
193 for (int i = 0; i < this.kamiwaai.Clist.size(); i++) {
194 StringTokenizer st = new StringTokenizer(
195 (String) this.kamiwaai.Clist.get(i), ",");
196 String element = st.nextToken();
197 if (element.startsWith("L")) {
198 Line oneline = (Line) this.kamiwaai.ENames.get(element);
199 double dyz = oneline.distanceYZ(picker);
200 if (dyz <= delta) {
201 linekey = element;
202 delta = dyz;
203 }
204 }
205 }
206 return linekey;
207 }
208
209 /***
210 * @param pt
211 * @param Poles
212 * @return
213 */
214 public double getDPoles(Point pt, MultiVector Poles) {
215 return Math.sqrt((getXCoordinate(pt) - getPolesZ(Poles))
216 * (getXCoordinate(pt) - getPolesZ(Poles))
217 + (getYCoordinate(pt) - getPolesY(Poles))
218 * (getYCoordinate(pt) - getPolesY(Poles)));
219 }
220
221 /***
222 * @param pt
223 * @param Pole
224 * @return
225 */
226 public double getDPole(Point pt, MultiVector Pole) {
227 return Math.sqrt((getXCoordinate(pt) - getPoleZ(Pole))
228 * (getXCoordinate(pt) - getPoleZ(Pole))
229 + (getYCoordinate(pt) - getPoleY(Pole))
230 * (getYCoordinate(pt) - getPoleY(Pole)));
231 }
232
233 }