# Point Clipping Algorithm in Computer Graphics

Clipping: In computer graphics our screen act as a 2-D coordinate system. it is not necessary that each and every point can be viewed on our viewing pane(i.e. our computer screen). We can view points, which lie in particular range (0,0) and (Xmax, Ymax). So, clipping is a procedure that identifies those portions of a picture that are either inside or outside of our viewing pane.
In case of point clipping, we only show/print points on our window which are in range of our viewing pane, others points which are outside the range are discarded.
Example

```Input :

Output :

```

Point Clipping Algorithm:

1. Get the minimum and maximum coordinates of both viewing pane.
2. Get the coordinates for a point.
3. Check whether given input lies between minimum and maximum coordinate of viewing pane.
4. If yes display the point which lies inside the region otherwise discard it.
5.  `// C program for point clipping Algorithm ` `#include ` `//#include ` ` ` `// Function for point clipping ` `void` `pointClip(``int` `XY[][2], ``int` `n, ``int` `Xmin, ``int` `Ymin, ` `                                   ``int` `Xmax, ``int` `Ymax) ` `{ ` `    ``/*************** Code for graphics view ` `    ``// initialize graphics mode ` `    ``detectgraph(&gm,&gr); ` `    ``initgraph(&gm,&gr,"d:\\tc\\BGI"); ` `    ``for (int i=0; i= Xmin) && (XY[i][0] <= Xmax)) ` `    ``{ ` `            ``if ( (XY[i][1] >= Ymin) && (XY[i][1] <= Ymax)) ` `        ``putpixel(XY[i][0],XY[i][1],3); ` `    ``} ` `    ``} ` `    ``**********************/` `    ``/**** Arithmetic view ****/` `    ``printf` `(``"Point inside the viewing pane:\n"``); ` `    ``for` `(``int` `i=0; i= Xmin) && (XY[i][0] <= Xmax)) ` `        ``{ ` `            ``if` `((XY[i][1] >= Ymin) && (XY[i][1] <= Ymax)) ` `                ``printf` `(``"[%d, %d] "``, XY[i][0], XY[i][1]); ` `        ``} ` `    ``} ` ` ` `    ``// print point coordinate outside viewing pane ` `    ``printf` `(``"\nPoint outside the viewing pane:\n"``); ` `    ``for` `(``int` `i=0; i Xmax)) ` `            ``printf` `(``"[%d, %d] "``, XY[i][0], XY[i][1]); ` `        ``if` `((XY[i][1] < Ymin) || (XY[i][1] > Ymax)) ` `            ``printf` `(``"[%d, %d] "``, XY[i][0], XY[i][1]); ` `    ``} ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` `    ``int` `XY[6][2] = {{10,10}, {-10,10}, {400,100}, ` `                    ``{100,400}, {400,400}, {100,40}}; ` ` ` `    ``// getmaxx() & getmaxy() will return Xmax, Ymax ` `    ``// value if graphics.h is included ` `    ``int` `Xmin = 0; ` `    ``int` `Xmax = 350; ` `    ``int` `Ymin = 0; ` `    ``int` `Ymax = 350; ` `    ``pointClip(XY, 6,  Xmin, Ymin, Xmax, Ymax); ` `    ``return` `0; ` `} `

Output:

```Point inside the viewing pane:
[10, 10] [100, 40]

Point outside the viewing pane:
[-10, 10] [400, 100] [100, 400] [400, 400] [400, 400]```