计算机图形学CG 中点画圆法 画圆
来源:互联网 发布:电脑桌面美化软件大全 编辑:程序博客网 时间:2024/04/27 15:17
画圆
姓 名:
学 号:
班 级:
日 期: 2012-4
实验: 画圆
实验内容:
我使用的是中点画圆法(改进(2)算法)
核心算法:
//画8个对称的点
public static void drawEightPoint(int x,int y,Graphics g)
{
g.fillOval(offsetX+x,offsetY+y,pointSize,pointSize);
g.fillOval(offsetX+x,offsetY-2*r+(offsetY-y),pointSize,pointSize);
g.fillOval(offsetX-3*r+(offsetX-x),offsetY+y,pointSize,pointSize);
g.fillOval(offsetX-3*r+(offsetX-x),offsetY-2*r+(offsetY-y),pointSize,pointSize);
g.fillOval(offsetX+y,offsetY+x,pointSize,pointSize);
g.fillOval(offsetX+y,offsetY-2*r+(offsetY-x),pointSize,pointSize);
g.fillOval(offsetX-3*r+(offsetX-y),offsetY+x,pointSize,pointSize);
g.fillOval(offsetX-3*r+(offsetX-y),offsetY-2*r+(offsetY-x),pointSize,pointSize);
}
//中点画圆核心算法
public staticvoiddrawCircle(Graphics g) {
int x, y, d;
x= 0;
y= r;
int deltax = 3;
int deltay = 2 -r -r;
d= 1 - r;
drawEightPoint(x,y,g);
while (x <= y) {
if (d < 0) {
d+= deltax;
deltax+= 2;
}else{
d+= deltax + deltay;
deltax+= 2;
deltay+= 2;
y--;
}
x++;
drawEightPoint(x,y,g);
}
实验结果:(截图)
程序源代码:
package cs0904.no200942094;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
public classDrawCircle extendsJPanel {
private static int frameWidth = 600;
private static int frameHeight = 600;
private static int offsetX = 300,offsetY = 200;
// 起点和重点的坐标
// 半径
private static int r = 100;
// 定义点的大小
private static int pointSize = 5;
// 每20格算一个小格
private static int turnBigger(int temp) {
return temp * 20;
}
public static void main(String[] args) {
JFrameframe = newJFrame("DrawLine");
frame.getContentPane().add(new DrawCircle());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(frameWidth,frameHeight);
frame.setLocation(200,10);
frame.setVisible(true);
}
//画8个对称的点
public static void drawEightPoint(int x,int y,Graphics g)
{
g.fillOval(offsetX+x,offsetY+y,pointSize,pointSize);
g.fillOval(offsetX+x,offsetY-2*r+(offsetY-y),pointSize,pointSize);
g.fillOval(offsetX-3*r+(offsetX-x),offsetY+y,pointSize,pointSize);
g.fillOval(offsetX-3*r+(offsetX-x),offsetY-2*r+(offsetY-y),pointSize,pointSize);
g.fillOval(offsetX+y,offsetY+x,pointSize,pointSize);
g.fillOval(offsetX+y,offsetY-2*r+(offsetY-x),pointSize,pointSize);
g.fillOval(offsetX-3*r+(offsetX-y),offsetY+x,pointSize,pointSize);
g.fillOval(offsetX-3*r+(offsetX-y),offsetY-2*r+(offsetY-x),pointSize,pointSize);
}
public static void drawCircle(Graphics g){
int x, y, d;
x= 0;
y= r;
int deltax = 3;
int deltay = 2 -r -r;
d= 1 - r;
drawEightPoint(x,y,g);
while (x <= y) {
if (d < 0) {
d+= deltax;
deltax+= 2;
}else{
d+= deltax + deltay;
deltax+= 2;
deltay+= 2;
y--;
}
x++;
drawEightPoint(x,y,g);
}
g.drawString("", x+20, y+20);
}
protected void paintComponent(Graphicsg) {
super.paintComponent(g);
for (int i = 0; i <frameHeight; i +=turnBigger(1)){
g.drawLine(0,i, frameWidth,i);
}
for (int i = 0; i <frameWidth; i +=turnBigger(1)){
g.drawLine(i,0, i, frameHeight);
}
drawCircle(g);
}
}
- 计算机图形学CG 中点画圆法 画圆
- 计算机图形学 :中点画圆法
- 中点画圆法(计算机图形学)
- 计算机图形学:中点画圆算法
- 中点画圆(计算机图形学)
- 计算机图形学之中点画圆法
- 【计算机图形学】中点画圆算法和Bresenham画圆算法
- 计算机图形学(二)中点画圆算法讲解与源代码
- 计算机图形学(二)输出图元_6_OpenGL曲线函数_2_中点画圆算法
- 计算机图形学之中点画算法
- 中点画圆法
- 中点画圆法
- 计算机图形学笔记---Cg语言(一)
- 计算机图形学笔记---Cg语言(二)
- 圆生成算法---中点画圆法
- 用OpenGL实现 中点画圆法
- 中点画圆
- 用Python&OpenGL采用数值微分法和中点画圆法写图形学作业——会动的时钟
- 中缀转后缀二叉树的答印
- OpenStreetMap初探(外一篇)——Serving Tiles
- Android实现左右滑动指引效果
- 2010.08.05_ximo_加VMP外壳后的程序的爆破分析二(vmp 2.05)
- 登录界面
- 计算机图形学CG 中点画圆法 画圆
- 【STL】C++ string 类基本用法样例
- poj 2001
- Android实现导航菜单左右滑动效果
- web工程读取properties配置各种方法
- 三大WEB服务器对比分析apache、lighttpd、nginx
- gFTP源码安装缺失stropts.h问题
- SQL中使用WITH AS提高性能
- fio 配置实验