Dark Mode
Image

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

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:

Difference between JDK, JRE, and JVM

  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

Comment / Reply From