// apply rotation around X and Y axis to reposition the sphere
RotX(1.5, y0, z0);
RotY(-2.5, x0, z0);
// plot only positive points
if (z0 > 0){
g.setColor(new Color(pix[i+j*w]));//pix[w*h]为图像的像素数组
int ix = (int)x0 + 150; //java可以用BufferedImage 对象的
int iy = (int)y0 + 150; //getRGB(0, 0,w , h, pix, 0, w)方法获得
g.fillOval(ix,iy,5,5);//没有找到setPoint函数用画圆代替了.
}
}
}
}
public void RotX(double angle, double y, double z)//旋转
{
double y1 = y * Math.cos(angle) - z * Math.sin(angle);
double z1 = y * Math.sin(angle) + z * Math.cos(angle);
y0 = y1;
z0 = z1;
}
public void RotY(double angle, double x, double z)
{
double x1 = x * Math.cos(angle) - z * Math.sin(angle);
double z1 = x * Math.sin(angle) + z * Math.cos(angle);
x0 = x1;
z0 = z1;
}
public void RotZ(double angle, double x, double y)
{
double x1 = x * Math.cos(angle) - y * Math.sin(angle);
double y1 = x * Math.sin(angle) + y * Math.cos(angle);
x0 = x1;
y0 = y1;
}