openGL虛線,點(diǎn)劃線,KOCK曲線實(shí)驗(yàn)報(bào)告_第1頁(yè)
openGL虛線,點(diǎn)劃線,KOCK曲線實(shí)驗(yàn)報(bào)告_第2頁(yè)
openGL虛線,點(diǎn)劃線,KOCK曲線實(shí)驗(yàn)報(bào)告_第3頁(yè)
openGL虛線,點(diǎn)劃線,KOCK曲線實(shí)驗(yàn)報(bào)告_第4頁(yè)
openGL虛線,點(diǎn)劃線,KOCK曲線實(shí)驗(yàn)報(bào)告_第5頁(yè)
已閱讀5頁(yè),還剩8頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、實(shí)驗(yàn)四實(shí)驗(yàn)報(bào)告1、實(shí)驗(yàn)?zāi)康暮鸵罄肙penGL實(shí)現(xiàn)實(shí)線,虛線,點(diǎn)劃線的繪制,及kock曲線。2、實(shí)驗(yàn)內(nèi)容1)用OpenGL程序繪制實(shí)現(xiàn),虛線和點(diǎn)劃線2)用OpenGL程序,分別以直線和正三角形為初始生成員,實(shí)現(xiàn)迭代次數(shù)在6次以內(nèi)的kock曲線,要求用鍵盤(pán)交互控制迭代次數(shù)。3、實(shí)驗(yàn)步驟1)相關(guān)算法及原理描述直線的繪制在OpenGL中繪制直線通過(guò)指定直線段的端點(diǎn)來(lái)實(shí)現(xiàn),用glVertex函數(shù)指定直線段端點(diǎn)的坐標(biāo)位置,用glBegin/glEnd函數(shù)對(duì)包含一系列的點(diǎn)坐標(biāo),并利用符號(hào)常量解釋這些點(diǎn)構(gòu)成直線的方式。虛線的繪制繪制虛線需要先調(diào)用函數(shù)過(guò)了Enable(GL_LINE_STIPPLE);打開(kāi)

2、劃線模式。然后,函數(shù)glLineStipple將建立用于劃線的模式glLineStipple(Glintfactor,GLushortpattern);Kock曲線Kock曲線的初始生成員是一條直線,生成規(guī)則是將直線段分為三等分,首尾兩段保持不變,中間用兩段等長(zhǎng)且互成60角的直線段代替。這樣,直線段被分成四段,每段長(zhǎng)度都只有原來(lái)的1/3。Kock曲線的分形維數(shù)為D=ln4/ln31.26186假設(shè)原直線的首尾點(diǎn)是P0(x0,y0),P1(x1,yl),則新的四段直線段的五個(gè)端點(diǎn)坐標(biāo)分別為(x0,y0)(x0+(x1-x0)/3,y0+(y1-y0)/3)(xl+x0)/2土(yO-yl)V3/

3、6,(yl+y0)/2(xl-xO)V3/6)(x0+2(x1-x0)/3,y0+2(y1-y0)/3)(x1,y1)其中,第三個(gè)點(diǎn)坐標(biāo)公式中的正負(fù)號(hào)表示中間兩條心直線段處于元直線段的哪一側(cè)。根據(jù)這一規(guī)則迭代六次。2)程序調(diào)試、測(cè)試與運(yùn)行結(jié)果分析直線的繪制結(jié)果以直線作為初始生成元的Kock曲線以三角形作為初始生成元的Kock曲線4、實(shí)驗(yàn)總結(jié)在上一次的實(shí)驗(yàn)基礎(chǔ)上,利用GL_LINES畫(huà)直線,這項(xiàng)實(shí)驗(yàn)內(nèi)容比較容易。然后,利用glEnable(GL_LINE_STIPPLE)函數(shù)和glLineStiopple(Glintfactor,GLushortpattern進(jìn)行虛線和點(diǎn)畫(huà)線的實(shí)現(xiàn)。也是比較簡(jiǎn)單

4、的。第二個(gè)實(shí)驗(yàn)是利用Kock曲線實(shí)現(xiàn)迭代生成圖形,這個(gè)實(shí)驗(yàn)很難。用了兩節(jié)課的時(shí)間,最終也沒(méi)有成功。我自己沒(méi)有做成功,去請(qǐng)教別人,看別人的才做出來(lái)的。看到生成的圖像很漂亮不管結(jié)果怎么樣,我在這次的實(shí)驗(yàn)中學(xué)到了很多知識(shí),對(duì)編程也好,對(duì)openGL也好,都有了更好更深的理解。5、附錄1直線的繪制#includeintwinWidth=400,winHeight=300;voidInitial(void)glClearColor(1.0f,1.0f,1.0f,1.0f);voidChangeSize(intw,inth)winWidth=w;winHeight=h;glViewport(0,0,w,h

5、);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluOrtho2D(0.0,winWidth,0.0,winHeight);voidDisplay(void)glClear(GL_COLOR_BUFFER_BIT);glColor3f(1.0f,0.0f,0.0f);glBegin(GL_LINES);glVertex2i(100,80);glVertex2i(220,250);glEnd();glutSwapBuffers();intmain(intargc,char*argv)glutInit(&argc,argv);glutInitDisp

6、layMode(GLUT_DOUBLE|GLUT_RGB);glutInitWindowSize(400,300);glutInitWindowPosition(100,100);glutCreateWindow(”直線”);glutDisplayFunc(Display);glutReshapeFunc(ChangeSize);Initial();glutMainLoop();return0;2虛線及點(diǎn)劃線的繪制#includeintwinWidth=400,winHeight=300;voidInitial(void)glClearColor(1.0f,1.0f,1.0f,1.0f);vo

7、idChangeSize(intw,inth)winWidth=w;winHeight=h;glViewport(0,0,w,h);glMatrixMode(GL_PROJECTION);glLoadIdentity();gluOrtho2D(0.0,winWidth,0.0,winHeight);voidDisplay(void)glClear(GL_COLOR_BUFFER_BIT);glColor3f(1.0f,0.0f,0.0f);glBegin(GL_LINES);glVertex2i(100,80);glVertex2i(220,250);glEnd();glutSwapBuffe

8、rs();intmain(intargc,char*argv)glutInit(&argc,argv);glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);glutInitWindowSize(400,300);glutInitWindowPosition(100,100);glutCreateWindow(”虛線”);glEnable(GL_LINE_STIPPLE);glLineStipple(2,0X00FF);glutDisplayFunc(Display);glutReshapeFunc(ChangeSize);Initial();glutMainLo

9、op();return0;3以直線為生成元的Kock曲線#include#include#include#include#definePI3.1415926usingnamespacestd;structPointfloatx;floaty;staticvectorcount;staticintm=0;/迭代次數(shù)floatline;voidfirst_state(vector&count)/初始情況是只有兩個(gè)點(diǎn)Pointfirst=-1.0f,0.0f,end=1.0f,0.0f;line=sqrt(pow(first.x-end.x,2)+pow(first.y-end.y,2);count

10、.push_back(first);count.push_back(end);voidDraw_pic(vector&count)for(vector:size_typei=0;i!=(count.size()-1);i+)glBegin(GL_LINES);glVertex2f(counti.x,counti.y);glVertex2f(counti+1.x,counti+1.y);glEnd();voidCalculate_point(vector&count)vectornew_count;floatpline=line/(float)pow(float)3,(int)m);vector

11、:size_typei;for(i=0;i!=(count.size()-1);i+)Pointp1,p2,pmid;p1.x=counti.x+(counti+1.x-counti.x)/3;p1.y=counti.y+(counti+1.y-counti.y)/3;p2.x=counti+1.x-(counti+1.x-counti.x)/3;p2.y=counti+1.y-(counti+1.y-counti.y)/3;doublealpha=0.0;if(counti+1.y=counti.y)alpha=atan(double)(counti+1.y-counti.y)/(count

12、i+1.x-counti.x);if(counti+1.xcounti.x)pmid.x=p1.x+pline*cos(alpha+PI/3);pmid.y=p1.y+pline*sin(alpha+PI/3);elsepmid.x=p1.x-pline*cos(alpha+PI/3);pmid.y=p1.y-pline*sin(alpha+PI/3);elsealpha=atan(double)(counti.y-counti+1.y)/(counti+1.x-counti.x);if(counti+1.xcounti.x)pmid.x=p2.x-pline*cos(alpha+PI/3);

13、pmid.y=p2.y+pline*sin(alpha+PI/3);elsepmid.x=p2.x+pline*cos(alpha+PI/3);pmid.y=p2.y-pline*sin(alpha+PI/3);new_count.push_back(counti);new_count.push_back(p1);new_count.push_back(pmid);new_count.push_back(p2);new_count.push_back(counti);count.clear();count=new_count;/之前要清空voidmyDisplay()glClear(GL_CO

14、LOR_BUFFER_BIT);switch(m)case0:case1:case2:case3:case4:case5:case6:case7:case8:case9:case10:Draw_pic(count);break;default:break;glFlush();voidKeyboard(unsignedcharkey,intx,inty)if(key=)+m;Calculate_point(count);glutPostRedisplay();intmain(intargc,char*argv)first_state(count);glutInit(&argc,argv);glu

15、tInitDisplayMode(GLUT_RGB|GLUT_SINGLE);glutInitWindowPosition(100,100);glutInitWindowSize(400,400);glutCreateWindowC直線Kock曲線”);glutDisplayFunc(&myDisplay);glutKeyboardFunc(Keyboard);/鍵盤(pán)響應(yīng)回調(diào)函數(shù)glutMainLoop();return0;4以三角形為初始生成元的Kock曲線#include#include#include#include#definePI3.1415926usingnamespacestd;

16、structPointfloatx;floaty;staticvectorcount1,count2,count3;constPointfirst=-0.5f,0.1f,end=0.5f,0.1f,second=0.0f,-0.766f;staticintm=0;/迭代次數(shù)floatline;voidfirst_state(vector&count1,vector&count2,vector&count3)/初始情況是只有兩個(gè)點(diǎn)line=sqrt(pow(first.x-end.x,2)+pow(first.y-end.y,2);count1.push_back(first);count1.p

17、ush_back(end);count2.push_back(end);count2.push_back(second);count3.push_back(second);count3.push_back(first);voidDraw_pic(vector&count1)for(vector:size_typei=0;i!=(count1.size()-1);i+)glBegin(GL_LINES);glVertex2f(count1i.x,count1i.y);glVertex2f(count1i+1.x,count1i+1.y);glEnd();for(vector:size_typej

18、=0;j!=(count2.size()-1);j+)glBegin(GL_LINES);glVertex2f(count2j.x,count2j.y);glVertex2f(count2j+1.x,count2j+1.y);glEnd();for(vector:size_typek=0;k!=(count3.size()-1);k+)glBegin(GL_LINES);glVertex2f(count3k.x,count3k.y);glVertex2f(count3k+1.x,count3k+1.y);glEnd();voidCalculate_point(vector&count1)vec

19、tornew_count;floatpline=line/(float)pow(float)3,(int)m);vector:size_typei;for(i=0;i!=(count1.size()-1);i+)Pointp1,p2,pmid;p1.x=count1i.x+(count1i+1.x-count1i.x)/3;p1.y=count1i.y+(count1i+1.y-count1i.y)/3;p2.x=count1i+1.x-(count1i+1.x-count1i.x)/3;p2.y=count1i+1.y-(count1i+1.y-count1i.y)/3;/markcount

20、i+1.x=count1i.y)alpha=atan(double)(count1i+1.y-count1i.y)/(count1i+1.x-count1i.x);if(count1i+1.xcount1i.x)pmid.x=p1.x+pline*cos(alpha+PI/3);pmid.y=p1.y+pline*sin(alpha+PI/3);elsepmid.x=p1.x-pline*cos(alpha+PI/3);pmid.y=p1.y-pline*sin(alpha+PI/3);elsealpha=atan(double)(count1i.y-count1i+1.y)/(count1i+1.x-count1i.x);if(count1i+1.xcount1i.x)pmid.x=p2.x-pline*cos(alpha+PI/3);pmid.y=p2.y+pline*sin(alpha+PI/3);elsepmid.x=p2.x+pline*cos(alpha+PI/3);pmid.y=p2.y-pline*sin(alpha+PI/3);new_count.push_back(count1i);new_count.push_back(p1);new_count.push_back(pmid);new_count.push_back(p2);new_count.p

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論