📜  计算机图形学|点裁剪

📅  最后修改于: 2020-12-21 00:43:28             🧑  作者: Mango

截点:

点剪辑用于确定该点是否在窗口内。为此,检查以下条件。

  • x≤x最大值
  • x≥x分钟
  • y≤y max
  • y≥y分钟

(x,y)是该点的坐标。如果以上不等式中的任何一个为假,则该点将落在窗口之外,并且不会被视为可见。

程序1:

要实现切点:

#include
#include
#include
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();
}

输出:


程序2:

要针对矩形窗口实现点裁剪:

#include
#include
#include
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

输出: