TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Computer Graphics | Point Clipping

Computer Graphics | Point Clipping with Computer Graphics Tutorial, Line Generation Algorithm, 2D Transformation, 3D Computer Graphics, Types of Curves, Surfaces, Computer Animation, Animation Techniques, Keyframing, Fractals etc.

<< Back to COMPUTER

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:

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
inttlx,tly,brx,bry,px,py;
void point_clip()
{
intwxmin,wymin,wxmax,wymax;
wxmin=tlx;
wxmax=brx;
wymin=tly;
wymax=bry;
if(px>=wxmin&&px<=wxmax)
if(py>=wymin&&py<=wymax)
putpixel(px,py,RED);
getch();
closegraph();
}
void main()
{ 
intgd=DETECT,gm,xc,yc,r;
clrscr();
printf("Enter the top left coordinate");
scanf("%d%d",&tlx,&tly);
printf("Enter the bottom right coordinate");
scanf("%d%d",&brx,&bry);
printf("\n Enter the point");
scanf("%d%d",&px,&py);
initgraph(&gd,&gm,"c:\\tc\\bgi");
setbkcolor(BLUE);
setcolor(RED);
rectangle(tlx,tly,brx,bry);
point_clip();
}

Output:

Point Clipping
Point Clipping

Program2:

To implement point clipping with respect to rectangular window:

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
        int gm,gr,xcmin,ycmin,xcmax,ycmax,x,y,c;
        clrscr();
        detectgraph(&gm,&gr);
        initgraph(&gm,&gr,"c:\\tc\\BGI");
          printf("Enter the clipmin coordinate :\n");
          scanf("%d%d",&xcmin,&ycmin);
          printf("Enter the clipmax coordinate :\n");
          scanf("%d%d",&xcmax,&ycmax);
          rectangle(xcmin,ycmax,xcmax,ycmin);
          printf("Enter the coordinate of the point:\n");
          scanf("%d%d",&x,&y);
          detectgraph(&gm,&gr);
          initgraph(&gm,&gr,"c:\\tc\\BGI");
          putpixel(x,y,15);
          printf("\n1.Point clipping\n2.Exit\nEnter your choice:\n");
           scanf("%d",&c);
           switch(c)
     {
           case 1:
          detectgraph(&gm,&gr);
          initgraph(&gm,&gr,"d:\\tc\\BGI");
          rectangle (xcmin,ycmax,xcmax,ycmin);
          printf("*******POINT CLIPPING******\n");
          if ((xcmin<x) && (x<xcmax))
      {
         if ((ycmin<y) && (y<ycmax))
        {
          printf("The point is inside the clip window\n");
           putpixel(x,y,15);
        }
     }
          else
          printf("The point is outside the clipwindow \nThe point is clipped\n");
          break;
         case 2: exit(0);
    }
         getch();
}

Output:

Point Clipping
Point Clipping
Point Clipping
Next TopicLine Clipping




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf