package HyperCube; //------------------------------------------------------------------------- // Point4D //------------------------------------------------------------------------- class Point extends Object { int x; int y;
Point(int x, int y) { this.x=x; this.y=y;}
Point(Point P) { this.x=P.x; this.y=P.y;}
Point() { this.x=0; this.y=0;}} //------------------------------------------------------------------------- // Point4D //------------------------------------------------------------------------- class Point4D extends Point { int z; int t;
Point4D(int x, int y, int z, int t) { this.x=x; this.y=y; this.z=z; this.t=t;}
//------------------------------------------------------------------------- // Point3D //------------------------------------------------------------------------- publicclass Cube { finalint dim=16*8; finaldouble PI=Math.PI; finalint base=28; // title height
Point DisplayWidth=new Point(0,0); int SideLength=0; double anglexy = PI / 3; double angleyz = PI / 3; double anglezt = PI / 3; double angletx = PI / 3; double anglety = PI / 3;
Point center=new Point(0,0); // center of pane
Point4D transform=new Point4D(); //set center of cube to origin
Point4D from[]=null;
Point4D to[]=null;
Point fromp[]=null;
Point top[]=null; int count=0;
//------------------------------------------------------------------------- // constructior Point3D //------------------------------------------------------------------------- public Cube(int w, int h) {
count=0;
from = new Point4D[dim];
to = new Point4D[dim];
fromp = new Point[dim];
top = new Point[dim];
DisplayWidth.x=w;
DisplayWidth.y=h;
center.x = w / 2;
center.y = base+(h-base) / 2;
SideLength=Math.min(2*center.x/3,2*center.y/3);
transform.x=SideLength / 2;
transform.y=SideLength / 2;
transform.z=SideLength / 2;
transform.t=SideLength / 2;} //------------------------------------------------------------------------- // add Point4D //------------------------------------------------------------------------- publicvoid add(Point4D f, Point4D t) {
Point mean=new Point(0,0);
count++; if (count > dim) System.out.println("Exception at cube, count ="+count); else {
from[count]=new Point4D(f);
to[count]=new Point4D(t);
Point4D PA = new Point4D(f.x * SideLength-transform.x, f.y * SideLength-transform.y,
f.z * SideLength-transform.z, f.t * SideLength-transform.t);
Point4D PE = new Point4D(t.x * SideLength-transform.x, t.y * SideLength-transform.y,
t.z * SideLength-transform.z, t.t * SideLength-transform.t);
PA = rotatexy(PA);
PE = rotatexy(PE);
PA = rotateyz(PA);
PE = rotateyz(PE);
PA = rotatetx(PA);
PE = rotatetx(PE);
PA = rotatety(PA);
PE = rotatety(PE);
fromp[count]=new Point(PA);
top[count]=new Point(PE); if (Math.abs(fromp[count].x)>mean.x) mean.x=Math.abs(fromp[count].x); if (Math.abs(fromp[count].y)>mean.y) mean.y=Math.abs(fromp[count].y); if (Math.abs(top[count].x)>mean.x) mean.x=Math.abs(top[count].x); if (Math.abs(top[count].y)>mean.y) mean.y=Math.abs(top[count].y);}} //------------------------------------------------------------------------- // rotate xy //------------------------------------------------------------------------- public Point4D rotatexy(Point4D P) { double cosa = Math.cos(anglexy); double sina = Math.sin(anglexy);
Point4D res = new Point4D();
res.x = (int) (float) (cosa * P.x - sina * P.y);
res.y = (int) (float) (sina * P.x + cosa * P.y);
res.z = P.z;
res.t = P.t; return res;} //------------------------------------------------------------------------- // rotate yz //------------------------------------------------------------------------- public Point4D rotateyz(Point4D P) { double cosa = Math.cos(angleyz); double sina = Math.sin(angleyz);
Point4D res = new Point4D();
res.x = P.x;
res.y = (int) (float) (cosa * P.y - sina * P.z);
res.z = (int) (float) (sina * P.y + cosa * P.z);
res.t = P.t; return res; } //------------------------------------------------------------------------- // rotate tx //------------------------------------------------------------------------- public Point4D rotatetx(Point4D P) { double cosa = Math.cos(angletx); double sina = Math.sin(angletx);
Point4D res = new Point4D();
res.y = P.y;
res.z = P.z;
res.t = (int) (float) (cosa * P.t - sina * P.x);
res.x = (int) (float) (sina * P.t + cosa * P.x); return res;} //------------------------------------------------------------------------- // rotate ty //------------------------------------------------------------------------- public Point4D rotatety(Point4D P) { double cosa = Math.cos(anglety); double sina = Math.sin(anglety);
Point4D res = new Point4D();
res.x = P.x;
res.z = P.z;
res.t = (int) (float) (cosa * P.t - sina * P.y);
res.y = (int) (float) (sina * P.t + cosa * P.y); return res;}}
¤ Dauer der Verarbeitung: 0.10 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.