用java3D,怎样画出一个一直函数的图形呢??急急急!!! 用QuardArray,你要画得应该是个面吧 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 给个例子好吗??呵呵……没学过JAVA3D啊!呵呵……谢谢!急急急!!! // 生成函数曲面import com.sun.j3d.utils.geometry.*;import javax.media.j3d.*;import javax.vecmath.*;public class Surface extends Shape3D { Surface() { this.setGeometry(createGeometry()); this.setAppearance(createAppearance()); } // 具体函数,更改这一函数即可显示不同函数的图像 float calz(float x,float y) { return (float)(-1f*Math.sqrt(2-x*x-y*y)); } Geometry createGeometry() { int MAXX=200; int MAXY=200; QuadArray surf = new QuadArray(MAXX*MAXY*4, GeometryArray.COORDINATES | GeometryArray.NORMALS); for(int i=0;i<MAXX;i++) { for(int j=0;j<MAXY*4;j+=4) { int jb=j/4; float x=(i-100f)/200.0f; float y=(jb-100f)/200.0f; // 计算一个平面上的4个点 Point3f A=new Point3f(x,y,calz(x,y)); Point3f B=new Point3f(x+0.005f,y,calz(x+0.005f,y)); Point3f C=new Point3f(x+0.005f,y+0.005f,calz(x+0.005f,y+0.005f)); Point3f D=new Point3f(x,y+0.005f,calz(x,y+0.005f)); // 计算四个点的法向量 Vector3f a = new Vector3f(A.x - B.x, A.y - B.y, A.z - B.z); Vector3f b = new Vector3f(C.x - B.x, C.y - B.y, C.z - B.z); Vector3f n = new Vector3f(); n.cross(b, a); n.normalize(); // 设置点坐标 surf.setCoordinate(i*MAXY*4+j, A); surf.setCoordinate(i*MAXY*4+j+1, B); surf.setCoordinate(i*MAXY*4+j+2, C); surf.setCoordinate(i*MAXY*4+j+3, D); // 设置点法向量 surf.setNormal(i*MAXY*4+j, n); surf.setNormal(i*MAXY*4+j+1, n); surf.setNormal(i*MAXY*4+j+2, n); surf.setNormal(i*MAXY*4+j+3, n); } } return surf; } Appearance createAppearance() { // 指定外观,这样才有明暗效果 Appearance appear = new Appearance(); Material material = new Material(); Color3f white = new Color3f(1.0f, 1.0f, 1.0f); Color3f red = new Color3f(1.0f, 0.0f, 0.0f); material.setDiffuseColor(red); material.setSpecularColor(white); material.setShininess(2.0f); appear.setMaterial(material); return appear; }}// end of Surface.java// 生成函数曲面import com.sun.j3d.utils.geometry.*;import javax.media.j3d.*;import javax.vecmath.*;public class Surface extends Shape3D { Surface() { this.setGeometry(createGeometry()); this.setAppearance(createAppearance()); } // 具体函数,更改这一函数即可显示不同函数的图像 float calz(float x,float y) { return (float)(-1f*Math.sqrt(2-x*x-y*y)); } Geometry createGeometry() { int MAXX=200; int MAXY=200; QuadArray surf = new QuadArray(MAXX*MAXY*4, GeometryArray.COORDINATES | GeometryArray.NORMALS); for(int i=0;i<MAXX;i++) { for(int j=0;j<MAXY*4;j+=4) { int jb=j/4; float x=(i-100f)/200.0f; float y=(jb-100f)/200.0f; // 计算一个平面上的4个点 Point3f A=new Point3f(x,y,calz(x,y)); Point3f B=new Point3f(x+0.005f,y,calz(x+0.005f,y)); Point3f C=new Point3f(x+0.005f,y+0.005f,calz(x+0.005f,y+0.005f)); Point3f D=new Point3f(x,y+0.005f,calz(x,y+0.005f)); // 计算四个点的法向量 Vector3f a = new Vector3f(A.x - B.x, A.y - B.y, A.z - B.z); Vector3f b = new Vector3f(C.x - B.x, C.y - B.y, C.z - B.z); Vector3f n = new Vector3f(); n.cross(b, a); n.normalize(); // 设置点坐标 surf.setCoordinate(i*MAXY*4+j, A); surf.setCoordinate(i*MAXY*4+j+1, B); surf.setCoordinate(i*MAXY*4+j+2, C); surf.setCoordinate(i*MAXY*4+j+3, D); // 设置点法向量 surf.setNormal(i*MAXY*4+j, n); surf.setNormal(i*MAXY*4+j+1, n); surf.setNormal(i*MAXY*4+j+2, n); surf.setNormal(i*MAXY*4+j+3, n); } } return surf; } Appearance createAppearance() { // 指定外观,这样才有明暗效果 Appearance appear = new Appearance(); Material material = new Material(); Color3f white = new Color3f(1.0f, 1.0f, 1.0f); Color3f red = new Color3f(1.0f, 0.0f, 0.0f); material.setDiffuseColor(red); material.setSpecularColor(white); material.setShininess(2.0f); appear.setMaterial(material); return appear; }}// end of Surface.java oracle数据库插入数据id的小问题,在线等 this 和 super的区别????? 这个错误谁知道,没有头绪啊!!!! map与list socket问题 问一个基础:怎样为自己开发的代码加密??? JBUILDER中使用SWING时自定义异常问题 网上赚钱的好方法 一个打包的问题~~ 数组的传递问题 请教,急!! 从ie中无法正确load applet。
呵呵……
谢谢!急急急!!!
import com.sun.j3d.utils.geometry.*;
import javax.media.j3d.*;
import javax.vecmath.*;
public class Surface extends Shape3D
{
Surface()
{
this.setGeometry(createGeometry());
this.setAppearance(createAppearance());
}
// 具体函数,更改这一函数即可显示不同函数的图像
float calz(float x,float y)
{
return (float)(-1f*Math.sqrt(2-x*x-y*y));
}
Geometry createGeometry()
{
int MAXX=200;
int MAXY=200;
QuadArray surf = new QuadArray(
MAXX*MAXY*4, GeometryArray.COORDINATES
| GeometryArray.NORMALS);
for(int i=0;i<MAXX;i++)
{
for(int j=0;j<MAXY*4;j+=4)
{
int jb=j/4;
float x=(i-100f)/200.0f;
float y=(jb-100f)/200.0f;
// 计算一个平面上的4个点
Point3f A=new Point3f(x,y,calz(x,y));
Point3f B=
new Point3f(x+0.005f,y,calz(x+0.005f,y));
Point3f C=new Point3f(x+0.005f,
y+0.005f,calz(x+0.005f,y+0.005f));
Point3f D=new Point3f(x,y+0.005f,
calz(x,y+0.005f));
// 计算四个点的法向量
Vector3f a = new Vector3f(
A.x - B.x, A.y - B.y, A.z - B.z);
Vector3f b = new Vector3f(
C.x - B.x, C.y - B.y, C.z - B.z);
Vector3f n = new Vector3f();
n.cross(b, a);
n.normalize();
// 设置点坐标
surf.setCoordinate(i*MAXY*4+j, A);
surf.setCoordinate(i*MAXY*4+j+1, B);
surf.setCoordinate(i*MAXY*4+j+2, C);
surf.setCoordinate(i*MAXY*4+j+3, D);
// 设置点法向量
surf.setNormal(i*MAXY*4+j, n);
surf.setNormal(i*MAXY*4+j+1, n);
surf.setNormal(i*MAXY*4+j+2, n);
surf.setNormal(i*MAXY*4+j+3, n);
}
}
return surf;
}
Appearance createAppearance()
{
// 指定外观,这样才有明暗效果
Appearance appear = new Appearance();
Material material = new Material();
Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
Color3f red = new Color3f(1.0f, 0.0f, 0.0f);
material.setDiffuseColor(red);
material.setSpecularColor(white);
material.setShininess(2.0f);
appear.setMaterial(material);
return appear;
}
}// end of Surface.java
// 生成函数曲面
import com.sun.j3d.utils.geometry.*;
import javax.media.j3d.*;
import javax.vecmath.*;
public class Surface extends Shape3D
{
Surface()
{
this.setGeometry(createGeometry());
this.setAppearance(createAppearance());
}
// 具体函数,更改这一函数即可显示不同函数的图像
float calz(float x,float y)
{
return (float)(-1f*Math.sqrt(2-x*x-y*y));
}
Geometry createGeometry()
{
int MAXX=200;
int MAXY=200;
QuadArray surf = new QuadArray(
MAXX*MAXY*4, GeometryArray.COORDINATES
| GeometryArray.NORMALS);
for(int i=0;i<MAXX;i++)
{
for(int j=0;j<MAXY*4;j+=4)
{
int jb=j/4;
float x=(i-100f)/200.0f;
float y=(jb-100f)/200.0f;
// 计算一个平面上的4个点
Point3f A=new Point3f(x,y,calz(x,y));
Point3f B=
new Point3f(x+0.005f,y,calz(x+0.005f,y));
Point3f C=new Point3f(x+0.005f,
y+0.005f,calz(x+0.005f,y+0.005f));
Point3f D=new Point3f(x,y+0.005f,
calz(x,y+0.005f));
// 计算四个点的法向量
Vector3f a = new Vector3f(
A.x - B.x, A.y - B.y, A.z - B.z);
Vector3f b = new Vector3f(
C.x - B.x, C.y - B.y, C.z - B.z);
Vector3f n = new Vector3f();
n.cross(b, a);
n.normalize();
// 设置点坐标
surf.setCoordinate(i*MAXY*4+j, A);
surf.setCoordinate(i*MAXY*4+j+1, B);
surf.setCoordinate(i*MAXY*4+j+2, C);
surf.setCoordinate(i*MAXY*4+j+3, D);
// 设置点法向量
surf.setNormal(i*MAXY*4+j, n);
surf.setNormal(i*MAXY*4+j+1, n);
surf.setNormal(i*MAXY*4+j+2, n);
surf.setNormal(i*MAXY*4+j+3, n);
}
}
return surf;
}
Appearance createAppearance()
{
// 指定外观,这样才有明暗效果
Appearance appear = new Appearance();
Material material = new Material();
Color3f white = new Color3f(1.0f, 1.0f, 1.0f);
Color3f red = new Color3f(1.0f, 0.0f, 0.0f);
material.setDiffuseColor(red);
material.setSpecularColor(white);
material.setShininess(2.0f);
appear.setMaterial(material);
return appear;
}
}// end of Surface.java