计算机图形学课后答案第五章
第5章 习题答案
5.1 下面有关平面几何投影的叙述中,哪些是正确的,
(1). 平面几何投影中,透视投影的投影中心到投影平面的距离是有限的。(Y) (2). 平面几何投影中,一组平行线的投影仍保持平行。(N)
(3). 平行投影与透视投影相比,视觉效果更有真实感,而且能真实地反映物体的精确集合尺寸与形状。(N) (4). 在三维空间中的平行投影变换不可能产生灭点。(Y)
5.2请写出当透视投影中心为原点,投影平面为z=3时的透视投影矩阵。
,,x300xq,,,,,,,,,,yy,030,,。 xx, /qyy, /q,,qpqpq,,,,,,,,,,qz001,,,,,,,,
5.3求端点为A(5,15,25)和B(10,20,30)的直线段在上述投影平面的投影。 A点在该平面上的投影为(3/5,9/5,3)B点在该平面上的投影为(1,2,3),投影线段的方程为
13,yx,,3,。 ,[,1]x,22,5,z,3,
5.4将Liang,Barsky裁剪算法扩展到三维空间中时,在规范的平行投影视域中确定其需要的不等式。
,为线段的终点,线段的参数
达式为pxyz,(,,)pxyz,(,,)11111222
xxxxu,,,(),121,yyyyuu,,,,(),0,1 ,,,121
,zzzzu,,,()121,
xxxxux,,,,,,(),min121max,yyyyuy,,,,,,()在规范的平行投影视口中的点满足下列不等式 ,min121max
,zzzzuz,,,,,,()min121max,
,。 xyz,,,0xyz,,,1minminminmaxmaxmax
pxqx,,,,(左),111,pxqx,,,,1(右)221,
,pyqy,,,,(下),331上述不等式可以写为 puqk,,,,1..6,kkpyqy,,,,1(上)441,
,pzqz,,,,(前)551,pzqz,,,,1(后),261,
5.5设视口由点(0,0)和点(10 , 10)确定,窗口由点(0,0)和(100,100)确定,由式(5.12)
写出窗口到视口的变换关系。
x,Ax,Bpv由式(5.12),计算得A=1/10,B=0,C=1/10,D=0.所以窗口到视口的变换关系为
y,Cy,Dvp
xx,,1/10pv
yy,,1/10vp
5.5用Java3D编程实现将一个立方体中心移到点(0.6,0.3,0.3)的平移变换。
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.universe.*; import com.sun.j3d.utils.geometry.*; import javax.media.j3d.*;
import javax.vecmath.*;
import javax.swing.*;
public class Question5 extends Applet implements ActionListener
{
JButton translate=new JButton("平移");
TransformGroup objTrans;
Transform3D transform=new Transform3D();
BranchGroup createSceneGraph()
{
BoundingSphere bounds=new BoundingSphere();
BranchGroup objRoot=new BranchGroup();
//环境光
AmbientLight lightA=new AmbientLight();
lightA.setInfluencingBounds(new BoundingSphere());
objRoot.addChild(lightA);
//trans
objTrans=new TransformGroup(transform);
objTrans.setCapability(objTrans.ALLOW_TRANSFORM_WRITE);
objTrans.setCapability(objTrans.ALLOW_TRANSFORM_READ);
objRoot.addChild(objTrans);
//绘制坐标系
Shape3D coord=drawCoord(0f,0f,0f);
objRoot.addChild(coord);
//绘制立方体
ColorCube cube=new ColorCube(.1);
objTrans.addChild(cube);
//background
Color3f bgColor=new Color3f(1f,1f,1f);
Background bg=new Background(bgColor);
bg.setApplicationBounds(bounds);
objRoot.addChild(bg);
objRoot.compile();
return objRoot;
}
public Shape3D drawCoord(float x,float y,float z)
{
float d=7;
float vert[]={x,y,z,x+d,y,z,x,y+d,z,x,y,z+d};
int[] index={0,1,0,2,0,3};
IndexedLineArray coord=new IndexedLineArray(4,IndexedLineArray.COORDINATES,6);
coord.setCoordinates(0,vert);
coord.setCoordinateIndices(0,index);
LineAttributes la=new LineAttributes();
la.setLinePattern(la.PATTERN_DASH);
Appearance coordApp=new Appearance();
coordApp.setLineAttributes(la);
ColoringAttributes coordAttributes=new ColoringAttributes();
coordAttributes.setColor(new Color3f(0f,0f,0f));
coordApp.setColoringAttributes(coordAttributes);
Shape3D shape=new Shape3D(coord,coordApp);
return shape;
}
public Question5()
{
setLayout(new BorderLayout());
GraphicsConfiguration config=SimpleUniverse.getPreferredConfiguration();
Canvas3D c=new Canvas3D(config);
add("Center",c);
JPanel p=new JPanel();
p.add(translate);
add("North",p);
translate.addActionListener(this);
ViewPlatform vierPlatform;
SimpleUniverse u=new SimpleUniverse(c);
BranchGroup scene=createSceneGraph();
u.getViewingPlatform().setNominalViewingTransform();
u.addBranchGraph(scene);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource()==translate)
{
transform.setTranslation(new Vector3d(.6,.3,.3));
objTrans.setTransform(transform);
}
}
public static void main(String[] args)
{
new MainFrame(new Question5(),250,200);
}
}
5.6用Java3D编程实现一个立方体的放缩变换,要求X方向放大5倍,Y方向缩小2倍,Z方向放大3倍。 import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.universe.*; import com.sun.j3d.utils.geometry.*; import javax.media.j3d.*;
import javax.vecmath.*;
import javax.swing.*;
public class Question6 extends Applet implements ActionListener
{
JButton scale=new JButton("scale");
TransformGroup objTrans;
Transform3D transform=new Transform3D();
BranchGroup createSceneGraph()
{
BoundingSphere bounds=new BoundingSphere();
BranchGroup objRoot=new BranchGroup();
//环境光
AmbientLight lightA=new AmbientLight();
lightA.setInfluencingBounds(new BoundingSphere());
objRoot.addChild(lightA);
//trans
objTrans=new TransformGroup(transform);
objTrans.setCapability(objTrans.ALLOW_TRANSFORM_WRITE);
objTrans.setCapability(objTrans.ALLOW_TRANSFORM_READ);
objRoot.addChild(objTrans);
//绘制坐标系
Shape3D coord=drawCoord(0f,0f,0f);
objRoot.addChild(coord);
//绘制立方体
ColorCube cube=new ColorCube(.1);
objTrans.addChild(cube);
//background
Color3f bgColor=new Color3f(1f,1f,1f);
Background bg=new Background(bgColor);
bg.setApplicationBounds(bounds);
objRoot.addChild(bg);
objRoot.compile();
return objRoot;
}
public Shape3D drawCoord(float x,float y,float z)
{
float d=7;
float vert[]={x,y,z,x+d,y,z,x,y+d,z,x,y,z+d};
int[] index={0,1,0,2,0,3};
IndexedLineArray coord=new IndexedLineArray(4,IndexedLineArray.COORDINATES,6);
coord.setCoordinates(0,vert);
coord.setCoordinateIndices(0,index);
LineAttributes la=new LineAttributes();
la.setLinePattern(la.PATTERN_DASH);
Appearance coordApp=new Appearance();
coordApp.setLineAttributes(la);
ColoringAttributes coordAttributes=new ColoringAttributes();
coordAttributes.setColor(new Color3f(0f,0f,0f));
coordApp.setColoringAttributes(coordAttributes);
Shape3D shape=new Shape3D(coord,coordApp);
return shape;
}
public Question6()
{
setLayout(new BorderLayout());
GraphicsConfiguration config=SimpleUniverse.getPreferredConfiguration();
Canvas3D c=new Canvas3D(config);
add("Center",c);
JPanel p=new JPanel();
p.add(scale);
add("North",p);
scale.addActionListener(this);
ViewPlatform vierPlatform;
SimpleUniverse u=new SimpleUniverse(c);
BranchGroup scene=createSceneGraph();
u.getViewingPlatform().setNominalViewingTransform();
u.addBranchGraph(scene);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource()==scale)
{
transform.setScale(new Vector3d(5,2,3));
objTrans.setTransform(transform);
}
}
public static void main(String[] args)
{
new MainFrame(new Question6(),250,200);
}
}
5.7用Java3D编程实现一个立方体绕y轴逆时针旋转90度的旋转变换。
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import com.sun.j3d.utils.applet.MainFrame; import com.sun.j3d.utils.universe.*; import com.sun.j3d.utils.geometry.*; import javax.media.j3d.*;
import javax.vecmath.*;
import javax.swing.*;
public class Question7 extends Applet implements ActionListener
{
JButton rotate=new JButton("rotate");
TransformGroup objTrans;
Transform3D transform=new Transform3D();
BranchGroup createSceneGraph()
{
BoundingSphere bounds=new BoundingSphere();
BranchGroup objRoot=new BranchGroup();
//环境光
AmbientLight lightA=new AmbientLight();
lightA.setInfluencingBounds(new BoundingSphere());
objRoot.addChild(lightA);
//trans
objTrans=new TransformGroup(transform);
objTrans.setCapability(objTrans.ALLOW_TRANSFORM_WRITE);
objTrans.setCapability(objTrans.ALLOW_TRANSFORM_READ);
objRoot.addChild(objTrans);
//绘制坐标系
Shape3D coord=drawCoord(0f,0f,0f);
objRoot.addChild(coord);
//绘制立方体
ColorCube cube=new ColorCube(.1);
objTrans.addChild(cube);
//background
Color3f bgColor=new Color3f(1f,1f,1f);
Background bg=new Background(bgColor);
bg.setApplicationBounds(bounds);
objRoot.addChild(bg);
objRoot.compile();
return objRoot;
}
public Shape3D drawCoord(float x,float y,float z)
{
float d=7;
float vert[]={x,y,z,x+d,y,z,x,y+d,z,x,y,z+d};
int[] index={0,1,0,2,0,3};
IndexedLineArray coord=new IndexedLineArray(4,IndexedLineArray.COORDINATES,6);
coord.setCoordinates(0,vert);
coord.setCoordinateIndices(0,index);
LineAttributes la=new LineAttributes();
la.setLinePattern(la.PATTERN_DASH);
Appearance coordApp=new Appearance();
coordApp.setLineAttributes(la);
ColoringAttributes coordAttributes=new ColoringAttributes();
coordAttributes.setColor(new Color3f(0f,0f,0f));
coordApp.setColoringAttributes(coordAttributes);
Shape3D shape=new Shape3D(coord,coordApp);
return shape;
}
public Question7()
{
setLayout(new BorderLayout());
GraphicsConfiguration config=SimpleUniverse.getPreferredConfiguration();
Canvas3D c=new Canvas3D(config);
add("Center",c);
JPanel p=new JPanel();
p.add(rotate);
add("North",p);
rotate.addActionListener(this);
ViewPlatform vierPlatform;
SimpleUniverse u=new SimpleUniverse(c);
BranchGroup scene=createSceneGraph();
u.getViewingPlatform().setNominalViewingTransform();
u.addBranchGraph(scene);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource()==rotate)
{
transform.setRotation(new AxisAngle4d(0,1,0,Math.PI/2));
objTrans.setTransform(transform);
}
}
public static void main(String[] args)
{
new MainFrame(new Question7(),250,200);
}
}