// C# program for point clipping Algorithm
using System;
class GFG
{
// Function for point clipping
static void pointClip(int [,]XY, 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<n; i++)
{
if ( (XY[i,0] >= Xmin) && (XY[i,0] <= Xmax))
{
if ( (XY[i,1] >= Ymin) && (XY[i,1] <= Ymax))
putpixel(XY[i,0],XY[i,1],3);
}
}
**********************/
/**** Arithmetic view ****/
Console.Write("Point inside the viewing pane:\n");
for (int i = 0; i < n; i++)
{
if ((XY[i, 0] >= Xmin) && (XY[i, 0] <= Xmax))
{
if ((XY[i, 1] >= Ymin) && (XY[i, 1] <= Ymax))
Console.Write("[{0}, {1}] ", XY[i, 0], XY[i, 1]);
}
}
// print point coordinate outside viewing pane
Console.Write("\nPoint outside the viewing pane:\n");
for (int i = 0; i < n; i++)
{
if ((XY[i, 0] < Xmin) || (XY[i, 0] > Xmax))
Console.Write("[{0}, {1}] ", XY[i, 0], XY[i, 1]);
if ((XY[i, 1] < Ymin) || (XY[i, 1] > Ymax))
Console.Write("[{0}, {1}] ", XY[i, 0], XY[i, 1]);
}
}
// Driver code
public static void Main(String[] args)
{
int [,]XY = {{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);
}
}
// This code contributed by Rajput-Ji