/*
 This is a proprietary part of DataMelt package.
 License: the Creative Commons Attribution-Share Alike License; either version 3.0 of the License, 
 or any later version.
 http://creativecommons.org/licenses/by-sa/3.0/
 

Redistributions of the source code, or parts of the source codes, must retain the copyright notice, this list of conditions and the following disclaimer (all at the top of each source code) and requires the written permission from DataMelt.

Redistribution in binary form of all or parts of a class must reproduce the copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution and requires the written permission of ScaVis

Details about license agreement or commercial use are: http://jwork.org/scavis/ */ package jhpro.nnet; import java.awt.Point; public class ThreeD { public ThreeD(int i, int j, int k, int l, int i1) { xSize = k; ySize = l; zSize = i1; midX = i / 2; midY = j / 2; computeSinCosTables(); setEyePosition(0, 0, -500); setAngles(0, 0, 0); } void computeSinCosTables() { sinTable = new int[512]; cosTable = new int[512]; for(int i = 0; i < 512; i++) { double d = ((double)i * 3.1415926535897931D) / 256D; sinTable[i] = (int)Math.round(Math.sin(d) * 512D + 0.5D); cosTable[i] = (int)Math.round(Math.cos(d) * 512D + 0.5D); } } public void setEyePosition(int i, int j, int k) { eyeX = i; eyeY = j; eyeZ = k; } public void setAngles(int i, int j, int k) { xAngle = i < 0 || i > 511 ? 0 : i; yAngle = j < 0 || j > 511 ? 0 : j; zAngle = k < 0 || k > 511 ? 0 : k; } public void setAngleSteps(int i, int j, int k) { xAngleStep = Math.abs(i) >= 51 ? 0 : i; yAngleStep = Math.abs(j) >= 51 ? 0 : j; zAngleStep = Math.abs(k) >= 51 ? 0 : k; } public int changeAngle(int i, int j) { if(j >= 0) i = i > 511 - j ? (511 + j) - i : i + j; else i = i < Math.abs(j) ? 511 + j : i + j; return i; } public void changeAngles() { xAngle = changeAngle(xAngle, xAngleStep); yAngle = changeAngle(yAngle, yAngleStep); zAngle = changeAngle(zAngle, zAngleStep); } public Point[] rotate3Dto2D(Point3D apoint3d[]) { Point apoint[] = new Point[apoint3d.length]; int k1 = sinTable[xAngle]; int l1 = sinTable[yAngle]; int i2 = sinTable[zAngle]; int j2 = cosTable[xAngle]; int k2 = cosTable[yAngle]; int l2 = cosTable[zAngle]; for(int i3 = 0; i3 < apoint3d.length; i3++) { int l = apoint3d[i3].x; int i1 = apoint3d[i3].y; int j1 = apoint3d[i3].z; int i = l * k2 + j1 * l1 >> 9; int k = j1 * k2 - l * l1 >> 9; l = i; j1 = k; int j = i1 * l2 - j1 * i2 >> 9; k = i1 * i2 + j1 * l2 >> 9; i1 = j; j1 = k; i = l * j2 - i1 * k1 >> 9; j = l * k1 + i1 * j2 >> 9; l = i; i1 = j; i = midX; j = midY; if(eyeZ != j1) { double d = (double)eyeZ / ((double)eyeZ - (double)j1); if(l != 0) i = (int)((double)i + d * (double)l); if(i1 != 0) j = (int)((double)j + d * (double)i1); } apoint[i3] = new Point(i, j); } return apoint; } public Point3D[] rotate3DPoint(Point3D apoint3d[]) { Point3D apoint3d1[] = new Point3D[apoint3d.length]; for(int k1 = 0; k1 < apoint3d.length; k1++) { int l = apoint3d[k1].x; int i1 = apoint3d[k1].y; int j1 = apoint3d[k1].z; int i = l * cosTable[yAngle] + j1 * sinTable[yAngle] >> 9; int k = j1 * cosTable[yAngle] - l * sinTable[yAngle] >> 9; l = i; j1 = k; int j = i1 * cosTable[zAngle] - j1 * sinTable[zAngle] >> 9; k = i1 * sinTable[zAngle] + j1 * cosTable[zAngle] >> 9; i1 = j; j1 = k; i = l * cosTable[xAngle] - i1 * sinTable[xAngle] >> 9; j = l * sinTable[xAngle] + i1 * cosTable[xAngle] >> 9; l = i; i1 = j; apoint3d1[k1] = new Point3D(l, i1, j1); } return apoint3d1; } public Point[] setPerspective(Point3D apoint3d[]) { Point apoint[] = new Point[apoint3d.length]; int i = midX; int k = midY; for(int i1 = 0; i1 < apoint3d.length; i1++) { int j = midX; int l = midY; if(eyeZ != apoint3d[i1].z) { double d = (double)eyeZ / ((double)eyeZ - (double)apoint3d[i1].z); if(apoint3d[i1].x != 0) j = (int)((double)j + d * (double)apoint3d[i1].x); if(apoint3d[i1].y != 0) l = (int)((double)l + d * (double)apoint3d[i1].y); } apoint[i1] = new Point(j, l); } return apoint; } public Point3D rotate3DPoint(Point3D point3d) { int l = point3d.x; int i1 = point3d.y; int j1 = point3d.z; int i = l * cosTable[yAngle] + j1 * sinTable[yAngle] >> 9; int k = j1 * cosTable[yAngle] - l * sinTable[yAngle] >> 9; l = i; j1 = k; int j = i1 * cosTable[zAngle] - j1 * sinTable[zAngle] >> 9; k = i1 * sinTable[zAngle] + j1 * cosTable[zAngle] >> 9; i1 = j; j1 = k; i = l * cosTable[xAngle] - i1 * sinTable[xAngle] >> 9; j = l * sinTable[xAngle] + i1 * cosTable[xAngle] >> 9; l = i; i1 = j; return new Point3D(l, i1, j1); } public Point setPerspective(Point3D point3d) { int i = midX; int j = midY; if(eyeZ != point3d.z) { double d = (double)eyeZ / ((double)eyeZ - (double)point3d.z); if(point3d.x != 0) i = (int)((double)i + d * (double)point3d.x); if(point3d.y != 0) j = (int)((double)j + d * (double)point3d.y); } return new Point(i, j); } final int tableSize = 512; final int angleShift = 9; final int maxAngle = 511; int sinTable[]; int cosTable[]; int xSize; int ySize; int zSize; int midX; int midY; int eyeX; int eyeY; int eyeZ; int xAngle; int yAngle; int zAngle; int xAngleStep; int yAngleStep; int zAngleStep; }

Ads help maintain this website.