haftendorn.uni-lueneburg.de/mathe-lehramt/geo/geo.htm |
![]() Weiterführung eines Programms von |
|
| Mathematisch entscheidend: Die Ecken müssen als Orts-Vektoren vom Mittelpunkt aus beschrieben werden. |
Tetraeder.java
import java.awt.*;
import java.applet.*;
public class Tetraeder extends Applet {
// 4 Eckpunkte 1-4
// mit je 3 Koordinaten 1,2,3
double p[][] = new double[5][4];
int x=1, y=2, z=3;
public void init() {
setBackground(new Color(255,255,255));
// Tetraeder-Höhe
double th = Math.sqrt(2/3.0)*300;
// Höhe des Tetraeder-Mittelpunkts
double tm = Math.sqrt(1/24.0)*300;
// Strecke Ecke-Mittelpunkt eines Dreiecks
double em = Math.sqrt(1/3.0)*300;
// Strecke Seite-Mittelpunkt eines Dreiecks
double sm = Math.sqrt(1/12.0)*300;
// 4 Eckpunkte im lokalen Tetraeder-Koordinatensystem
// Nullpunkt = Mittelpunkt
p[1][x] = -150; p[1][y] = -tm; p[1][z] = +sm;
p[2][x] = 0; p[2][y] = -tm; p[2][z] = -em;
p[3][x] = +150; p[3][y] = -tm; p[3][z] = +sm;
p[4][x] = 0; p[4][y] = +th-tm; p[4][z] = 0;
// 4
// / | \
// / | \
// / | \
// 1 - -|- - 3
// ` 2 ´
// y-Werte spiegeln
for (int i=1;i<5;i++) {
p[i][y] = -p[i][y];
}
}
// Rotationswinkel in rad
double angle_x = 0.01;
double angle_y = 0.007;
double angle_z = 0.001;
Image buffer;
Graphics2D gBuffer;
public void paint(Graphics g) {
// Double-Buffering
if (buffer==null) {
buffer=createImage(this.getSize().width, this.getSize().height);
gBuffer=(Graphics2D)buffer.getGraphics();
}
gBuffer.clearRect(0,0,this.getSize().width, this.getSize().height);
// Antialiasing
gBuffer.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
gBuffer.setColor(new Color(70,0,0));
// Lokale Tetraeder-Koordinaten
// in Welt-Koordinaten: +200
gBuffer.drawLine((int)(p[1][x])+200,(int)(p[1][y])+200,
(int)(p[2][x])+200,(int)(p[2][y])+200);
gBuffer.drawLine((int)(p[2][x])+200,(int)(p[2][y])+200,
(int)(p[3][x])+200,(int)(p[3][y])+200);
gBuffer.drawLine((int)(p[3][x])+200,(int)(p[3][y])+200,
(int)(p[1][x])+200,(int)(p[1][y])+200);
gBuffer.drawLine((int)(p[1][x])+200,(int)(p[1][y])+200,
(int)(p[4][x])+200,(int)(p[4][y])+200);
gBuffer.drawLine((int)(p[2][x])+200,(int)(p[2][y])+200,
(int)(p[4][x])+200,(int)(p[4][y])+200);
gBuffer.drawLine((int)(p[3][x])+200,(int)(p[3][y])+200,
(int)(p[4][x])+200,(int)(p[4][y])+200);
g.drawImage (buffer, 0, 0, this);
// Verzögerung
try {Thread.sleep(10);}
catch (InterruptedException e) {}
double px, py, pz;
for (int i=1;i<5;i++) {
px = p[i][x];
py = p[i][y];
pz = p[i][z];
// Rotation um x-Achse
p[i][y] = py*Math.cos(angle_x)-pz*Math.sin(angle_x);
p[i][z] = py*Math.sin(angle_x)+pz*Math.cos(angle_x);
py = p[i][y];
pz = p[i][z];
// Rotation um y-Achse
p[i][x] = px*Math.cos(angle_y)+pz*Math.sin(angle_y);
p[i][z] =-px*Math.sin(angle_y)+pz*Math.cos(angle_y);
px = p[i][x];
// Rotation um z-Achse
p[i][x] = px*Math.cos(angle_z)-py*Math.sin(angle_z);
p[i][y] = py*Math.cos(angle_z)+px*Math.sin(angle_z);
}
repaint();
}
public void update(Graphics g) {paint(g);}
}
Download Tetraeder.zip (Applet und Code, ca. 3 kb)
© 2001-2004 Albert Kluge - Alle Rechte vorbehalten
[www.doerte-haftendorn.de] [haftendorn.uni-lueneburg.de/mathe-lehramt] |