Here are the steps to implement Sutherland-Hodgman polygon clipping algorithm:1. Take the subject polygon vertices as input and store them in an array. 2. Also take the clipping window coordinates (xmin, ymin, xmax, ymax) as input.3. Initialize an output array to store the clipped polygon vertices. 4. For each edge of the subject polygon: 4.1. Call the clipping functions clipl(), clipt(), clipr(), clipb() to clip the edge against left, top, right and bottom clipping lines respectively. 4.2. These functions will calculate the intersection points of the edge with the clipping lines and add them to the output array if the
According to NU of Bangladesh for BSC Hons in CSE 6th semester, here you can find the solution about this subject according to the board question respectively.
Mathematics Towards Elliptic Curve Cryptography-by Dr. R.Srinivasan
Similar to Here are the steps to implement Sutherland-Hodgman polygon clipping algorithm:1. Take the subject polygon vertices as input and store them in an array. 2. Also take the clipping window coordinates (xmin, ymin, xmax, ymax) as input.3. Initialize an output array to store the clipped polygon vertices. 4. For each edge of the subject polygon: 4.1. Call the clipping functions clipl(), clipt(), clipr(), clipb() to clip the edge against left, top, right and bottom clipping lines respectively. 4.2. These functions will calculate the intersection points of the edge with the clipping lines and add them to the output array if the
The Ring programming language version 1.7 book - Part 63 of 196Mahmoud Samir Fayed
Similar to Here are the steps to implement Sutherland-Hodgman polygon clipping algorithm:1. Take the subject polygon vertices as input and store them in an array. 2. Also take the clipping window coordinates (xmin, ymin, xmax, ymax) as input.3. Initialize an output array to store the clipped polygon vertices. 4. For each edge of the subject polygon: 4.1. Call the clipping functions clipl(), clipt(), clipr(), clipb() to clip the edge against left, top, right and bottom clipping lines respectively. 4.2. These functions will calculate the intersection points of the edge with the clipping lines and add them to the output array if the (20)
Here are the steps to implement Sutherland-Hodgman polygon clipping algorithm:1. Take the subject polygon vertices as input and store them in an array. 2. Also take the clipping window coordinates (xmin, ymin, xmax, ymax) as input.3. Initialize an output array to store the clipped polygon vertices. 4. For each edge of the subject polygon: 4.1. Call the clipping functions clipl(), clipt(), clipr(), clipb() to clip the edge against left, top, right and bottom clipping lines respectively. 4.2. These functions will calculate the intersection points of the edge with the clipping lines and add them to the output array if the
1. SECTION-A:::::::::::::::::
PROGRAM-1::::::::::::::
Program Title:
Write a program to implement DDA line drawing algorithm.
Source Code:
#include <windows.h>
#include <gl/glut.h>
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_POINTS);
int x1 = 10, y1 = 10, x2 = 100, y2 = 100, x, y, xend, dx, dy;
float m, b;
dx = x2 -x1;
dy = y2 -y1;
m = dy / dx;
b = y1 - m*x1;
if(dx < 0) {
x = x2;
y = y2;
xend = x1;
} else {
x = x1;
y = y1;
xend = x2;
}
while(x < xend){
glVertex2i(x,y);
x = x+1;
y = m * x + b;
}
glEnd();
glFlush();
}
2. int main(int argc,char *argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100, 100);
glutCreateWindow ("points");
glClearColor(0,0,0,0.0);
glMatrixMode (GL_PROJECTION);
gluOrtho2D (0.0, 200.0, 0.0, 150.0);
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
Output:
PROGRAM-2::::::::::::::
Program Title:
Write a program to implement Bresenhams line drawing algorithm.
Source Code:
#include <windows.h>
15. {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(50, 100);
glutInitWindowSize(500, 500);
glutCreateWindow("House Section OpenGL");
init();
glutDisplayFunc(buildHouse);
glutMainLoop();
return 0;
}
Output:
Hay listen carefully, don’t draw this home with your own color, just use pencil.
16. SECTION-B:::::::::::::::::
PROGRAM-1::::::::::::::
Program Title:
Write a program to implement Cohen Sutherland Line Clipping algorithm.
Source Code:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<graphics.h>
#include<dos.h>
typedef struct coordinate
{
int x,y;
char code[4];
}PT;
void drawwindow();
void drawline(PT p1,PT p2);
PT setcode(PT p);
int visibility(PT p1,PT p2);
PT resetendpt(PT p1,PT p2);
int main()
{
int gd=DETECT,v,gm;
PT p1,p2,p3,p4,ptemp;
17. printf("nEnter x1 and y1n");
scanf("%d %d",&p1.x,&p1.y);
printf("nEnter x2 and y2n");
scanf("%d %d",&p2.x,&p2.y);
initgraph(&gd,&gm,"c:turboc3bgi");
drawwindow();
delay(500);
drawline(p1,p2);
delay(500);
cleardevice();
delay(500);
p1=setcode(p1);
p2=setcode(p2);
v=visibility(p1,p2);
delay(500);
switch(v)
{
case 0: drawwindow();
delay(500);
drawline(p1,p2);
break;
case 1: drawwindow();
29. Output:
PROGRAM-3::::::::::::::
Program Title:
Write a program to implement Window to Viewport transformation.
Source Code:
#include<stdio.h>
#include<conio.h>
#include<dos.h>
#include<graphics.h>
#include<math.h>
int main()
{
int xwmin,ywmin,xwmax,ywmax,xv1,yv1;
int xvmin,xvmax,yvmin,yvmax,xw,yw,xv,yv;
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
printf("Enter the window coordinates xwmin,xwmax,ywmin,ywmaxn");
scanf("%dt%dt%dt%d",&xwmin,&xwmax,&ywmin,&ywmax);
line(xwmin-25,xwmin-25,xwmin-25,ywmax+50);
line(xwmin-40,ywmax+25,xwmax+50,ywmax+25);
outtextxy(xwmin+5,ywmax+5,"Window");
line(xwmin,ywmin,xwmin,ywmax);
line(xwmin,ywmax,xwmax,ywmax);
31. Output:
PROGRAM-4::::::::::::::
Program Title:
Write a program to implement the following 2D transformations:-
a) Translation
b) Scaling
c) Rotation
Source Code:
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include<math.h>
int main()
{
int gm;
int gd=DETECT;
int x1,x2,x3,y1,y2,y3,nx1,nx2,nx3,ny1,ny2,ny3,c;
int sx,sy,xt,yt,r;
32. float t;
initgraph(&gd,&gm,"c:tcbg:");
printf("t Program for basic transactions");
printf("nt Enter the points of triangle");
setcolor(1);
scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3);
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x1,y1);
getch();
printf("n 1.Transactionn 2.Rotationn 3.Scallingn 4.exit");
printf("Enter your choice:");
scanf("%d",&c);
switch(c)
{
case 1:
printf("n Enter the translation factor");
scanf("%d%d",&xt,&yt);
nx1=x1+xt;
ny1=y1+yt;
nx2=x2+xt;
ny2=y2+yt;
nx3=x3+xt;
ny3=y3+yt;
line(nx1,ny1,nx2,ny2);
line(nx2,ny2,nx3,ny3);
line(nx3,ny3,nx1,ny1);
33. getch();
case 2:
printf("n Enter the angle of rotation");
scanf("%d",&r);
t=3.14*r/180;
nx1=abs(x1*cos(t)-y1*sin(t));
ny1=abs(x1*sin(t)+y1*cos(t));
nx2=abs(x2*cos(t)-y2*sin(t));
ny2=abs(x2*sin(t)+y2*cos(t));
nx3=abs(x3*cos(t)-y3*sin(t));
ny3=abs(x3*sin(t)+y3*cos(t));
line(nx1,ny1,nx2,ny2);
line(nx2,ny2,nx3,ny3);
line(nx3,ny3,nx1,ny1);
getch();
case 3:
printf("n Enter the scalling factor");
scanf("%d%d",&sx,&sy);
nx1=x1*sx;
ny1=y2*sy;
nx2=x2*sx;
ny2=y2*sy;
nx3=x3*sx;
ny3=y3*sy;
line(nx1,ny1,nx2,ny2);
35. Output:
PROGRAM-5::::::::::::::
Program Title:
Write a program to draw a triangle and rotate about the pivot point.
Source Code:
#include<graphics.h>
#include<conio.h>
#include<stdio.h>
#include<math.h>
int main()
{
int gd=DETECT,gm;
int i,xmid,ymid,x1,y1,x2,y2,x3,y3,x,y,dy,dx,p,gap=50,temp,xr,yr;
int x1dash,y1dash,x2dash,y2dash,x3dash,y3dash;
float m;
double theta;
char str[5];
//clrscr();
initgraph(&gd,&gm,"..bgi");
printf("Enter first co-ords of the trianglen");
36. scanf("%d %d",&x1,&y1);
printf("Enter second co-ords of the trianglen");
scanf("%d %d",&x2,&y2);
printf("Enter third co-ords of the trianglen");
scanf("%d %d",&x3,&y3);
xmid= getmaxx()/2;
ymid= getmaxy()/2;
line(5,ymid,getmaxx()-5,ymid);
line(xmid+3,5,xmid+3,getmaxy()-5);
for( i= xmid+gap;i<getmaxx()-5;i=i+gap)
{
outtextxy(i,ymid-3,"|");
//itoa(i-xmid,str,10);
outtextxy(i,ymid+3,str);
}
for( i= ymid-gap;i>5;i=i-gap)
{
outtextxy(xmid,i,"-");
//itoa(ymid-i,str,10);
outtextxy(xmid+5,i,str);
}
for( i= xmid-gap;i>5;i=i-gap)
{
outtextxy(i,ymid-3,"|");
//itoa(-(xmid-i),str,10);
outtextxy(i-6,ymid+3,str);
}
for( i= ymid+gap;i<getmaxy()-5;i=i+gap)
{
outtextxy(xmid,i,"-");
//itoa(-(i-ymid),str,10);
outtextxy(xmid+8,i,str);
}
line(x1+xmid,ymid-y1,x2+xmid,ymid-y2);
line(x2+xmid,ymid-y2,x3+xmid,ymid-y3);
line(x3+xmid,ymid-y3,x1+xmid,ymid-y1);
printf("Enter the degree to rotaten");
37. scanf("%lf",&theta);
theta= ((float) theta *3.14f )/(float)180; // converting theta to radian
printf("Enter the arbitrary point to rotaten");
scanf("%d%d",&xr,&yr);
x1dash=xr+(x1-xr)*cos(theta)-(y1-yr)*sin(theta);
x2dash=xr+(x2-xr)*cos(theta)-(y2-yr)*sin(theta);
x3dash=xr+(x3-xr)*cos(theta)-(y3-yr)*sin(theta);
y1dash=yr+(x1-xr)*sin(theta)+(y1-yr)*cos(theta);
y2dash=yr+(x2-xr)*sin(theta)+(y2-yr)*cos(theta);
y3dash=yr+(x3-xr)*sin(theta)+(y3-yr)*cos(theta);
line(x1dash+xmid,ymid-y1dash,x2dash+xmid,ymid-y2dash);
line(x2dash+xmid,ymid-y2dash,x3dash+xmid,ymid-y3dash);
line(x3dash+xmid,ymid-y3dash,x1dash+xmid,ymid-y1dash);
getch();
closegraph();
}
Input: