Graphics Lab Report - 2
Graphics Lab Report - 2
Institute of Engineering
Thapathali Campus, Thapathali
Submitted by:
Name: Atul Shreewastav
Roll No.: THA077BCT013
Submitted to:
Department of Electronics and Computer Engineering
Date: 19th July, 2023
Mid-point Ellipse Drawing Algorithm
Title: To use draw and reflect a triangle about x and y axes.
Theory:
Midpoint ellipse algorithm plots(finds) points of an ellipse on the first quadrant by dividing the
quadrant into two regions.
Each point(x, y) is then projected into the other three quadrants (-x, y), (x, -y), (-x, -y) i.e. it uses
4-way symmetry.
Decision parameter:
Initially, we have two decision parameters p10 in region 1 and p20 in region 2.
p10=ry2+1/4rx2-rx2ry
• Take the input radius along the x axis and y axis and obtain the center of the ellipse.
• Initially, we assume the ellipse to be centered at the origin and the first point as : (x, y0)=
(0, ry).
• Obtain the initial decision parameter for region 1 as: p10=ry2+1/4rx2-rx 2ry
• For every xk position in region 1 :
If p1k<0 then the next point along the is (xk+1 , yk) and p1k+1=p1k+2ry2xk+1+ry2
• Obtain the initial value in region 2 using the last point (x0, y0) of region 1 as:
p20=ry2(x0+1/2)2+rx2 (y0-1)2-rx2ry2
• At each yk in region 2 starting at k =0 perform the following task.
#include<stdio.h>
#include<math.h>
#include<graphics.h>
Conclusion:
Thus, as shown in the program above, we can draw an ellipse using the various functions
available in the graphics.h header file.
Translation and Scaling
Title: To use translate and scale a given triangle.
Theory:
Translation:
A translation process moves every point a constant distance in a specified direction. It can be
described as a rigid motion. A translation can also be interpreted as the addition of a constant vector
to every point, or as shifting the origin of the coordinate system.
Whenever we perform translation of any object we simply translate its each and every point. Some
of basic objects along with their translation can be drawn as:
1. Point Translation P(X, Y) : Here we only translate the x and y coordinates of given point
as per given translation factor dx and dy respectively.
2. Line Translation: The idea to translate a line is to translate both of the end points of the
line by the given translation factor(dx, dy) and then draw a new line with inbuilt graphics
function.
3. Rectangle Translation : Here we translate the x and y coordinates of both given points
A(top left ) and B(bottom right) as per given translation factor dx and dy respectively and
then draw a rectangle with inbuilt graphics function
Scaling:
A scaling transformation alters size of an object. In the scaling process, we either compress or
expand the dimension of the object.
Scaling operation can be achieved by multiplying each vertex coordinate (x, y) of the polygon by
scaling factor sx and sy to produce the transformed coordinates as (x’, y’).
Or P’ = S . P
If the scaling factor S is less than 1, then we reduce the size of the object. If the scaling factor S is
greater than 1, then we increase size of the objec
Source Code (Translation & Scaling of a Triangle):
#include<stdio.h>
#include<math.h>
#include<graphics.h>
int main(){
// Initializing graphics variables
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
setbkcolor(WHITE);
cleardevice();
// Initializing drawing variables
int x1=100, x2=150, x3=200, y1=50, y2=200, y3=20;
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x1,y1);
delay(1000);
line(x1,y1,x2,y2);
line(x2,y2,x3,y3);
line(x3,y3,x1,y1);
Conclusion:
Thus, as shown in the program above, we can draw, translate and scale a triangle using the
various functions available in the graphics.h header file.
Source Code (Moving Car):
#include<graphics.h>
#include<stdio.h>
delay(100);
int main(){
draw_moving_car();
return 0;
}
Output:
Conclusion:
Thus, as shown in the program above, we can draw, translate a car and make it appear as it is
moving by erasing the previous car using the various functions available in the graphics.h header
file.