-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDREIECK.java
More file actions
375 lines (321 loc) · 11.1 KB
/
DREIECK.java
File metadata and controls
375 lines (321 loc) · 11.1 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
/** @author mike ganshorn
*
* @Version 2.4-beginner (2017-04-11)
*
* @changelog 2.4 WECHSELBILD erbt von Knoten und damit von Raum
* verschiebenUm greift auf bewegen zurueck
* Methoden in allen Klassen vereinheitlicht (bis auf indiv. Methoden)
*
* 2.3 Methode beruehrt(WECHSELBILD) hinzugefuegt
*
* 2.2 Jump'n'Run-Physik hinzu gefuegt.
*
* 2.1 keine Abhaengigkeit mehr zwischen den alpha-Formen
* Der Mittelpunkt des Dreiecks ist hier der Mittelpunkt des umhuellenden Rechtecks !!!
*
*
*/
import ea.edu.DreieckE;
import ea.Raum;
/**
* Diese Klasse stellt ein einfaches Dreieck dar.
*/
public class DREIECK
extends DreieckE
{
/**
* Die Farbe dieses Dreiecks
*/
private String farbe;
/**
* Gibt an, ob dieses Dreieck sichtbar ist.
*/
private boolean sichtbar;
/**
* x-Koordinate des Eckpunkts A
*/
private float A_x;
/**
* y-Koordinate des Eckpunkts A
*/
private float A_y;
/**
* x-Koordinate des Eckpunkts B
*/
private float B_x;
/**
* y-Koordinate des Eckpunkts B
*/
private float B_y;
/**
* x-Koordinate des Eckpunkts C
*/
private float C_x;
/**
* y-Koordinate des Eckpunkts C
*/
private float C_y;
/**
* x-Koordinate des Mittelpunkts des umschliessenden Rechtecks
*/
private float M_x;
/**
* y-Koordinate des Mittelpunkts des umschliessenden Rechtecks
*/
private float M_y;
/**
* Konstruktor der Klasse <code>DREIECK</code>. Erstellt ein neues Standard-Dreieck.
*/
public DREIECK()
{
this( 80 , 190 , 150 , 70 , 220 , 190 );
}
/**
* Konstruktor der Klasse <code>DREIECK</code>. Erstellt ein neues Dreieck mit gegebenen Eck-Koordinaten.
* Die Reihenfolge der Ecken ist egal.
*
* @param Ax Die x-Koordinate der ersten Ecke
* @param Ay Die y-Koordinate der ersten Ecke
* @param Bx Die x-Koordinate der zweiten Ecke
* @param By Die y-Koordinate der zeiten Ecke
* @param Cx Die x-Koordinate der dritten Ecke
* @param Cy Die y-Koordinate der dritten Ecke
*/
public DREIECK( float Ax , float Ay , float Bx , float By , float Cx , float Cy )
{
this.A_x = Ax;
this.A_y = Ay;
this.B_x = Bx;
this.B_y = By;
this.C_x = Cx;
this.C_y = 50;
this.M_x = ( Math.min(Math.min(Ax,Bx),Cx) + Math.max(Math.max(Ax,Bx),Cx) ) / 2 ;
this.M_y = ( Math.min(Math.min(Ay,By),Cy) + Math.max(Math.max(Ay,By),Cy) ) / 2 ;
super.punkteSetzen( (int)Ax , (int)Ay , (int)Bx , (int)By , (int)Cx , (int)Cy );
this.sichtbar = true;
super.sichtbarSetzen( true);
this.farbe = "Gruen";
super.farbeSetzen( this.farbe );
}
/**
* Setzt die Ecken dieses Dreiecks (A, B, C) neu.
*
* @param Ax Die X-Koordinate des Punktes A
* @param Ay Die Y-Koordinate des Punktes A
* @param Bx Die X-Koordinate des Punktes B
* @param By Die Y-Koordinate des Punktes B
* @param Cx Die X-Koordinate des Punktes C
* @param Cy Die Y-Koordinate des Punktes C
*/
public void setzeEcken( float Ax , float Ay , float Bx , float By , float Cx , float Cy )
{
this.A_x = Ax;
this.A_y = Ay;
this.B_x = Bx;
this.B_y = By;
this.C_x = Cx;
this.C_y = Cy;
this.M_x = ( Math.min(Math.min(Ax,Bx),Cx) + Math.max(Math.max(Ax,Bx),Cx) ) / 2 ;
this.M_y = ( Math.min(Math.min(Ay,By),Cy) + Math.max(Math.max(Ay,By),Cy) ) / 2 ;
super.punkteSetzen( (int)Ax , (int)Ay , (int)Bx , (int)By , (int)Cx , (int)Cy );
}
/**
* Setzt die Farbe dieses Dreiecks neu.
*
* @param farbeNeu Diese Farbe erhaelt das Dreieck (z.B. "Rot")
*/
public void setzeFarbe( String farbeNeu )
{
this.farbe = farbeNeu;
super.farbeSetzen( farbe );
}
/**
* Setzt den Mittelpunkt dieses Dreieck neu.<br />
* <b>ACHTUNG!</b><br />
* Dies ist <i>nicht</i> der geometrische Mittelpunkt. Denkt man sich ein Rechteck,
* das man "genau ueber das Dreieck" spannt, sodass es dieses gerade von allen Seiten umschliesst,
* so ist der Mittelpunkt <b>dieses Rechtecks</b> der, der hier neu gesetzt wird.
*
* @param x Die X-Koordinate des neuen Mittelpunktes
*
* @param y Die Y-Koordinate des neuen Mittelpunktes
*/
public void setzeMittelpunkt( int x , int y )
{
int deltaX = (int)(x - this.M_x);
int deltaY = (int)(y - this.M_y);
this.A_x = this.A_x + deltaX;
this.A_y = this.A_y + deltaY;
this.B_x = this.B_x + deltaX;
this.B_y = this.B_y + deltaY;
this.C_x = this.C_x + deltaX;
this.C_y = this.C_y + deltaY;
this.M_x = x;
this.M_y = y;
super.mittelpunktSetzen( x , y );
}
/**
* Setzt, ob dieses Dreieck sichtbar sein soll.
*
* @param sichtbarNeu Ist dieser Wert <code>true</code>, ist nach dem Aufruf dieser Methode
* dieses Dreieck sichtbar. Ist dieser Wert <code>false</code>, so ist nach dem Aufruf
* dieser Methode dieses Dreieck unsichtbar.
*/
public void setzeSichtbar( boolean sichtbarNeu )
{
this.sichtbar = sichtbarNeu;
super.sichtbarSetzen( sichtbarNeu );
}
/**
* Verschiebt dieses Dreieck um eine Verschiebung - angegeben durch ein "Delta X" und "Delta Y".
*
* @param deltaX Der X Anteil dieser Verschiebung. Positive Werte verschieben nach rechts, negative nach links.
*
* @param deltaY Der Y Anteil dieser Verschiebung. Positive Werte verschieben nach unten, negative nach oben.
*/
public void verschiebenUm( float deltaX , float deltaY )
{
this.A_x = this.A_x + deltaX;
this.A_y = this.A_y + deltaY;
this.B_x = this.B_x + deltaX;
this.B_y = this.B_y + deltaY;
this.C_x = this.C_x + deltaX;
this.C_y = this.C_y + deltaY;
this.M_x = this.M_x + deltaX;
this.M_y = this.M_y + deltaY;
super.bewegen( deltaX , deltaY );
}
/**
* Testet, ob ein anderes Grafik-Objekt beruehrt wird.
*
* @param r Ein anderes BILD, RECHTECK, KREIS, DREIECK, ...
*
* @return true, wenn sich die beiden Objekte ueberschneiden
*/
public boolean beruehrt( Raum r )
{
return super.schneidet( r );
}
/**
* Methode beinhaltetPunkt
*
* @param x x-Koordinate des Punkts (Pixel)
* @param y x-Koordinate des Punkts (Pixel)
* @return true, wenn Punkt innerhalb der Grafik
*/
public boolean beinhaltetPunkt(int x, int y)
{
return super.beinhaltet( new ea.Punkt(x,y) );
}
/**
* Diese Methode gibt die x-Koordinate des Mittelpunkts dieses Dreiecks zurueck.
*
* @return Die aktuelle x-Koordinate des Mittelpunktes dieses Dreiecks
*/
public int nenneMx()
{
return (int)( Math.round(this.M_x) );
}
/**
* Diese Methode gibt die y-Koordinate des Mittelpunkts dieses Kreises zurueck.
*
* @return Die aktuelle y-Koordinate des Mittelpunktes dieses Kreises
*/
public int nenneMy()
{
return (int)( Math.round(this.M_y) );
}
/**
* Diese Methode gibt die Farbe dieses Dreiecks zurueck.
*
* @return Die aktuelle Farbe dieses Dreiecks
*/
public String nenneFarbe()
{
return this.farbe;
}
/**
* Diese Methode gibt die Sichtbarkeit dieses Dreiecks zurueck.
*
* @return Die aktuelle Sichtbarkeit dieses Dreiecks
*/
public boolean nenneSichtbar()
{
return this.sichtbar;
}
/**
* Diese Methode prueft, wie weit der Mittelpunkt dieses Rechtecks vom Mittelpunkt
* eines anderen Grfik-Objekts in x-Richtung entfernt ist.
*
* @param grafikObjekt Das andere Grafik-Objekt
*
* @return Abstand (in Pixeln) dieses Rechtecks vom anderen Grafik-Objekt in x-Richtung (>0, wenn dieses Rechteck rechts des anderen Grafik-Objekts liegt)
*/
public int berechneAbstandX( Raum grafikObjekt )
{
return (int)( this.M_x - grafikObjekt.mittelPunkt().x() );
}
/**
* Diese Methode prueft, wie weit der Mittelpunkt dieses Dreiecks vom Mittelpunkt
* eines anderen Grfik-Objekts in y-Richtung entfernt ist.
*
* @param grafikObjekt Das andere Grafik-Objekt
*
* @return Abstand (in Pixeln) dieses Dreiecks vom anderen Grafik-Objekt in y-Richtung (>0, wenn dieses Dreieck unterhalb des anderen Grafik-Objekts liegt)
*/
public int berechneAbstandY( Raum grafikObjekt )
{
return (int)( this.M_y - grafikObjekt.mittelPunkt().y() );
}
/**
* liefert den Sinus des Drehwinkels der Grafik.
*
* @return Sinus des aktuellen Drehwinkels
*/
public float sin_Drehwinkel()
{
return (float)( Math.sin( this.gibDrehung() * Math.PI / 180 ) );
}
/**
* liefert den Cosinus des Drehwinkels der Grafik
*
* @return Cosinus des aktuellen Drehwinkels
*/
public float cos_Drehwinkel()
{
return (float)( Math.cos( this.gibDrehung() * Math.PI / 180 ) );
}
/**
* Dreht die Grafik um einen Winkel
*
* @param winkelAenderung +: mathematisch positiver Drehsinn (gegen den Uhrzeigersinn)
* -: mathematisch negativer Drehsinn (im Uhrzeigersinn)
*/
public void drehenUm( float winkelAenderung )
{
this.drehenRelativ( -winkelAenderung );
}
/**
* Setzt den Drehwinkel auf eine absoluten neuen Wert
*
* @param neuerDrehwinkel der neue Drehwinkel
* +: mathematisch positiver Drehsinn (gegen den Uhrzeigersinn)
* -: mathematisch negativer Drehsinn (im Uhrzeigersinn)
*/
public void setzeDrehwinkel( float neuerDrehwinkel )
{
this.drehenAbsolut( -neuerDrehwinkel );
}
/**
* Nennt den Winkel, um den die Grafik gedreht wurde
*
* @return der Winkel, um den die Grafik gedreht wurde
* 0: wenn nicht gedreht
* +: wenn mathematisch positiver Drehsinn (gegen den Uhrzeigersinn)
* -: wenn mathematisch negativer Drehsinn (im Uhrzeigersinn)
*/
public float nenneWinkel()
{
return (float)( -this.gibDrehung() );
}
}