Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F61330456
Ex1.pde
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, May 6, 00:08
Size
1 KB
Mime Type
text/x-c++
Expires
Wed, May 8, 00:08 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
17496461
Attached To
rBAFOURPROJECT InfoVisuGit
Ex1.pde
View Options
void settings() {
size (400, 400, P2D);
}
void setup() {
}
void draw() {
My3DPoint eye = new My3DPoint(-100, -100, -5000);
My3DPoint origin = new My3DPoint(0, 0, 0); //The first vertex of your cuboid
My3DBox input3DBox = new My3DBox(origin, 100, 150, 300);
projectBox(eye, input3DBox).render();
}
My2DBox projectBox (My3DPoint eye, My3DBox box) {
My3DPoint[] threeDP=box.p;
My2DPoint[] twoDP=new My2DPoint[threeDP.length];
for (int i=0; i<threeDP.length; ++i) {
twoDP[i]=projectPoint(eye, threeDP[i]);
}
return new My2DBox(twoDP);
}
class My2DBox {
My2DPoint[] s;
My2DBox(My2DPoint[] s) {
this.s = s;
}
void render() {
for (int i=0; i<4; i++) {
line(s[i].x, s[i].y, s[(i+1)%4].x, s[(i+1)%4].y);
line(s[i].x, s[i].y, s[i+4].x, s[i+4].y);
line(s[i+4].x, s[i+4].y, s[((i+5)%4)+4].x, s[((i+5)%4)+4].y);
}
}
}
class My3DBox {
My3DPoint[] p;
My3DBox(My3DPoint origin, float dimX, float dimY, float dimZ) {
float x = origin.x;
float y = origin.y;
float z = origin.z;
this.p = new My3DPoint[]{new My3DPoint(x, y+dimY, z+dimZ),
new My3DPoint(x, y, z+dimZ),
new My3DPoint(x+dimX, y, z+dimZ),
new My3DPoint(x+dimX, y+dimY, z+dimZ),
new My3DPoint(x, y+dimY, z),
origin,
new My3DPoint(x+dimX, y, z),
new My3DPoint(x+dimX, y+dimY, z)
};
}
My3DBox(My3DPoint[] p) {
this.p = p;
}
}
My2DPoint projectPoint(My3DPoint e, My3DPoint p) {
return new My2DPoint((p.x-e.x)/(1-p.z/e.z), (p.y-e.y)/(1-p.z/e.z));
}
class My2DPoint {
float x;
float y;
My2DPoint(float x, float y) {
this.x = x;
this.y = y;
}
}
class My3DPoint {
float x;
float y;
float z;
My3DPoint(float x, float y, float z) {
this.x = x;
this.y = y;
this.z = z;
}
}
Event Timeline
Log In to Comment