Implementation of Point Clipping Algorithm


//Program to do POINT CLIPPING

#include<iostream.h>

#include<conio.h>

#include<graphics.h>

class  ptclip

{

private:

int x[10],y[10],a[10],b[10],c[10],d[10],n;

public:

void drawrect();

void getpixeldata();

void result();

}clip;

void ptclip::drawrect()

{

int gd=DETECT,gm;

initgraph(&gd,&gm,”ug:\\bcpp\\bgi”);

cout<<“Enter the coordinates of rectangle”;

cin>>x[1]>>y[1]>>x[2]>>y[2];

rectangle(x[1],y[1],x[2],y[2]);

getch();

}

void ptclip::getpixeldata()

{

cout<<“Enter the total nymber of  pixels want to plot:\n:”;

cin>>n;

for(int i=1;i<=n;i++)

{

cout<<“Enter the pixel position(x,y)”<<i<<“;”;

cin>>a[i]>>b[i];

putpixel(a[i],b[i],15);

}

}

void ptclip::result()

{

cleardevice();

cout<<“Result for the point clipping program:”;

rectangle(x[1],y[1],x[2],y[2]);

for(int i=1;i<=n;i++)

if((a[i]<=x[2]&&a[i]>=x[i]&&b[i]<=y[2]&&b[i]>=y[i]))

putpixel(a[i],b[i],15);

getch();

closegraph();

}

void main()

{

clip.drawrect();

clip.getpixeldata();

clip.result();

}

Advertisements