## Posts

### C++ Program of Translation of Triangle

Program of Translation of a Triangle(C++)

#include<conio.h> #include<stdio.h> #include<Graphics.h>
voidmain(){ int gd = DETECT,gm; initgraph(&gd,&gm,"C:\\TC\\BGI");
int x1[3]={300,300,200}; int y1[3]={100,100,200}; int x2[3]={200,400,400}; int y2[3]={200,200,200};
int i; for(i=0; i<3; i++) line(x1[i],y1[i],x2[i],y2[i]);
int tx1[3], ty1[3], tx2[3], ty2[3];
int vx,vy; printf(

### Ellipse Using Mid Point Algorithm C++ Program

#include<conio.h>
#include<stdio.h> #include<Graphics.h>
voidmain() { int gd = DETECT,gm; initgraph(&gd,&gm,"C:\\TC\\BGI");
intxc,yc,x,y; longrx,ry; floatd;
printf("Enter Coordinates of Centre of Ellipse: "); scanf("%d%d",&xc,&yc); printf("Enter Radius along X-AXIS: "); scanf("%ld",&rx); printf("Enter Radius along Y-AXIS: "); scanf("%ld",&ry);
//Region 1 d=((ry*ry)-(rx*rx*ry)+(rx*rx))/4; x=0;y=ry;
while(2.0*ry*ry*x < = 2.0*rx*rx*y)

### Bresenham Line Drawing program C++

Bresenham’s Line Drawing Algorithm In bresenham's line drawing algorithm, we find the closest possible points, and then by using those points, we form a line on the computer screen.
This algorithm is an incremental scan conversion line drawing algorithm. It is one of the efficient line drawing algorithms, because it uses integer addition and subtraction and a little bit of multiplication, these operations are easy to perform, that's why we can rapidly use these operations, and quickly form the lines simultaneously.
To further understand the working of bresenham's line drawing algorithm, you can check out the derivation of the bresenham's line drawing algorithm.
Program For Bresenham's Line drawing Algorithm
#include<stdio.h> #include<graphics.h> #include<conio.h>
void main()
{  int gd =DETECT,gm;  initgraph(&gd,&gm,"C:\\TurboC3\\BGI");  int x,x1,y,y1,dx,dy,pk;  printf("Enter first co-ordinates");  scanf(" %d%d",&x,…

### Mid Point Circle Drawing Algorithm

Mid Point Circle Drawing Algorithm
A circle is made up of 8 Equal Octets so we need to find only coordinates of anyone octet rest we can conclude using that coordinates. We took octet-2. Where X and Y will represent the pixel Let us make a function Circle() with parameters coordinates of Centre (Xc, Yc) and pixel point (X, Y) that will plot the pixel on a screen.

We will find pixels assuming that Center is at Origin (0,0) then we will add the coordinates of center to corresponding X and Y while drawing circle on the screen.
Circle (Xc,Yc,X,Y){
Plot (Y+Xc , X+Yc)……Octet-1 Plot (X+Xc , Y+Yc)……Octet-2 Plot (-X+Xc , Y+Yc)……Octet-3 Plot (-Y+Xc , X+Yc)…..Octet-4 Plot (-Y+Xc , -X+Yc)……Octet-5 Plot (-X+Xc , -Y+Yc)

### Mid point Circle Drawing program C++

Mid Point Circle Drawing Program (C++)
#include<conio.h> #include<Graphics.h> #include<stdio.h> voidmain() { intgd = DETECT, gm; initgraph(&gd, &gm, "C:\\TC\\BGI"); intxc, yc, x, y, r, D; printf("Enter Radius of Circle: "); scanf("%d", &r); printf ("Enter coordinates of centre of Circle: "); scanf("%d%d", &xc, &yc);
x=0;y=r;
D=5/4-r; //Initial Decision parameter while (x<=y) { putpixel(y+xc, x+yc, 15 );//……octet-1 putpixel(x+xc, y+yc, 15 ); //……octet-2 putpixel(-x+xc, y+yc, 15 ); //……octet-3 putpixel(-y+xc, x+yc, 15 ); //……octet-4 putpixel(-y+xc, -x+yc, 15 );//……octet-5 putpixel(-x+xc, -y+yc, 15 ); //……octet-6

### Bresenham's Circle Drawing Program (C++)

Bresenham's Circle Drawing C++ Program
#include<conio.h> #include<Graphics.h> #include<stdio.h> voidmain() { intgd = DETECT, gm; initgraph(&gd, &gm, "C:\\TC\\BGI"); intxc, yc, x, y, r, D; printf("Enter Radius of Circle: "); scanf("%d", &r); printf ("Enter coordinates of centre of Circle: "); scanf("%d%d", &xc, &yc); x=0;y=r; D=3-(2*r);//Initial Decision parameter while (x<=y) { putpixel(y+xc, x+yc, 15 );//……octet-1 putpixel(x+xc, y+yc, 15 ); //……octet-2 putpixel(-x+xc, y+yc, 15 ); //……octet-3 putpixel(-y+xc, x+yc, 15 ); //……octet-4 putpixel(-y+xc, -x+yc, 15 );//……octet-5 putpixel(-x+xc, -y+yc, 15 ); //……octet-6 putpixel(x+xc, -y+yc, 15 );//……octet-7