Computer Science Related Others Courses AvailableThe Best Codder.blogspot.com

Point Clipping

 

Point Clipping:

Point Clipping is used to determining, whether the point is inside the window or not. For this following conditions are checked.

  1. x ≤ xmax
  2. x ≥ xmin
  3. y ≤ ymax
  4. y ≥ ymin

“Point clipping is a process which is used to define the point position.” The point is either inside the view pane (window) or outside the view pane.

In computer graphics, the computer screen work like a two-dimensional coordinate system. Each point does not need to be displayed inside the computer screen.

It includes two terms-

  • Window: It means what to display?
  • Clipping: It means discarding the portion that is outside the window.

Example: Let us have a view pane (window). The coordinates of the window are-

(xwmax, xwmin) - For X-axis of the window

(ywmax, ywmin) - For Y-axis of the window    

Let us assume a point coordinate (P, Q). If the point lies inside the window, then there is no need to perform point clipping. But if the point lies outside the window, we need to perform clipping. We can understand it by the following equation-

xwmax <= P <= xwmin

ywmax <= Q <= ywmin

There are four conditions; if these four are satisfied, then the point lies inside the window. If anyone condition is not satisfied, then the point lies outside the window, it means we have to perform clipping on the point.

xwmin <= P

xwmax => P

ywmin <= Q

ywmax => Q

Point Clipping

The (x, y) is coordinate of the point. If anyone from the above inequalities is false, then the point will fall outside the window and will not be considered to be visible.

Program1:

To implement Point Clipping:

  1. #include<stdio.h>  
  2. #include<conio.h>  
  3. #include<graphics.h>  
  4. inttlx,tly,brx,bry,px,py;  
  5. void point_clip()  
  6. {  
  7. intwxmin,wymin,wxmax,wymax;  
  8. wxmin=tlx;  
  9. wxmax=brx;  
  10. wymin=tly;  
  11. wymax=bry;  
  12. if(px>=wxmin&&px<=wxmax)  
  13. if(py>=wymin&&py<=wymax)  
  14. putpixel(px,py,RED);  
  15. getch();  
  16. closegraph();  
  17. }  
  18. void main()  
  19. {   
  20. intgd=DETECT,gm,xc,yc,r;  
  21. clrscr();  
  22. printf("Enter the top left coordinate");  
  23. scanf("%d%d",&tlx,&tly);  
  24. printf("Enter the bottom right coordinate");  
  25. scanf("%d%d",&brx,&bry);  
  26. printf("\n Enter the point");  
  27. scanf("%d%d",&px,&py);  
  28. initgraph(&gd,&gm,"c:\\tc\\bgi");  
  29. setbkcolor(BLUE);  
  30. setcolor(RED);  
  31. rectangle(tlx,tly,brx,bry);  
  32. point_clip();  
  33. }  

Output:

Point Clipping
Point Clipping

Program2:

To implement point clipping with respect to rectangular window:

  1. #include<stdio.h>  
  2. #include<conio.h>  
  3. #include<graphics.h>  
  4. void main()  
  5. {  
  6.         int gm,gr,xcmin,ycmin,xcmax,ycmax,x,y,c;  
  7.         clrscr();  
  8.         detectgraph(&gm,&gr);  
  9.         initgraph(&gm,&gr,"c:\\tc\\BGI");  
  10.           printf("Enter the clipmin coordinate :\n");  
  11.           scanf("%d%d",&xcmin,&ycmin);  
  12.           printf("Enter the clipmax coordinate :\n");  
  13.           scanf("%d%d",&xcmax,&ycmax);  
  14.           rectangle(xcmin,ycmax,xcmax,ycmin);  
  15.           printf("Enter the coordinate of the point:\n");  
  16.           scanf("%d%d",&x,&y);  
  17.           detectgraph(&gm,&gr);  
  18.           initgraph(&gm,&gr,"c:\\tc\\BGI");  
  19.           putpixel(x,y,15);  
  20.           printf("\n1.Point clipping\n2.Exit\nEnter your choice:\n");  
  21.            scanf("%d",&c);  
  22.            switch(c)  
  23.      {  
  24.            case 1:  
  25.           detectgraph(&gm,&gr);  
  26.           initgraph(&gm,&gr,"d:\\tc\\BGI");  
  27.           rectangle (xcmin,ycmax,xcmax,ycmin);  
  28.           printf("*******POINT CLIPPING******\n");  
  29.           if ((xcmin<x) && (x<xcmax))  
  30.       {  
  31.          if ((ycmin<y) && (y<ycmax))  
  32.         {  
  33.           printf("The point is inside the clip window\n");  
  34.            putpixel(x,y,15);  
  35.         }  
  36.      }  
  37.           else  
  38.           printf("The point is outside the clipwindow \nThe point is clipped\n");  
  39.           break;  
  40.          case 2: exit(0);  
  41.     }  
  42.          getch();  
  43. }  

Output:

Point Clipping
Point Clipping
Point Clipping

Post a Comment

© Computer Graphics. The Best Codder All rights reserved. Distributed by