C.G.
C.G.
Example: A line with starting point as (0, 0) and ending point (6, 18) is
given. Calculate value of intermediate points and slope of line.
Solution: P1 (0,0) P7 (6,18)
y = 3x + b..............equation (1)
put b = 0 in equation (1)
y = 3x + 0
y = 3x
DDA algorithm
Digital Differential Analyzer
1. Input the two end points of the line segment, (x1,y1) and (x2,y2).
2. Calculate the difference between the x-coordinates and y-coordinates of the
endpoints as dx and dy respectively.
3. Calculate the slope of the line as m = dy/dx.
4. Set the initial point of the line as (x1,y1).
5. Loop through the x-coordinates of the line, incrementing by one each time,
and calculate the corresponding y-coordinate using the equation y = y1 + m.
6. Plot the pixel at the calculated (x,y) coordinate.
7. Repeat steps 5 and 6 until the endpoint (x2,y2) is reached.
m=slope of line
Δy=y2-y1
Δx=x2-x1
M=y2-y1/x2-x1
m>1=(Δy>Δx)
y is increase by one it means y++
xnext=xprevious+1/m
m<1=(Δx>Δy)
x is increase by one it means x++
ynext=Yprevious+m
m=1=(Δy=Δx)
x & y both are increase by one
x++
y++
Ex….Calculate (2,3)(12,10)
Ex….Calculate (5,5)(10,9)
Ex….Calculate (2,3)(6,6)
Ex….Calculate (0,0)(5,8)
Ex…Calculate(2,7)(9,1)
X1=0 y1=0 X2=5 y2=8
Δx=x2-x1 5-0=5
Δy=y2-y1 8-0=8
M=Δy/Δx 8/5=1.6
Y will be increase by one…. it means y++
X y
0 0
Formula= Xprev.=xprev+1/m Formula=y++
x=0+1/1.6 =0+(10/16) =0.62 1
0.62+0.62=1.24 2
1.24+0.62=1.86 3
1.86+0.62=2.48 4
2.48+0.62=3.10 5
3.10+0.62=3.72 6
3.72+0.62=4.32 7
4.32+0.62=4.96 8
Last coordinate of x is=5 & y is 8
Ex….Calculate(1,5)(5,7)
X1=1 y1=5 X2=5 y2=7
Δx=x2-x1 5-1=4
Δy=y2-y1 7-5=2
M=Δy/Δx 2/4=1/2=0.5
Y will be increase by one…. it means y++
X y
1 5
Formula= X++ Formula=yprev.=yprev+1
2 5+0.5=5.5
3 5.5+0.5=6
4 6+0.5=6.5
5 6.5+0.5=7
Last coordinate of x is=5 & y is 7
DDA program
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
float y1,m,y2,x1,x2,k;
initgraph(&gd,&gm,"c:\\turboc3\\bgi");
cin>>x1>>y1>>x2>>y2;
m=(y2-y1)/(x2-x1);
while(x1<=x2)
{
if(m<1)
{
cout<<x1<<"\t"<<y1<<"\n";
putpixel(x1,y1,RED);
x1++;
y1=y1+m;
}
else if(m>1)
{
cout<<x1<<"\t"<<y1<<"\n";
putpixel(x1,y1,RED);
x1=x1+1/m;
y1++;
}
}
getch();
}
Bresenham’s line Drawing Algorithm:-
Algorithm:-
1)Input the two line endpoints and store the left endpoint in(x1,y1)
(20,10,30,18)
Δx=10,Δy=8
Pk=2Δy-Δx=6
1) pk=6 and 6 is positive value
pk=6 xk+1=21 yk+1=11
Pk+1=pk+2Δy-2Δx
Pk+1=6+(2*8)-(2*10)=2
2) pk=2 and 2 is positive value
Pk=2 xk+1=22 yk+1=12
Pk+1=pk+2Δy-2Δx
Pk+1=2+(2*8)-(2*10)=-2
Ex..1 (2,2,10,8)
2 (2,3,18,4)
3 (5,7,17,15)
2D Transformation
1. Translation
2. Rotation
3. Scaling
4. Reflection
5. Shearing
1)Translation:-
it is applied to an object by
repositioning in a long straight line
path.from one coordinate location to
another coordinate position.
It another words whenever we change the
position of two 2D object such that co-
ordinate value change then it is called
translation
It can be performed on 2D object by adding
translation distance to the original co-
ordinate of the object
These translation distance are represented
by two variables known as translation
vector.
B1
[ ] [][] []
l
x 5 4 9
l = + =
y 4 3 7
C1
[ ] [][] [ ]
l
x 5 3 8
l = + =
y 4 6 10
[ ][ ][]
xl 1 0 tx x
y
l
= 0 1 ty ∗ y
1 0 0 1 1
A=( 0 , 0 ) B=( 10 , 0 )
C=( 0 , 20 ) D=(10 ,20)
[ ][ ][ ]
xl 1 0 15 0 10 0 10
y
l
= 0 1 20 ∗ 0 0 20 20
1 0 0 1 1 1 1 1
| |
15 25 15 25
¿ 20 20 40 40
1 1 1 1
Rotation:-
In rotation we have to mention on angel a 2 D rotation is applied
rotation is applied to an object
By repositioning it along a circular path.
To perform a rotation to any object we need the rotation angle
theta()and pivot point co-ordinates point(xr,yr)
This point (xr,yr) is called pivot point rotational point
The pivot point is the point about which an object is rotate
If the theta is positive then the object is rotated is an anticlockwise
direction and negative value of theta will rotate the object in
clockwise direction
Rotation about the origin:-
In such rotation the pivot point is consider to be other origin
equ:-
Xl=xcosθ-ysinθ
Yl= ycosθ+xsinθ
Last equation
Xl=xcosθ-ysinθ
Yl= xsinθ+ycosθ
[][ ][ ]
x = cos θ −sinθ . x
l
y
l
sin θ cos θ y
[][ ][ ]
xl cos θ −sinθ −hcosθ +ksinθ+h x
y = sin θ cos θ −hsinθ−kcosθ+ k . y
l
1 0 0 1 1
[][ ][ ]
xl cos θ −sinθ −hcosθ +ksinθ+h x
y
l
= sin θ cos θ −hsinθ−kcosθ+ k . y
1 0 0 1 1
[][ ][ ]
xl cos 90 −sin 90 0+0+ 0 2
y = sin 90 cos 90 0−0+0 . 4
l
1 0 0 1 1
[ ][ ] [ ]
0 −1 0 2 −4
1 0 0 . 4= 2
0 0 1 1 1
Qno 2
H=5
K=5
θ =900
Co-ordinate
(0,0)
(10,0)
(10,10)
(0,10)
[][ ][ ]
xl cos 90 −sin 90 −5∗0+5∗1+ 5 0 10 10 0
y
l
= sin 90 cos 90 −5∗1−5∗0+5 * 0 0 10 10
1 0 0 1 1 1 11
Cos900=0
Sin900=1
[ ][ ]
0 −1 10 0 10 10 0
1 0 0 * 0 0 10 10
0 0 1 1 1 11
[ ]
10 10 −10+10−10+ 10
0 10 10 0
1 1 11
10 10 0 0
Answer=¿ 0 1 0 10 0 ⌋
⌊
1 1 11
Step:-1
Q.No 3
H=0,k=0
θ =300
co−ordinate
( 0 , 0) (1,1) (5,2)
Step−2
[][ ][ ]
xl cos θ −sinθ −hcosθ +ksinθ+h x
y = sin θ cos θ −hsinθ−kcosθ+ k . y
l
1 0 0 1 1
Step−3
[][ ]
xl cos 30 −sin 30 −0 cos 30+0 sin 30+0 0 1 5
y
l
= sin 30 cos 30 −0 sin 30−0 cos 30+ 0 . ⌊ 0 1 2 ⌋
1 0 0 1 1 1 1
Sin 300=1/2=0.5
[ ][ ]
8.7 −0.5 0 0 1 5
= 0.5 8.7 0 ∗ 0 1 2
0 0 1 0 1 1
[ ]
0 8.7−0.5 93.5−1.0
= 0 0.5+8.7 2.5+17.4
1 1 1
[ ]
0 8.2 42.5
Answer 0 9.2 19.9
1 1 1
Scaling:-
A scaling change the size an object.
Scaling is perform by multiplying original co-ordinates of the object to
scaling factor sx,sy
Xl=sx.x
Yl=sy.y
(Sx) scale object in x direction
(Sy) scale object in y direction
[ ][ ][]
l
x sx x
l = ∗
y sy y
[][ ][ ]
xl sx 0 0 x
y = 0 sy 0 . y
l
1 0 0 1 1
Step-1
A=(2,7) B=(2,2) C=(6,2)
Sx=2 sy=3
Step-2
[][ ]
xl sx 0 0
y = 0 sy 0
l
1 0 0 1
Step-3
[][ ][ ]
xl 2 0 0 2 2 6
y
l
= 0 3 0 * 7 2 2
1 0 0 1 1 1 1
[][ ][ ]
xl 2 0 0 2 2 6
y =0 3 0
l
* 7 2 2
1 0 0 1 1 1 1
4 4 12
= 6 6
21
1 1 1
Step-4
New point will be:-
Al=(4,21) bl=(4,6) cl=(12,6)
Scaling with respect to a fixed point:--
->In above diagram the object is located at(2,2)before scaling and after
scaling also the point is at(2,2)
->the fix point represented by two variable(xf,yf)
->(xf,yf)and (sx,sy)will remain same for all co-ordinates of the object.
2D matrix for scaling (scaling with respect to a fixed point)
Reflection
It is called derived transformation because it is derived from rotation and
translation.
It produces mirror image of an object.
It is perform with respect to a fixed line known as reflection axis.
During reflection the object is copied, then the copied image is
rotated by 1800 and finally the image translated to a new position.
There are two types of reflection:-
3,6
C (4,2)
A (2,2)
(2,-2)
(4,-2)
(3,-6)
[ ][ ][]
l
x 10 x
l = ∗
y 0−1 y
A (2,2) C (4,2)
cl (-4,2) Al(-2,2)
[ ] [ ][ ]
l
x −10 x
l = ∗
y 01 y
In such type of reflection the path of the reflection the path of the
reflection is in x,y plane
In such type of reflection axis is assumed to be passing through the
origin and it is perpendicular to x,y plane
In such reflection the object is rotated by 1800 around reflection axis
x and y co-ordinate became.
[ ] [ ][ ]
l
x −10 x
l = ∗
y 0−1 y
[][ ][ ]
xl −1 0 0 x
y = 0 −1 0 . y
l
1 0 0 1 1
1 0 0 1 1 1 1
[ ]
−2 −2 −6
= −7 −2 −2
1 1 1
Shearing
1) Shearing in x direction:--
-During this shearing the co-ordinate of the object are shifted
horizontally along the x axis
-The distance by which co-ordinate are shifted is stored in shearing
Equation:-
Xnew = Xold + Shx * Yold
Ynew = Yold
Shearing in Y Axis-
Xnew = Xold
Ynew = Yold + Shy * Xold
Given a triangle with points (1, 1), (0, 0) and (1, 0). Apply shear
parameter 2 on X axis and 2 on Y axis and find out the new coordinates
of the object.
Solution-
Given-
Old corner coordinates of the triangle = A (1, 1), B(0, 0), C(1, 0)
Shearing parameter towards X direction (Shx) = 2
Shearing parameter towards Y direction (Shy) = 2
Shearing in X Axis-
For Coordinates A(1, 1)
Let the new coordinates of corner A after shearing = (Xnew, Ynew).
Applying the shearing equations, we have-
Xnew = Xold + Shx x Yold = 1 + 2 x 1 = 3
Ynew = Yold = 1
Shearing in Y Axis-
For Co-ordinates A(1, 1)
Let the new coordinates of corner A after shearing = (Xnew, Ynew).
Applying the shearing equations, we have-
Xnew = Xold = 1
Ynew = Yold + Shy x Xold = 1 + 2 x 1 = 3
Translation
Let T1 (tx1, ty1) and T2 (tx2,ty2) be two translations applied on a point
P(x,y) in succession.
Scaling
Translation
It is the movement of an object from one position to another position. Translation
is done using translation vectors. There are three vectors in 3D instead of two.
These vectors are in x, y, and z directions. Translation in the x-direction is
represented using Tx. The translation is y-direction is represented using T y. The
translation in the z- direction is represented using Tz.
x1=x+Tx
y1=y+Ty
z1=z+ Tz
Matrix representation of point translation
Point shown in fig is (x, y, z). It become (x 1,y1,z1) after translation. Tx Ty Tz are
translation vector.
Rotation
It is moving of an object about an angle. Movement can be anticlockwise or
clockwise. 3D rotation is complex as compared to the 2D rotation. For 2D we
describe the angle of rotation, but for a 3D angle of rotation and axis of rotation
are required. The axis can be either x or y or z.
Equation:-xi=x
Yi=ycosɵ - zsinɵ
Zi=ysinɵ + zcosɵ
Given a homogeneous point (1, 2, 3). Apply rotation 90 degree towards X, Y and Z axis and
find out the new coordinate points.
Solution-
Xnew = Xold = 1
Ynew = 2 x cos90° – 3 x sin90° = 2 x 0 – 3 x 1 = -3
Znew = 2 x sin90° + 3 x cos90° = 2 x 1 + 3 x 0 = 2
Scaling
Scaling is used to change the size of an object. The size can be increased or
decreased. The scaling three factors are required Sx Sy and Sz.
Xl=sx.x
Yl=sy.y
Z1=sz*z
Question:--Given a 3D object with coordinate points A(0, 3, 3), B(3, 3, 6), C(3, 0,
1), D(0, 0, 0). Apply the scaling parameter 2 towards X axis, 3 towards Y axis and 3
towards Z axis and obtain the new coordinates of the object.
Old coordinates of the object = A (0, 3, 3), B(3, 3, 6), C(3, 0, 1), D(0, 0, 0)
Scaling factor along X axis = 2
Scaling factor along Y axis = 3
Scaling factor along Z axis = 3
Reflection:
It is also called a mirror image of an object. For this reflection axis and reflection
of plane is selected. Three-dimensional reflections are similar to two dimensions.
Reflection is 180° about the given axis. For reflection, plane is selected (xy,xz or
yz). Following matrices show reflection respect to all these three planes.
Question-01:
Given a 3D triangle with coordinate points A(3, 4, 1), B(6, 4, 2), C(5, 6, 3). Apply
the reflection on the XY plane and find out the new coordinates of the object.
Solution-
Given-
Old corner coordinates of the triangle = A (3, 4, 1), B(6, 4, 2), C(5, 6, 3)
Reflection has to be taken on the XY plane
Let the new coordinates of corner A after reflection = (Xnew, Ynew, Znew).
Let the new coordinates of corner B after reflection = (Xnew, Ynew, Znew).
Let the new coordinates of corner C after reflection = (Xnew, Ynew, Znew).
Question-02:
Given a 3D triangle with coordinate points A(3, 4, 1), B(6, 4, 2), C(5, 6, 3). Apply
the reflection on the XZ plane and find out the new coordinates of the object.
Solution-
Given-
Old corner coordinates of the triangle = A (3, 4, 1), B(6, 4, 2), C(5, 6, 3)
Reflection has to be taken on the XZ plane
For Coordinates A(3, 4, 1)
Let the new coordinates of corner A after reflection = (Xnew, Ynew, Znew).
Let the new coordinates of corner B after reflection = (Xnew, Ynew, Znew).
Let the new coordinates of corner C after reflection = (Xnew, Ynew, Znew).
Applying the reflection equations, we have-
Xnew = Xold = 5
Ynew = -Yold = -6
Znew = Zold = 3
3D Shearing
Shearing in X direction
Shearing in Y direction
Shearing in Z direction
Let-
Initial co-ordinates of the object O = (Xold, Yold, Zold)
Shearing parameter towards X direction = Shx
Shearing parameter towards Y direction = Shy
Shearing parameter towards Z direction = Shz
New coordinates of the object O after shearing = (Xnew, Ynew, Znew)
Shearing in X Axis-
Shearing in Y Axis-
Solution-
Given-
Old corner coordinates of the triangle = A (0, 0, 0), B(1, 1, 2), C(1, 1, 3)
Shearing parameter towards X direction (Shx) = 2
Shearing parameter towards Y direction (Shy) = 2
Shearing parameter towards Y direction (Shz) = 3
Shearing in X Axis-
Let the new coordinates of corner B after shearing = (Xnew, Ynew, Znew).
Let the new coordinates of corner C after shearing = (Xnew, Ynew, Znew).
Shearing in Y Axis-
Let the new coordinates of corner A after shearing = (Xnew, Ynew, Znew).
Let the new coordinates of corner B after shearing = (Xnew, Ynew, Znew).
Let the new coordinates of corner C after shearing = (Xnew, Ynew, Znew).
Shearing in Z Axis-
Let the new coordinates of corner A after shearing = (Xnew, Ynew, Znew).
Applying the shearing equations, we have-
Xnew = Xold + Shx x Zold = 0 + 2 x 0 = 0
Ynew = Yold + Shy x Zold = 0 + 2 x 0 = 0
Znew = Zold = 0
Let the new coordinates of corner B after shearing = (Xnew, Ynew, Znew).
Let the new coordinates of corner C after shearing = (Xnew, Ynew, Znew).
Given the centre point coordinates (0, 0) and radius as 10, generate all the points
to form a circle.
Concept:-
1)Work on 90 degree to 45 degree
2)At 90 degree x=0 and y=r(radius)
3)At 45 degree x==y
4)At 0 degree (x==r and y=0)
5)if current pixel is(x,y)then
a)side pixel(x+1,y)
b)bottom pixel(x+1,y-1)
6)initial value:-
a)d(decision variable)=1-r
7)other value are(not initial value)
a)ds=2*x+3
b)dp=2*(x-y)+5
Algorithem
(h,k)are (enter co-ordinate r is radius)
1)Begin
2)Declare x,y,d
3)Set the initial values:-
a)r=radius of the circle
b)(h,k)center co-ordinate
c)x=0,y=r
d)d(decision variable)=1-r
4)Repeat step 5 to 6 until x<=y
5)plot the 8 point to using 8 way symmetry.
Compute the next pixel
a)if d<0 choose side pixel
set x=x+1
set d=d+2*x+3
a)else
(d>0) choose side pixel
set x=x+1
set y=y-1
set d=d+2*(x-y)+5
Solution-
Step-01:
Assign the starting point coordinates (X0, Y0) as-
X0 = 0
Y0 = R = 10
Step-02:
Step-03:
As Pinitial < 0, so case-01 is satisfied
Step 1 -9<0
Xk+1 = Xk + 1 = 0 + 1 = 1
Yk+1 = Yk = 10
plot (1,10)
Now xk is 1 & yk is 10
Pk+1 = Pk + 2 * Xk+1 + 3
Pk+1 = -9 + (2 * 1) + 3 = -4
Step 2 -4< 0
Xk+1 = Xk + 1 = 1 + 1 = 2
Yk+1 = Yk = 10
Plot (2,10)
Pk+1 = Pk + 2 * Xk+1 + 3
Pk+1 = -4 + (2 * 2) + 3 = 3
Step 3 3 > 0
Xk+1 = Xk + 1 = 2 + 1 = 3
Yk+1 = Yk-1 = 10-1=9
Plot (3,9)
Pk+1 = Pk + 2 *(x-y) + 5
Pk+1 = 3 + 2 * (3 -9) +5 =-4
Step 4 -4< 0
Xk+1 = Xk + 1 = 3 + 1 = 4
Yk+1 = Yk = 9
Plot (4,9)
Pk+1 = Pk + 2 * Xk+1 + 3
Pk+1 = -4 + (2 * 4) + 3 = 7
Step 5 7>0
Xk+1 = Xk + 1 = 4 + 1 = 5
Yk+1 = Yk -1=9-1=8
Plot (5,8)
Pk+1 = Pk + 2 *(x-y) + 5
Pk+1 = 7 +2 * (5 - 8) + 5 = 6
Step 6 6>0
Xk+1 = Xk + 1 = 5+ 1 = 6
Yk+1 = Yk -1=8-1=7
Plot (6,7)
Pk+1 = Pk + 2 *(x-y) + 5
Pk+1 = 6 +2 * (6 - 7) + 5 = 9
Step 7 9>0
Xk+1 = Xk + 1 = 6+ 1 = 7
Yk+1 = Yk -1=7-1=6
When x>y then stop
Pk (Xk+1, Yk+1)
(0, 10)
-9 (1, 10)
-4 (2, 10)
3 (3, 9)
-4 (4, 9)
7 (5, 8)
6 (6, 7)
9 (7,6)
if(d<0)
{
d=d+(2*x)+3;
}
else
{
d=d+2*(x-y)+5;
y--;
}
x++;
putpixel(x+h,y+k,RED);
putpixel(y+h,x+k,WHITE);
putpixel(-y+h,x+k,GREEN);
putpixel(-x+h,y+k,RED);
putpixel(-x+h,-y+k,WHITE);
putpixel(-y+h,-x+k,GREEN);
putpixel(y+h,-x+k,RED);
putpixel(x+h,-y+k,WHITE);
getch();
}
}
Algorithm:-
1) (h,k) are center co-ordinate r is radius
2) Begin
3) Declare x,y,d
4) Set the initial values:-
a) r=radius of the circle
b) (h,k)=center co-ordinate
c) X=0,y=r
d) d (decision variable)=3-2*r
5) Repeat step 5 to 6 until x<=y
6) Plot the 8 points using 8 way symmetry.
7) Compute the next pixel.
a) if d<0 choose side pixel
set x=x+1
set d=d+4*x+6
b) else choose bottom pixel
set x=x+1
set y=y-1
set d=d+4*(x-y)+10
end if
8)End loop
9)End
1) Create or draw arc point using Bresenham’s circle drawing algorithm
Center point (0,0)
Radius 10
step 1:- h=0
K=0
r=10
d=3-2*r
d=3-2*10=-17
step 2:-x=0
y=r
(i) (0,r) (0,0)
(ii) d<0
x++,y
(1,10)
d = d+4*1+6
d =-17+4+6=-7
(iii) d<0
x++,y
(2,10)
d=d+4*2+6=7
(iv) d>0
x++,y--
(3,9)
d=d+4*(x-y)+10
d =7+4(3-9)+10=-7
(v) d<0
x++,y
(4,9)
d=d+4*4+6
d=-7+16+6=15
(vi) d>0
x++,y—
(5,8)
d=d+4*(x-y)+10
d=15+4*(5-8)+10=13
(vii) d>0
x++,y—
(6,7)
d=d+4*x(x-y)+10
=13+4*(6-7)+10=19
(viii) d>0
x++,y—
(7,6)
d=d+4*(x-y)+10
=19+4(7-6)+10
=33
X Y D
0 10 -17
1 10 -7
2 10 7
3 9 -7
4 9 15
5 8 13
6 7 19
7 6 33
#include<iostream.h>
#include<graphics.h>
#include<dos.h>
#include<conio.h>
void main()
{
int d,c,gd=0,gm,a,h,k,x=0,y,r=10;
initgraph(&gd,&gm,"c:\\turboc3\\bgi");
cin>>h>>k;
x=0;
y=r;
d=3-(2*r);
while(x<=y)
{
if(d<0)
{
d=d+(4*x)+6;
}
else
{
d=d+4*(x-y)+10;
y--;
}
x++;
putpixel(x+h,y+k,RED);
putpixel(y+h,x+k,WHITE);
putpixel(-y+h,x+k,GREEN);
putpixel(-x+h,y+k,RED);
putpixel(-x+h,-y+k,WHITE);
putpixel(-y+h,-x+k,GREEN);
putpixel(y+h,-x+k,RED);
putpixel(x+h,-y+k,WHITE);
getch();
}
For it first of all rotate function is used. Sequences of steps are given below for
rotating an object about origin.
1. Translate object to origin from its original position as shown in fig (b)
2. Rotate the object about the origin as shown in fig (c).
3. Translate the object to its original position from origin. It is called as reverse
translation as shown in fig (d).
The matrix multiplication of above 3 steps is given below
Step2: The object is translated so that its center coincides with origin as
shown in fig (b)
Step3: Scaling of object by keeping object at origin is done as shown in fig
(c)
| |
sx 0 xf (1−sx )
= 0 sy yf (1−sy ) ∗p
0 0 1
Given p(6,8) sx=2,sy=3 & fixed point (2,2) use that find pi
| | []
2 0 2∗(1−2) 6
i
P= 0 3 2∗(1−3) * 8
0 0 1 1
| | []
2 0 −2 6
= 0 3 −4 * 8
0 0 1 1
[]
10
= 20
0
Clipping:
When we have to display a large portion of the picture, then not only scaling & translation is
necessary, the visible part of picture is also identified. This process is not easy. Certain parts
of the image are inside, while others are partially inside. The lines or elements which are
partially visible will be omitted.
For deciding the visible and invisible portion, a particular process called clipping is used.
Clipping determines each element into the visible and invisible portion. Visible portion is
selected. An invisible portion is discarded.
Types of Lines:
Applications of clipping:
1. It will extract part we desire.
2. For identifying the visible and invisible area in the 3D object.
3. For creating objects using solid modeling.
4. For drawing operations.
Types of Clipping:
1. Point Clipping
2. Line Clipping
3. Area Clipping (Polygon)
Point Clipping:
Point Clipping is used to determining, whether the point is inside the window or not. For this
following conditions are checked.
1. x ≤ xmax
2. x ≥ xmin
3. y ≤ ymax
4. y ≥ ymin
The (x, y) is coordinate of the point. If anyone from the above inequalities is false, then the
point will fall outside the window and will not be considered to be visible.
Line Clipping:
It is performed by using the line clipping algorithm. The line clipping algorithms are:
1. Visible
2. Not Visible
3. Clipping Case
1. Visible: If a line lies within the window, i.e., both endpoints of the line lies within the
window. A line is visible and will be displayed as it is.
2. Not Visible: If a line lies outside the window it will be invisible and rejected. Such lines will
not display. If any one of the following inequalities is satisfied, then the line is considered
invisible. Let A (x1,y2) and B (x2,y2) are endpoints of line.
Advantage of Cohen Sutherland Line Clipping:
1. It calculates end-points very quickly and rejects and accepts lines quickly.
2. It can clip pictures much large than screen size.
Step4:If a line is clipped case, find an intersection with boundaries of the window
m=(y2-y1 )(x2-x1)
Example:---
Use Cohen-Sutherland algorithm to clip two lines p1(40,15) ,p2(75,45),p3(70,20),p4(100,10)
against a window A(50,10),B(80,10),C(80,40),D(50,40)
(75,45)
x1
(50,40) (80,40)
y1
xleft=50
xright=80
ybottom=10
ytop=40
x1=40 x2=75
y1=15 y2=40
Y1=m(xleft-x1)+y1 y1=6/7(50-40)+15=23.57
y2=m(xright-x1)+y1 y2=6/7(80-40)+15=49.28
x1=1/m(ytop—y1)+x1 X1=7/6(40-15)+40=69.70
X2=1/m(ybottom-y1)+x1 x2 =7/6(10-15)+40=34.16
Projections
Parallel Projection:
A parallel projection is formed by extending parallel lines from each vertex of object until
they intersect plane of screen. Parallel projection transforms object to the view plane along
parallel lines. A projection is said to be parallel, if center of projection is at an infinite
distance from the projected plane. A parallel projection preserves relative proportion of
objects,
Orthographic Projections:
Oblique Projections:
Oblique projections are obtained by projectors along parallel lines that are not
perpendicular to the projection plane. An oblique projection shows the front and top
surfaces that include the three dimensions of height, width and depth. The front or principal
surface of an object is parallel to the plane of projection.
Isometric Projections: Orthographic projections that show more than one side of an
object are called axonometric orthographic projections. The most common axonometric
projection is an isometric projection. In this projection parallelism of lines are preserved
but angles are not preserved.
Diametric projections: In these two projectors have equal angles with respect to two
principal axis.
Trimetric projections: The direction of projection makes unequal angle with their
principal axis.
Cavalier Projections:
All lines perpendicular to the projection plane are projected with no change in length. If the
projected line making an angle 45 degrees with the projected plane, as a result the line of
the object length will not change.
Cabinet Projections:
All lines perpendicular to the projection plane are projected to one half of their length.
These gives a realistic appearance of object. It makes 63.4 degrees angle with the projection
plane. Here lines perpendicular to the viewing surface are projected at half their actual
length.
Perspective Projections:
A perspective projection is the one produced by straight lines radiating from a common
point and passing through point on the sphere to the plane of projection.
Two characteristic of perspective are vanishing point and perspective force shortening. Due
to fore shortening objects and lengths appear smaller from the center of projections. The
projections are not parallel and we specify a center of projection cop.
Different types of perspective projections:
One point perspective projections: In this, principal axis has a finite vanishing point.
Perspective projection is simple to draw.
Two point perspective projections: Exactly 2 principals have vanishing points.
Perspective projection gives better impression of depth.
Three point perspective projections: All the three principal axes have finite vanishing
point. Perspective projection is most difficult to draw.
Curves
In computer graphics, we often need to draw different types of objects onto the screen.
Objects are not flat all the time and we need to draw curves many times to draw an object.
Types of Curves
A curve is an infinitely large set of points. Each point has two neighbors except endpoints.
Curves can be broadly classified into three categories − explicit, implicit, and parametric
curves.
Implicit Curves
Implicit curve representations define the set of points on a curve by employing a procedure
that can test to see if a point in on the curve. Usually, an implicit curve is defined by an
implicit function of the form –
fx,y = 0
x2 + y 2 - R 2 = 0
Explicit Curves
Curves having parametric form are called parametric curves. The explicit and implicit curve
representations can be used only when the function is known. In practice the parametric
curves are used. A two-dimensional parametric curve has the following form −
The functions f and g become the x,y coordinates of any point on the curve, and the points
are obtained when the parameter t is varied over a certain interval [a, b], normally [0, 1].
Spline curve
A spline is a flexible strip used to produce a smooth curve through a designed set of
points.
The term spline curve originally referred to a curve drawn in this manner
There are several different kinds of spline specification that are used in graphical
application
Splines are used in:-
Graphics application to design curve and surface shapes.
Typical CAD applications for splines include the design automobile bodies.
Aircraft, Spacecraft surface & Ship hulls.
Central points
Spine curve by giving a set of coordinate positions, called control point. Which indicate
the general shape of the curve. Interpolation curves are commonly used to digitize
drawing or to specify animation paths. Polynomial section are fitted so that the curve
passes through each control point, resulting curve is said to interpolate the set of control
point
A set of six control point interpolate with piecewise continuous polynomial section.
Approximation
The polynomials are fitted to the general control-point path without necessarily passing
through any control point, the resulting curve is said to approximate the set of control
points.
Approximation curves are primarily used as design to structure object surfaces.
straight lines connect the control-point positions above the surface.
Convex hull
The convex hull of a set of points in a Euclidean space is the smallest convex polygon
that encloses all of the points. In two dimensions (2D), the convex hull is a convex
polygon, and in three dimensions (3D), it is a convex polyhedron.The below image
shows a 2-D convex polygon:
Polynomial Function
polynomial function is the simplest, most commonly used, and most important mathematical
function. These functions represent algebraic expressions with certain conditions. They also
cover a wide number of functions. It is essential for one to study and understand polynomial
functions due to their extensive applications.
Polynomial functions are expressions that may contain variables of varying degrees, coefficients,
positive exponents, and constants. Here are some examples of polynomial functions.
f(x) = 3x2 - 5
g(x) = -7x3 + (1/2) x - 7
h(x) = 3x4 + 7x3 - 12x2
Monomials are polynomials that contain only one term. Examples: 15x 2, 3b, and 12y4
Binomials are polynomials that contain only two terms. Examples: x + y, 4x – 7, and 9x + 2
Trinomials are polynomials that contain only three terms. Examples: x3 – 3 + 5x, z4 + 45 +
3z, and x2 – 12x + 15
A zero polynomial function is of the form f(x) = 0, yes, it just contains just 0 and no other term
or variable. Since f(x) = a constant here
it is a constant function.
A linear polynomial function has a degree 1. It is of the form f(x) = ax + b. Some examples of a
linear polynomial function are f(x) = x + 3, f(x) = 25x + 4, and f(y) = 8y – 3.
f(x) = x2 4 1 0 1 4
Let's plot the points and join them by a curve (also extend it on both sides) to get the graph of
the polynomial function.