ImageVerifierCode 换一换
格式:DOCX , 页数:20 ,大小:166.05KB ,
资源ID:6343477      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/6343477.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(图形学实验三.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

图形学实验三.docx

1、图形学实验三图形学实验三Bezier曲线040930301 陈圣楠一、 程序实现环境、硬件配置、操作系统、编程语言1. 程序实现环境本程序在eclipse-indigo通过,使用jdk1.62. 硬件配置处理器:Intel(R) Core i3 CPU M350 2.27GHz安装内存(RAM):2.00GB3. 操作系统Windows7 旗舰版32位操作系统4. 编程语言java二、 算法思想阐述Bezier曲线的定义是给定空间n+1 个点的位置矢量,则Bezier曲线可定义为: 算法推导设是一条抛物线上顺序三个不同的点。过和点的两切线交于点,在点的切线交和于和,则如下比例成立当固定,引入参

2、数t,令上述比值为,即有:t从0变到1,第一、二式就分别表示控制二边形的第一、二条边,它们是两条一次Bezier曲线。将一、二式代入第三式得:当t从0变到1时,它表示了由三顶点三点定义的一条二次Bezier曲线。并且表明:这二次Bezier曲线可以定义为分别由前两个顶点和后两个顶点决定的一次Bezier曲线的线性组合。依次类推,由四个控制点定义的三次Bezier曲线可被定义为分别由和确定的二条二次Bezier曲线的线性组合,由(n+1)个控制点定义的n次Bezier曲线可被定义为分别由前、后n个控制点定义的两条(n-1)次Bezier曲线与的线性组合。由此得到Bezier曲线的递推计算公式三、

3、 怎样使用本程序实现了编程实现绘制一段三次Bezier曲线和实现两段三次Bezier曲线的拼接。双击空白可添加顶点,添加两个顶点时,两点之间自动生成直线,添加第三个顶点时,根据Bezier公式,可产生一条曲线,继续添加顶点,每三个连续的顶点之间将产生一条曲线。其他功能包括:双击一个顶点,可将该顶点删除,拖动一个顶点可改变顶点位置,双击右键清屏。图1 初始化程序图2 选中一个顶点四、 实验结果(图示) Bezier曲线图3 选中两点的结果图4 Bezier曲线图5 Bezier曲线(2)五、 测试用例(合法用例、非法用例)1. 合法用例在画板灰色区域鼠绘即可,如上图4和图5。2. 非法用例本程序

4、采用鼠标点击,无非法用例,所以在此不提供非法用例及处理。六、 实验程序适用范围本程序可作为画板、word等其他需要绘制曲线的程序的一部分,也可用于photoshop和flash中处理图像。源代码工程名:csn0423Proj3包名:test3类名:Bezier.javapackage test3;import javax.swing.*;import java.awt.*;public class Bezier boolean packFrame=false; public Bezier() Draw frame=new Draw(); if(packFrame) frame.pack();

5、else frame.validate(); Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize=frame.getSize(); if(frameSize.heightscreenSize.height) frameSize.height=screenSize.height; if(frameSize.widthscreenSize.width) frameSize.width=screenSize.width; frame.setLocation(screenSize.w

6、idth-frameSize.width)/2,(screenSize.height-frameSize.height)/2); frame.setVisible(true); public static void main(String args) try UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName(); catch(Exception e) e.printStackTrace(); new Bezier(); 工程名:csn0423Proj3包名:test3类名:BezierPanel.javapacka

7、ge test3;import java.awt.*;import javax.swing.*;import java.util.ArrayList;class Vertex static final Color VEXCOLOR=Color.pink; static final double RADII=4; private double x,y; public Vertex(double xx,double yy) x=xx; y=yy; public double getX() return x; public double getY() return y; public void se

8、tX(double xx) x=xx; public void setY(double yy) y=yy; /*判断所给坐标是否在该顶点内*/ public boolean isIn(double dx,double dy) double len; len=Math.sqrt(Math.pow(dy-y,2)+Math.pow(dx-x,2); if(len=RADII) return true;else return false; public String toString() return (+x+ , +y+); public class BezierPanel extends JPa

9、nel private static final String INS1=双击空白地方添加顶点; private static final String INS2=双击一个顶点删除该顶点; private static final String INS3=拖动一个顶点改变该顶点的位置; private static final String INS4=双击右键清屏; private static final Color VEXLINK=Color.red;/顶点间连线的颜色 static final Color BEZIERCOLOR=Color.blue;/ private ArrayLis

10、t vexs;/顶点 private int bim;/伯恩斯坦多项式系数 public BezierPanel() super(); vexs=new ArrayList(); /*取得原点横坐标*/ private int getX0() return 10; /*取得原点纵坐标*/ private int getY0() return this.getHeight()-10; /*实数横坐标转象素横坐标*/ public int toPelsX(double dx) return getX0()+(int)dx; /*实数纵坐标转象素纵坐标*/ public int toPelsY(do

11、uble dy) return getY0()-(int)dy; /*象素横坐标转实数横坐标*/ public double toRealX(int px) return (double)px-(double)getX0(); /*象素纵坐标转实数纵坐标*/ public double toRealY(int py) return (double)getY0()-(double)py; /*求杨辉三角的底边 * param n 阶次 * return int */ private int yangHui(int n) int i,j1,j2; int c,tc; c=new int1; c0=

12、1; for(i=2;i=n;i+) tc=c; c=new inti; c0=1; for(j2=0,j1=1;j1tc.length;j2+,j1+) cj1=tcj2+tcj1; cj1=1; return c; /*增加一个顶点 * param px 象素横坐标 * param py 象素纵坐标 */ public void addVex(int px,int py) vexs.add(new Vertex(toRealX(px),toRealY(py);/加入顶点 bim=yangHui(vexs.size();/修改伯恩斯坦多项式系数 this.repaint();/重画 /*删除

13、一个顶点 * param index 顶点序号 */ public void removeVex(int index) vexs.remove(index);/删除 bim=yangHui(vexs.size();/修改伯恩斯坦多项式系数 this.repaint();/重画 /*删除所有顶点*/ public void clear() vexs.clear(); this.repaint();/重画 /*设置某个顶点的坐标 * param index 序号 * param dx 象素横坐标 * param dy 象素纵坐标 */ public void setLocation(int ind

14、ex,int dx,int dy) Vertex vex; if(index=-1) return; vex=(Vertex)vexs.get(index); vex.setX(toRealX(dx); vex.setY(toRealY(dy); this.repaint(); /*取得贝塞尔线的横坐标 * param t 参数 * return double */ public double getBezierX(double t) int i; double bx=0; for(i=0;ivexs.size();i+) bx+=(Vertex)vexs.get(i).getX()*bimi

15、*Math.pow(t,i)*Math.pow(1-t,vexs.size()-1-i); return bx; /*取得贝塞尔线的纵坐标 * param t 参数 * return double */ public double getBezierY(double t) int i; double by=0; for(i=0;ivexs.size();i+) by+=(Vertex)vexs.get(i).getY()*bimi*Math.pow(t,i)*Math.pow(1-t,vexs.size()-1-i); return by; /*取得选中的顶点序号 * param px 鼠标横

16、坐标 * param py 鼠标纵坐标 * return 若没选中则返回-1 */ public int getSelectexVexIndex(int px,int py) int i; double dx,dy; dx=toRealX(px); dy=toRealY(py); for(i=0;ivexs.size();i+) if(Vertex)vexs.get(i).isIn(dx,dy) return i; return -1; /*画坐标系*/ public void drawCoordinate(Graphics g) Color oldcolor; oldcolor=g.getC

17、olor(); /坐标轴 g.drawLine(getX0(),getY0(),this.getWidth()-10,getY0(); g.drawLine(getX0(),getY0(),getX0(),10); g.drawString(0,getX0()-7,getY0()+10); g.drawString(x,this.getWidth()-10,getY0()+10); g.drawString(y,getX0()-7,10); /说明文字 g.drawString(INS1,15,20); g.drawString(INS2,15,32); g.drawString(INS3,1

18、5,44); g.drawString(INS4,15,56); g.setColor(oldcolor); /*画顶点极其连线*/ public void drawVexList(Graphics g) int i,dia; Vertex vex1,vex2; Color oldcolor; if(vexs.size()=0) return;/没有顶点则返回 oldcolor=g.getColor();/保存原来的颜色 g.setColor(Vertex.VEXCOLOR);/顶点色 dia=(int)Vertex.RADII*2;/直径 vex1=(Vertex)vexs.get(0);/

19、第一个顶点 /fillOval()的坐标参数为左上角坐标,不是原点坐标 g.fillOval(toPelsX(vex1.getX()-(int)Vertex.RADII,toPelsY(vex1.getY()-(int)Vertex.RADII,dia,dia);/画第一个顶点 for(i=1;i=2) g.setColor(BEZIERCOLOR); dx1=getBezierX(0); dy1=getBezierY(0); for(t=0;t=1;t+=dt) dx2=dx1; dy2=dy1; dx1=getBezierX(t); dy1=getBezierY(t); g.drawLin

20、e(toPelsX(dx2),toPelsY(dy2),toPelsX(dx1),toPelsY(dy1); 工程名:csn0423Proj3包名:test3类名:Draw.javapackage test3;import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.border.*;public class Draw extends JFrame JPanel jPanel; JMenuBar jMenuBar1=new JMenuBar(); JMenu jMenuFile=new J

21、Menu(); BorderLayout borderLayout1=new BorderLayout(); private JPanel jpboard=new JPanel(); private TitledBorder titledBorder1; private BezierPanel board=new BezierPanel(); private BorderLayout borderLayout2=new BorderLayout(); private JLabel jlloc=new JLabel(); private int index; /选中的顶点 public Draw

22、() enableEvents(AWTEvent.WINDOW_EVENT_MASK); try jbInit(); catch(Exception e) e.printStackTrace(); index=-1; /Component initialization private void jbInit() throws Exception jPanel=(JPanel)this.getContentPane(); titledBorder1=new TitledBorder(BorderFactory.createEtchedBorder(Color.white,new Color(16

23、5,163,151),bezier board:); jPanel.setLayout(borderLayout1); this.setSize(new Dimension(538,417); this.setTitle(Bezier); jpboard.setBorder(titledBorder1); jpboard.setLayout(borderLayout2); board.addMouseListener(new Draw_MouseAdapter(this); jlloc.setHorizontalAlignment(SwingConstants.RIGHT); jlloc.se

24、tText( ); board.addMouseMotionListener(new GUI_board_mouseMotionAdapter(this); jpboard.add(board,BorderLayout.CENTER); jPanel.add(jpboard,BorderLayout.CENTER); jPanel.add(jlloc,BorderLayout.SOUTH); this.setJMenuBar(jMenuBar1); /*鼠标点击*/ void board_mouseClicked(MouseEvent e) int index; if(e.getClickCo

25、unt()!=2) return; /双击事件 if(e.getButton()=MouseEvent.BUTTON3) board.clear(); /右键双击删除所有顶点 else if(e.getButton()=MouseEvent.BUTTON1) /左键双击 index=board.getSelectexVexIndex(e.getX(),e.getY(); /取得顶点序号 if(index=-1) board.addVex(e.getX(),e.getY(); /若点击空白则加入顶点 else board.removeVex(index); /删除顶点 /*鼠标移动*/ void

26、 board_mouseMoved(MouseEvent e) jlloc.setText(Location: (+board.toRealX(e.getX()+ , +board.toRealY(e.getY()+) ); /*鼠标压下*/ void board_mousePressed(MouseEvent e) index=board.getSelectexVexIndex(e.getX(),e.getY(); /*鼠标放开*/ void board_mouseReleased(MouseEvent e) index=-1; /*鼠标拖动*/ void board_mouseDragged(MouseEvent e) int px,py; if(index!=-1) px=e.getX(); py=e.getY(); /将坐标限制在画板内 if(pxboard.getWidth() px=board.getWidth(); if(py0) py=0;

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1