1 / 18

Computer Graphics Line Drawing Functions Point structure

Computer Graphics Line Drawing Functions Point structure. Asima Latif 19-Nov-2009. Main Mile stones that we will cover in this course Basic Concepts Basic Shapes, Line Drawing Algorithms Projection / Display of Graphics Transformation Parametric Equations Graphics Pipeline OpenGL

keisha
Download Presentation

Computer Graphics Line Drawing Functions Point structure

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Computer GraphicsLine Drawing FunctionsPoint structure Asima Latif 19-Nov-2009

  2. Main Mile stones that we will cover in this course • Basic Concepts • Basic Shapes, Line Drawing Algorithms • Projection / Display of Graphics • Transformation • Parametric Equations • Graphics Pipeline OpenGL • Two dimensional Graphics • 3D Graphics

  3. Book / Other Material • Computer Graphics FS Hill or the hevern one • Turbo C++ remember that there is a BGI folder • Visual C++ , OpenGL GLUT Library • Java3D optional

  4. Origin – Center of the screen • To get the center of the screen • We have two functions • Getmaxx() • Getmaxy() • Center of Screen • Int cx = getmaxx()/2; • Int cy = getmaxy()/2;

  5. Complete Program with cx, cy int main(void) { int gdriver = DETECT, gmode; initgraph(&gdriver, &gmode, "\\tc\\bgi"); int radius=100; Int cx=getmaxx()/2; Int cy=getmaxy()/2; circle(cx, cy, radius); getch(); closegraph(); }

  6. Drawing Lines .. 1 Line(int x1,int y1,int x2, int y2); • Draws a line between (x1,y1) AND (x2,y2) int main(void) { int gdriver = DETECT, gmode; initgraph(&gdriver, &gmode, "\\tc\\bgi"); Line(cx,cy,cx+200,cy); getch(); closegraph(); }

  7. Drawing Lines .. 1 int main(void) { int gdriver = DETECT, gmode; initgraph(&gdriver, &gmode, "\\tc\\bgi"); Line(cx,cy,cx+200,cy); Line(cx,cy,cx,cy-200); getch(); closegraph(); }

  8. Drawing Line …2 • Linerel(int dx, int dy) • Draws a line from the current position to the distance dx, and dy • Curret Position CP is achived through using the function moveto(int x, int y);

  9. Drawing Lines .. 2 int main(void) { int gdriver = DETECT, gmode; initgraph(&gdriver, &gmode, "\\tc\\bgi"); Moveto(cx,cy); Linerel(200,0); getch(); closegraph(); }

  10. Drawing Lines .. 3 • Lineto(int x, int y) • Draws a line from the current position to the given point.

  11. Drawing Lines .. 3 int main(void) { int gdriver = DETECT, gmode; initgraph(&gdriver, &gmode, "\\tc\\bgi"); Moveto(cx,cy); Lineto(100,200); getch(); closegraph(); }

  12. Line Drawing AlgorithmDigital Differential Analyzer

  13. DDA void lineDDA(int xa,int ya,int xb,int yb) { int dx,dy,steps; dx=xb-xa; dy=yb-ya; float xincrement,yincrement,x,y; if (abs(dx)>abs(dy)) steps=abs(dx); else steps=abs(dy); xincrement=dx/steps; yincrement=dy/steps; x=xa,y=ya; putpixel(round(x),round(y),2); for (int k=1;k<=steps;k++) { x=x+xincrement; y=y+yincrement; putpixel(round(x),round(y),2); } }

  14. Main function void main() { int driver=DETECT,mode; initgraph(&driver,&mode,"C:\\tc\\bgi"); lineDDA(100,100,401,401); getch(); closegraph(); }

  15. LINE MIDPOINT ALGORITHM(BRESHMAN ALGORITHM • void main() • { • int gd=DETECT,gm,x0,y0,x1,y1,dx,dy,d,x,y,c1,c2; • initgraph(&gd,&gm,"c:\\tc\\bgi"); • clrscr(); • cout<<"\t\tMID POINT ALGORITHM FOR LINE\n"; • cout<<"\n enter initial coordinates\t"; • cin>>x0>>y0; • cout<<"\nenter final coordinates\t\t"; • cin>>x1>>y1;

  16. while(x<=x1) { X++; if(d<=0) { d+=c1; } else { d+=incrne; y++; } putpixel(x,y,RED); } } dx=x1-x0; dy=y1-y0; d=2*dy-dx; c1=2*dy; c2=2*(dy-dx); if(x1>x0) { x=x0; y=y0; putpixel(x,y,RED);

  17. else { x=x0; y=y0; putpixel(x,y,YELLOW); while(x>=x1) { if(d<=0) { d-=c1; x--; } else { d-=c2; x--; y--; } putpixel(x,y,RED); } } getch(); closegraph(); }

  18. That’s all for Today

More Related