变换矩阵为:
变换矩阵为:
变换矩阵为:
将物体向正面投影,即令 y=0 ,变换矩阵为:
将物体向水平面(H面)投影,即令 z=0 ,然后将得到的投影图绕 x 轴顺时针旋转 90。 ,使其与 V 面共面,再沿负 z 方向平移一段距离,以使 H 面投影与 V 面投影之间保持一段距离。使变换矩阵为:
将物体向侧面作正投影,即令 x=0 ,然后绕 z 轴逆时针旋转 90。 ,使其与 V 面共面,为保证与正面投影有一段距离,再沿负 x 方向平移一段距离,这样即得到侧视图。
变换矩阵为:
Demo
Processing3.0
class box2d{
ArrayList<PVector> points;
int X,Y,Z;
box2d(int x,int y,int z){
X=x;
Y=y;
Z=z;
points=new ArrayList<PVector>();
points.add(new PVector(0,0,0));
points.add(new PVector(x,0,0));
points.add(new PVector(0,y,0));
points.add(new PVector(0,0,z));
points.add(new PVector(x,y,0));
points.add(new PVector(x,0,z));
points.add(new PVector(0,y,z));
points.add(new PVector(x,y,z));
for(int i=1;i<x;i++){
points.add(new PVector(i,0,0));
points.add(new PVector(i,0,z));
points.add(new PVector(i,y,0));
points.add(new PVector(i,y,z));
}
for(int i=1;i<y;i++){
points.add(new PVector(0,i,0));
points.add(new PVector(0,i,z));
points.add(new PVector(x,i,0));
points.add(new PVector(x,i,z));
}
for(int i=1;i<z;i++){
points.add(new PVector(0,0,i));
points.add(new PVector(x,0,i));
points.add(new PVector(0,y,i));
points.add(new PVector(x,y,i));
}
for(int i=0;i<points.size();i++){
PVector t=points.get(i);
println(t.x+" "+t.y+" "+t.z);
}
}
void TH(PVector t){
float x,y;
x=t.x;
y=t.y;
point(int(x),int(-y+300));
}
void TV(PVector t){
float x,z;
x=t.x;
z=t.z;
point(int(x),int(z));
}
void TW(PVector t){
float y,z;
y=t.y;
z=t.z;
point(int(-y+300),int(z));
}
void show(){
translate(100,100);
fill(0, 102, 153, 204);
text("V view",-20,-20);
text("H view",-20,280);
text("W view",280,-20);
textSize(16);
text("use x,y,z key to ratate, use +,- to control the speed.\nOther key will interrupt the ratate, and esc to exit",100,300);
for(int i=0;i<points.size();i++){
TV(points.get(i));
TH(points.get(i));
TW(points.get(i));
}
}
PVector rx(PVector t,float a){
return new PVector(t.x,t.y*cos(a)-t.z*sin(a),t.y*sin(a)+t.z*cos(a));
}
PVector ry(PVector t,float a){
return new PVector(t.x*cos(a)+t.z*sin(a),t.y,-t.x*sin(a)+t.z*cos(a));
}
PVector rz(PVector t,float a){
return new PVector(t.x*cos(a)-t.y*sin(a),t.x*sin(a)+t.y*cos(a),t.z);
}
void rotate(char f,float r){
int n=points.size();
for(int i=0;i<n;i++){
switch (f){
case 'x':
points.add(rx(points.remove(0),r));
break;
case 'y':
points.add(ry(points.remove(0),r));
break;
case 'z':
points.add(rz(points.remove(0),r));
break;
}
}
}
}
box2d bx;
void setup(){
size(700,500);
background(255);
bx = new box2d(50,50,50);
}
char d;
float r=0.3;
void keyPressed(){
switch (key){
case '+':
r+=0.1;
break;
case '-':
r-=0.1;
break;
case ESC:
exit();
default:
d=key;
}
if(r>1)
r=1;
if(r<0)
r=0;
println("R: "+r);
}
void draw(){
background(255);
bx.rotate(d,r);
bx.show();
}