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. |
Ikosaeder.java
import java.awt.*;
import java.applet.*;
public class Ikosaeder extends Applet {
// 12 Eckpunkte 1-12
// mit je 3 Koordinaten 1,2,3
double p[][] = new double[13][4];
int x=1, y=2, z=3;
public void init() {
setBackground(new Color(255,255,255));
// Halbe Seitenlänge des umschriebenen Würfels
double s = 150;
// Entfernung Ikosaeder-Ecke Würfel-Flächen-Mittelunkt
double h = s*0.5*(Math.sqrt(5)-1);
// 12 Eckpunkte im lokalen Ikosaeder-Koordinatensystem
// Nullpunkt = Mittelpunkt
p[1][x] = -h; p[1][y] = -s; p[1][z] = 0;
p[2][x] = h; p[2][y] = -s; p[2][z] = 0;
p[3][x] = 0; p[3][y] = -h; p[3][z] = s;
p[4][x] = 0; p[4][y] = -h; p[4][z] = -s;
p[5][x] = s; p[5][y] = 0; p[5][z] = h;
p[6][x] = s; p[6][y] = 0; p[6][z] = -h;
p[7][x] = -s; p[7][y] = 0; p[7][z] = -h;
p[8][x] = -s; p[8][y] = 0; p[8][z] = h;
p[9][x] = 0; p[9][y] = h; p[9][z] = s;
p[10][x] = 0; p[10][y] = h; p[10][z] = -s;
p[11][x] = -h; p[11][y] = s; p[11][z] = 0;
p[12][x] = h; p[12][y] = s; p[12][z] = 0;
}
// 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);
// Ikosaeder-Eckpunkte verbinden
drawLine(1,2);
drawLine(2,3);
drawLine(3,1);
drawLine(2,4);
drawLine(4,1);
drawLine(2,5);
drawLine(5,6);
drawLine(6,2);
drawLine(1,7);
drawLine(7,8);
drawLine(8,1);
drawLine(3,9);
drawLine(3,5);
drawLine(3,8);
drawLine(4,6);
drawLine(4,7);
drawLine(9,8);
drawLine(9,5);
drawLine(4,10);
drawLine(10,7);
drawLine(7,11);
drawLine(8,11);
drawLine(10,6);
drawLine(6,12);
drawLine(5,12);
drawLine(12,9);
drawLine(9,11);
drawLine(11,10);
drawLine(10,12);
drawLine(11,12);
g.drawImage (buffer,0,0,this);
// Verzögerung
try {Thread.sleep(20);}
catch (InterruptedException e) {}
for (int i=1;i<13;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] |