Bresnehm Algorithm (CG)

Bresnehm Algorithm (CG)

We can Draw the Line or Circle using Bresnehm circle easily. So it is very useful and popular algorithm in computer graphic field.

Line algorithm for Bresnehm is valid for slope less then 1.

This page Contain Link of pdf of Bresnehm Line and circle.

Link for Bresnehm Line :
Click Here


Link for Bresnehm Circle:
Click Here

Scaling Program

Scaling Program

//Write a program for the Scaling of Triangle

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
int x1,x2,x3,y1,y2,y3,sx,sy,i;
initgraph(&gd,&gm,"..\\bgi");
printf("Enter the first co-ordinate:");
scanf("%d%d",&x1,&y1);
printf("Enter the second co-ordinate:");
scanf("%d%d",&x2,&y2);
printf("Enter the third co-ordinate:");
scanf("%d%d",&x3,&y3);
cleardevice();
//printf("Traingle before scaling:\n\n\n");
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x1,y1);
getch();
cleardevice();
printf("\nProvide value of Scalinf factor:");
scanf("%d%d",&sx,&sy);
x1=x1*sx;
x2=x2*sx;
x3=x3*sx;
y1=y1*sy;
y2=y2*sy;
y3=y3*sy;
cleardevice();
printf("\nTraingle after scaling:");
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x1,y1);
getch();
closegraph();
}

//This code was  compile in turboc.
For Query and any doubt please leave your comments.
Reflection Program(CG)

Reflection Program(CG)

//Write a program for Reflection of Triangle.

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>

int main()
{
int gdriver=DETECT,gmode;
int x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6;
    float theta;
initgraph(&gdriver,&gmode,"..//BGI");
cleardevice();
printf("\n Enter first  coordinates of triangle:");
scanf("%d%d",&x4,&y4);
printf("\n Enter second  coordinates of triangle:");
scanf("%d%d",&x5,&y5);
printf("\n Enter third  coordinates of triangle:");
scanf("%d%d",&x6,&y6);
x1=320+x4;
y1=240-y4;
x2=320+x5;
y2=240-y5;
x3=320+x6;
y3=240-y6;
getch();
cleardevice();
line(320,0,320,480);
line(0,240,640,240);
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x1,y1,x3,y3);
y1+=2*y4;
y2+=2*y5;
y3+=2*y6;
printf("Traingle after Reflection :\n");
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x1,y1,x3,y3);
x1-=2*x4;
y1=240-y4;
x2-=2*x5;
y2=240-y5;
x3-=2*x6;
y3=240-y6;
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x1,y1,x3,y3);
closegraph();
}


//this code is compile in Turbo c
Program for Translation (CG)

Program for Translation (CG)

// Write  a program for Translation Of Triangle.

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm,x1,x2,x3,y1,y2,y3,tx,ty;
initgraph(&gd,&gm,"..\\bgi");
printf("\nEnter the first Coordinate : ");
scanf("%d%d",&x1,&y1);
printf("\nEnter the second Coordinate : ");
scanf("%d%d",&x2,&y2);
printf("\nEnter the third Coordinate : ");
scanf("%d%d",&x3,&y3);
cleardevice();
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x1,y1);
getch();
cleardevice();
printf("\nEnter the Trasformation Factor : ");
scanf("%d%d",&tx,&ty);
x1=x1+tx;
x2=x2+tx;
x3=x3+tx;
y1=y1+ty;
y2=y2+ty;
y3=y3+ty;
cleardevice();
printf("\nTriangle After Trasformation :\n ");
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x1,y1);
getch();
closegraph();
}

//This code is complie in turbo c.




Powered by Blogger.

Popular Posts