没有合适的资源?快使用搜索试试~ 我知道了~
第二章 习题1. 把中点画圆算法从1/8改成整圆public class MidpointCircle extends JFrame {public Midpo
资源详情
资源评论
资源推荐
第二章 习题
1. 把中点画圆算法从1/8改成整圆
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Graphics;
public class MidpointCircle extends JFrame {
public MidpointCircle() {
setTitle("DrawArcs");
add(new ArcsPanel());
}
/** Main method */
public static void main(String[] args) {
MidpointCircle frame = new MidpointCircle();
frame.setLocationRelativeTo(null); // Center the frame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500, 500);
frame.setVisible(true);
}
}
// The class for drawing arcs on a panel
class ArcsPanel extends JPanel {
// Draw four blazes of a fan
protected void paintComponent(Graphics g) {
super.paintComponent(g);
int x,y,R=100;
double d;
x=0; y=R; d=1.25-R;
g.drawString(".", x,y);
while(x<y){
if(d<0){
d+=2*x+3;
x++; }
else{
d+=2*(x-y)+5;
x++;
y--; }
g.drawString(".", x,y);
g.drawString(".",
(int)(x*Math.cos(-3.14159*1/4)-y*Math.sin(-3.14159*1/4)),(int)(x*Math
.sin(-3.14159*1/4)+y*Math.cos(-3.14159*1/4)));
g.drawString(".", x+200,y+200);
g.drawString(".",
(int)(x*Math.cos(-3.14*2/8)-y*Math.sin(-3.14*2/8)+200),(int)(x*Math.s
in(-3.14*2/8)+y*Math.cos(-3.14*2/8))+200);
g.drawString(".", -x+200,-y+200);
g.drawString(".",
(int)(x*Math.cos(-3.14*2/8)-y*Math.sin(-3.14*2/8)+200),-(int)(x*Math.
sin(-3.14*2/8)+y*Math.cos(-3.14*2/8))+200);
g.drawString(".", x+200,-y+200);
g.drawString(".", -x+200,y+200);
}
}
}
2.线性和线宽问题,画虚线和点画线
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Graphics;
public class BresenhamLine2 extends JFrame {
public BresenhamLine2() {
setTitle("BresenhamLine1");
add(new LinePanel());
}
/** Main method */
public static void main(String[] args) {
BresenhamLine2 frame = new BresenhamLine2();
frame.setLocationRelativeTo(null); // Center the frame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 300);
frame.setVisible(true);
}
}
class LinePanel extends JPanel {
protected void paintComponent(Graphics g) {
super.paintComponent(g);
int x1=0,x2=100,y1=0,y2=30,s=100,x,y,dx,dy,p,type=2;
x=x1;
y=y1;
dx=x2-x1;
dy=y2-y1;
p = 2 * dy-dx;
s=0;
for(;x<=x2;x++){
s=s+1;
if (type ==0) //画实线
g.drawString(".", (int)x,(int)y);
if (type==1) //画虚线
if ((s%5) != 0)
g.drawString(".", (int)x,(int)y);
if (type==2) //画点划线
if ((s%10)!=5 && (s%10)!=6 && (s%10)!=7)
g.drawString(".", (int)x,(int)y);
if (p>=0){
y++;
p+=2*(dy-dx);
}
else{
p+=2*dy;
}
}
}
}
设五边形的五个顶点是(10.5,10.5)、(15,5)、( 12,5)、( 8,2.5)、(4,5.5),要利用使
用活跃边表的扫描算法进行填充,写出应填写的 ET 表,写出活跃边表的变化情况。
首先对顶点坐标进行四舍五入,得到(11,11),( 15,5),( 12,5),( 8,3),( 4,6)。
ET 表如下:
剩余12页未读,继续阅读
天眼妹
- 粉丝: 21
- 资源: 333
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0