haftendorn.uni-lueneburg.de/mathe-lehramt/geo/geo.htm |
![]() Ein Programm von |
|
| Mathematisch entscheidend: Die Ecken müssen als Orts-Vektoren vom Mittelpunkt aus beschrieben werden. |
Dodekaeder.java
import java.awt.*;
import java.applet.*;
public class Dodekaeder extends Applet {
// 20 Eckpunkte 1-20
// mit je 3 Koordinaten 1,2,3
double p[][] = new double[21][4];
int x=1, y=2, z=3;
public void init() {
setBackground(new Color(255,255,255));
// Halbe Seitenlänge des eingeschriebenen Würfels
double s = 100;
// Höhe einer Dodekaeder-Kante über dem Würfel
double h = s*0.5*(Math.sqrt(5)-1);
// 20 Eckpunkte im lokalen Dodekaeder-Koordinatensystem
// Nullpunkt = Mittelpunkt
p[1][x] = 0; p[1][y] = -h; p[1][z] = -(s+h);
p[2][x] = 0; p[2][y] = h; p[2][z] = -(s+h);
p[3][x] = s; p[3][y] = -s; p[3][z] = -s;
p[4][x] = s; p[4][y] = s; p[4][z] = -s;
p[5][x] = -s; p[5][y] = s; p[5][z] = -s;
p[6][x] = -s; p[6][y] = -s; p[6][z] = -s;
p[7][x] = s+h; p[7][y] = 0; p[7][z] = -h;
p[8][x] = -(s+h); p[8][y] = 0; p[8][z] = -h;
p[9][x] = h; p[9][y] = h+s; p[9][z] = 0;
p[10][x] = -h; p[10][y] = h+s; p[10][z] = 0;
p[11][x] = -h; p[11][y] = -(s+h); p[11][z] = 0;
p[12][x] = h; p[12][y] = -(s+h); p[12][z] = 0;
p[13][x] = s+h; p[13][y] = 0; p[13][z] = h;
p[14][x] = -(s+h); p[14][y] = 0; p[14][z] = h;
p[15][x] = s; p[15][y] = -s; p[15][z] = s;
p[16][x] = s; p[16][y] = s; p[16][z] = s;
p[17][x] = -s; p[17][y] = s; p[17][z] = s;
p[18][x] = -s; p[18][y] = -s; p[18][z] = s;
p[19][x] = 0; p[19][y] = -h; p[19][z] = s+h;
p[20][x] = 0; p[20][y] = h; p[20][z] = s+h;
}
// Rotationswinkel in rad
double ax = 0.01;
double ay = 0.0075;
double az = 0.005;
Image buffer;
Graphics2D gBuffer;
int w = 200; // -> Weltkoordinaten
double px, py, pz;
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);
// Dodekaeder-Eckpunkte verbinden
drawLine(1,2); drawLine(2,4); drawLine(4,7);
drawLine(7,3); drawLine(3,1); drawLine(2,5);
drawLine(5,8); drawLine(8,6); drawLine(6,1);
drawLine(4,9); drawLine(9,10); drawLine(10,5);
drawLine(6,11); drawLine(11,12); drawLine(12,3);
drawLine(7,13); drawLine(8,14); drawLine(9,16);
drawLine(10,17); drawLine(11,18); drawLine(12,15);
drawLine(13,16); drawLine(16,20); drawLine(20,19);
drawLine(19,15); drawLine(15,13); drawLine(20,17);
drawLine(17,14); drawLine(14,18); drawLine(18,19);
g.drawImage (buffer,0,0,this);
// Verzögerung
try {Thread.sleep(20);}
catch (InterruptedException e) {}
for (int i=1;i<21;i++) {
px = p[i][x];
py = p[i][y];
pz = p[i][z];
// Rotation um x-Achse
p[i][y] = py*Math.cos(ax)-pz*Math.sin(ax);
p[i][z] = py*Math.sin(ax)+pz*Math.cos(ax);
py = p[i][y];
pz = p[i][z];
// Rotation um y-Achse
p[i][x] = px*Math.cos(ay)+pz*Math.sin(ay);
p[i][z] =-px*Math.sin(ay)+pz*Math.cos(ay);
px = p[i][x];
// Rotation um z-Achse
p[i][x] = px*Math.cos(az)-py*Math.sin(az);
p[i][y] = py*Math.cos(az)+px*Math.sin(az);
}
repaint();
}
public void update(Graphics g) {paint(g);}
public void drawLine(int i, int j) {
gBuffer.drawLine(
(int)(p[i][x])+w,(int)(p[i][y])+w,
(int)(p[j][x])+w,(int)(p[j][y])+w);
}
}
Schema der Berechnung des Kreuzprodukts der Fläche. Dabei sind p und q die eine Fläche aufspannenden Vektoren.
[ p1 ] [ q1 ] [ p2*q3 - p3*q2 ] [ p2 ] x [ q2 ] = [ p3*q1 - p1*q3 ] [ p3 ] [ q3 ] [ p1*q2 - p2*q1 ]Download ©Albert Kluge www.jjam.de
[www.doerte-haftendorn.de] [haftendorn.uni-lueneburg.de/mathe-lehramt] |