0% found this document useful (0 votes)
2 views

C.G.

The document discusses scan conversion techniques for points and straight lines in computer graphics, detailing methods such as the DDA algorithm and Bresenham's line drawing algorithm. It explains the process of converting mathematical points to pixel coordinates and the steps involved in generating line segments between endpoints. Additionally, it covers 2D transformations including translation, rotation, scaling, reflection, and shearing, along with their mathematical representations.

Uploaded by

sagarchouhan5252
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

C.G.

The document discusses scan conversion techniques for points and straight lines in computer graphics, detailing methods such as the DDA algorithm and Bresenham's line drawing algorithm. It explains the process of converting mathematical points to pixel coordinates and the steps involved in generating line segments between endpoints. Additionally, it covers 2D transformations including translation, rotation, scaling, reflection, and shearing, along with their mathematical representations.

Uploaded by

sagarchouhan5252
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 81

Scan conversion of a point

 A mathematical point(x,y)where ,y are real number. it needs to be


scan converted to a pixel at location(xl,yl)
 This is done by making xl,yl to be integer part of x and y
 Xl=floor(x) yl=floor(y)
 if point(17.20,12.50)it can be represented in pixel by
 xl=floor(x) yl=floor(y)
floor(17.20) floor(12.50)
17 12

Then pixel will be draw at location(17,12)

Scan Converting a Straight Line


A straight line may be defined by two endpoints & an equation. In fig the
two endpoints are described by (x1,y1) and (x2,y2). The equation of the line
is used to determine the x, y coordinates of all the points that lie between
these two endpoints.
Direct use of line equation:
It is the simplest form of conversion. First of all scan P 1 and P2 points.
P1 has co-ordinates (x1',y1') and (x2' y2' ).

Then m = (y2',y1')/( x2',x1') and b =

If value of |m|≤1 for each integer value of x. But do not consider

If value of |m|>1 for each integer value of y. But do not consider

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

Now calculate intermediate points


Let x = 1 ⟹ y = 3 x 1 ⟹ y = 3
Let x = 2 ⟹ y = 3 x 2 ⟹ y = 6
Let x = 3 ⟹ y = 3 x 3 ⟹ y = 9
Let x = 4 ⟹ y = 3 x 4 ⟹ y = 12
Let x = 5 ⟹ y = 3 x 5 ⟹ y = 15
Let x = 6 ⟹ y = 3 x 6 ⟹ y = 18

DDA algorithm
Digital Differential Analyzer

DDA is a line drawing algorithm used in computer graphics to generate a line


segment between two specified endpoints. It is a simple and efficient algorithm
that works by using the incremental difference between the x-coordinates and y-
coordinates of the two endpoints to plot the line.

The steps involved in DDA line generation algorithm are:

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:-

1)This algorithm is designed by jack E. Bresenham’s in 1962


2)this algorithm works on the concept when dx>dy and line will draw in
the area 0 to 45 degree

Algorithm:-
1)Input the two line endpoints and store the left endpoint in(x1,y1)

2)Load(x1,y1)into the frame buffer, that is plot the first point:-


3)Calculate constant Δx,Δy,2Δy-2Δx and obtain the starting value for
the decision parameter as
Pk=2Δy-Δx
4) At each along the line ,starting at k=0,perform the
following test if pk<0,the next point to plot is(xk+1,yk)
Pk+1=pk+2Δy
5) At each along the line ,starting at k=0,perform the following test if
pk>0,the next point to plot is(xk+1,yk+1)
Pk+1=pk+2Δy-2Δx

(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

3) pk=-2 and -2 is Negative value


Pk=-2 xk+1=23 yk+1=12
Pk+1=pk+2Δy
Pk+1=- -2+(2*8)=14

4)pk=14 and 14 is positive value


pk=14 xk+1=24 yk+1=13
Pk+1=pk+2Δy-2Δx
Pk+1=14+(2*8)-(2*10)=10
5)pk=10 and 10 is positive value
pk=10 xk+1=25 yk+1=14
Pk+1=pk+2Δy-2Δx
Pk+1=10+(2*8)-(2*10)=6

6)pk=6 and 6 is positive value


pk=6 xk+1=26 yk+1=15
Pk+1=pk+2Δy-2Δx
Pk+1=6+(2*8)-(2*10)=2
7)pk=2 and 2 is positive value
pk=2 xk+1=27 yk+1=16
Pk+1=pk+2Δy-2Δx
Pk+1=2+(2*8)-(2*10)=-2

8)pk=-2 and -2 is Negative value


pk=-2 xk+1=28 yk+1=16
Pk+1=pk+2Δy
Pk+1= -2+(2*8)=14

9)pk=14 and 14 is positive value


pk=14 xk+1=29 yk+1=17
Pk+1=pk+2Δy-2Δy
Pk+1= 14+(2*8)-(2*10)=10

10)pk=10 and 10 is positive value


pk=10 xk+1=30 yk+1=18

Ex..1 (2,2,10,8)
2 (2,3,18,4)
3 (5,7,17,15)

DDA vs Bresenham’s Algorithm: Difference and Comparison


1. DDA Algorithm uses floating-point arithmetic for rasterization,
while Bresenham’s Algorithm uses integer arithmetic, making it
more efficient.
2. Bresenham’s Algorithm generates more accurate line drawings than
the DDA Algorithm.
3. Bresenham’s Algorithm is faster and requires fewer computational
resources than the DDA Algorithm.

Bresenham’s line Drawing Programme:-


#include<iostream.h>
#include<graphics.h>
#include<conio.h>
void main()
{
int pk,x1,y1,x2,y2,dx,dy,x,y,gd=0,gm;
initgraph(&gd,&gm,"c:\\turboc3\\bgi");
cout<<"enter a no";
cin>>x1>>y1>>x2>>y2;
x=x1;
y=y1;
dy=y2-y1;
dx=x2-x1;
pk=2*dy-dx;
for(;x1<x2;x1++)
{
if(pk<0)
{
x++;
putpixel(x,y,WHITE);
pk=pk+2*dy;
}
else
{
x++;
y++;
putpixel(x,y,WHITE);
pk=pk+2*dy-2*dx;
}
}
getch();
}
Computer Graphics Homogeneous Coordinates
Homogeneous coordinate systems mean expressing each coordinate as a
homogeneous coordinate to represent all geometric transformation
equations as matrix multiplication. The transformed matrix can be
expressed in general matrix form.

2D Transformation
1. Translation
2. Rotation
3. Scaling
4. Reflection
5. Shearing

 2D Transformation means changing the


shape,size,orientation or position of 2 d
object such that the coordinate value of the
object are changed.
 There are five transformation which can be
performed any 2D object.
 Out of these five transformation 3 are known
as basic transformation and other two known as
derived.The basic transformation are:-
1)Translation 2)Rotation 3)Scaling

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.

tx=Translation distance in x direction


ty=translation distance in y direction
then new co-ordinate will be calculated
according to the following:-

The translation eq. will be


Xl=tx+x
Yl=ty+y

matrix representation will be


step 1
[ ][ ][]
l
x tx x
= +
yl ty y
Step 2
1st point (2,3)=A
2nd point (4,3)=B
3rd point (3,6)=c
Step 3
Method 1
Al
[ ] [][] []
l
x 5 2 7
l = + =
y 4 3 7

B1
[ ] [][] []
l
x 5 4 9
l = + =
y 4 3 7

C1
[ ] [][] [ ]
l
x 5 3 8
l = + =
y 4 6 10

Homogeneous matrix for translation:-

[ ][ ][]
xl 1 0 tx x
y
l
= 0 1 ty ∗ y
1 0 0 1 1

Translate the following withtx=15∧ty=20

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

P(x,y) -> original co-ordinates


Pl(xl,yl) -> New position after rotation
R=distance from the origin
ϕ =original angle which the object make with x axis.
θ =θ is the angle throw which an object is rotated.

Matrix for rotation is a clockwise direction.

we can specify the position of the object as follow


 Before the rotation:-
X=r cosϕ
Y=r sinϕ
 After the rotation:-
Xl=r cos(ϕ+θ)
Yl= r sin(ϕ+θ)
 Then xl and yl will be
Xl=r[cosϕ.cosθ - sinϕ.sinθ]
yl=r[sinϕ.cosθ + cosϕ.sinθ]
Then
Xl=r cosϕ.cosθ - r sinϕ.sinθ
yl=r sinϕ.cosθ + r cosϕ.sinθ

equ:-
Xl=xcosθ-ysinθ
Yl= ycosθ+xsinθ

Last equation
Xl=xcosθ-ysinθ
Yl= xsinθ+ycosθ

Matrix form is:---

[][ ][ ]
x = cos θ −sinθ . x
l

y
l
sin θ cos θ y

Rotation is body transformation, that means the complex object is


rotated and rotate does not change the shape of the object.
Whenever we rotate an object then only the vertices of the object are
rotated and after rotation new line are drawn between new vertices
Homogeneous matrix for rotation

[][ ][ ]
xl cos θ −sinθ −hcosθ +ksinθ+h x
y = sin θ cos θ −hsinθ−kcosθ+ k . y
l

1 0 0 1 1

H,k=center coordinate (pivot point)


θ =Angle of rotation
Rotate a point (2,4) when h=0,k=0 and θ=900
Step 1
Table

00 300 450 600 900 1800 2700


sinθ 0 ½ 1/√2 √3/2 1 0 -1/2
cosθ 1 √3/2 1/√2 1/2 0 -1 0

[][ ][ ]
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

Cos 300= √2 =8.7


3

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

General equation of scaling:-


Pi=s.p
A positive value >1 then size of the object is increase
A Negative value <1 then size of the object is decrease
And the value of one will have no effect on the object
In this scaling two factor are important
1) Point of scaling
2) Scaling vectors

Homogeneous matrix for scaling


H=1

[][ ][ ]
xl sx 0 0 x
y = 0 sy 0 . y
l

1 0 0 1 1

Sx,sy --->scaling vector


Scale a triangle with co-ordinates (2,7)(2,2)(6,2)
Where sx=2 and sy=3

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:-

o Reflection with respect to x axis


o Reflection about respect to y axis

Reflection with respect to x axis:--


B (3, 6)

3,6

C (4,2)
A (2,2)
(2,-2)
(4,-2)

(3,-6)

 2 D matrix for reflection with respect to x axis:--

[ ][ ][]
l
x 10 x
l = ∗
y 0−1 y

 Homogenous matrix representation for reflection with respect to x


axis
[][ ][ ]
xl 1 0 0 x
y
l
= 0 −1 0 . y
1 0 0 1 1

In such reflection the x axis is known as reflection axis.


Here after reflection the y value become negative and x value remain
same.

Reflection with respect to y axis:--


B (3, 6)
Bl (-3,6)

A (2,2) C (4,2)
cl (-4,2) Al(-2,2)

 2 D matrix for reflection with respect to y axis:--

[ ] [ ][ ]
l
x −10 x
l = ∗
y 01 y

 Homogenous matrix representation for reflection with respect to y


axis
[][ ][ ]
xl −1 0 0 x
y
l
= 0 1 0 . y
1 0 0 1 1

In such reflection the y axis is known as reflection axis.


Here after reflection the y value become positive and x axis negative.

Reflection with respect to origin:--

 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.

 2 D marix for reflection with respect to origin:--

[ ] [ ][ ]
l
x −10 x
l = ∗
y 0−1 y

 Homogenius matrix representation for reflection with respect to y


axis

[][ ][ ]
xl −1 0 0 x
y = 0 −1 0 . y
l

1 0 0 1 1

Qno 1) Reflect a triangle with co-ordinate value (2,7),(2,2),(6,2)


And the reflection is performed about the origin
[][ ][ ]
xl −1 0 0 2 2 6
y = 0 −1 0 . 7 2 2
l

1 0 0 1 1 1 1

[ ]
−2 −2 −6
= −7 −2 −2
1 1 1

Qno 2 Rotate a triangle by 900 with co-ordinates values(1,1),(2,3),(3,2)


and then reflect the triangle by the x axis

Shearing

 In shearing the shape of the object changes we assumed that object


is making up of many layers.
 During shearing the top layer shifted a little ,the next layer is shifted
A little less and so on
 In shearing the bottom (layer is not shifted)
 There are two common methods of shearing
1. Shearing in x direction (x direction shearing)
2. Shearing in y direction (y direction 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-

Shearing in Y axis is achieved by using the following shearing equations-

 Xnew = Xold
 Ynew = Yold + Shy * Xold

In Matrix form, the above shearing equations may be represented as-


For homogeneous coordinates, the above shearing matrix may be
represented as a 3 x 3 matrix as-

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

Thus, New coordinates of corner A after shearing = (3, 1).

For Coordinates B(0, 0)


Let the new coordinates of corner B after shearing = (Xnew, Ynew).
Applying the shearing equations, we have-
 Xnew = Xold + Shx x Yold = 0 + 2 x 0 = 0
 Ynew = Yold = 0

Thus, New coordinates of corner B after shearing = (0, 0).


For Coordinates C(1, 0)
Let the new coordinates of corner C after shearing = (Xnew, Ynew).
Applying the shearing equations, we have-
 Xnew = Xold + Shx x Yold = 1 + 2 x 0 = 1
 Ynew = Yold = 0

Thus, New coordinates of corner C after shearing = (1, 0).


Thus, New coordinates of the triangle after shearing in X axis = A (3, 1),
B(0, 0), C(1, 0).

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

Thus, New coordinates of corner A after shearing = (1, 3).


For Co-ordinates B(0, 0)
Let the new coordinates of corner B after shearing = (Xnew, Ynew).
Applying the shearing equations, we have-
 Xnew = Xold = 0
 Ynew = Yold + Shy x Xold = 0 + 2 x 0 = 0
Thus, New coordinates of corner B after shearing = (0, 0).
For Co-ordinates C(1, 0)
Let the new coordinates of corner C after shearing = (Xnew, Ynew).

Applying the shearing equations, we have-


 Xnew = Xold = 1
 Ynew = Yold + Shy x Xold = 0 + 2 x 1 = 2

Thus, New co-ordinates of corner C after shearing = (1, 2).


Thus, New coordinates of the triangle after shearing in Y axis = A (1, 3),
B(0, 0), C(1, 2).
Composite Transformation in 2-D graphics

 Composite transformations and their representation in homogeneous


coordinates.

Translation
Let T1 (tx1, ty1) and T2 (tx2,ty2) be two translations applied on a point
P(x,y) in succession.

Scaling

Let S1 (sx1,sy1) and S2 (sx2, sy2) be two rotations applied on a point


P(x,y) in succession, with respect to origin..

3-D Transformation: In very general terms a 3D model is a mathematical


representation of a physical entity that occupies space. In more practical terms,
a 3D model is made of a description of its shape and a description of its color
appearance

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.

If P is a point having co-ordinates in three directions (x, y, z) is translated, then


after translation its coordinates will be (x i yi zi) after translation. Tx Ty Tz are
translation vectors in x, y, and z directions respectively.

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.

Following figures shows rotation about x, y, z- axis


Matrix for representing three-dimensional rotations about the
Z axis
Equation:-xi=xcosɵ - ysinɵ
Yi=xsinɵ + ycosɵ
Zi=z

Matrix for representing three-dimensional rotations


about the X axis

Equation:-xi=x
Yi=ycosɵ - zsinɵ
Zi=ysinɵ + zcosɵ

Matrix for representing three-dimensional rotations


about the Y axis
Equation:-xi=zsinɵ - xsinɵ
Yi=y
Zi=zcosɵ-xsinɵ

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-

 Old coordinates = (Xold, Yold, Zold) = (1, 2, 3)


 Rotation angle = θ = 90º

For X-Axis Rotation-

Let the new coordinates after rotation = (Xnew, Ynew, Znew).


Applying the rotation equations, we have-

 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

Thus, New coordinates after rotation = (1, -3, 2).


For Y-Axis Rotation-

Let the new coordinates after rotation = (Xnew, Ynew, Znew).

Applying the rotation equations, we have-


 Xnew = 3 x sin90° + 1 x cos90° = 3 x 1 + 1 x 0 = 3
 Ynew = Yold = 2
 Znew =2 x cos90° – 1 x sin90° = 2 x 0 – 1 x 1 = -1

Thus, New coordinates after rotation = (3, 2, -1).

For Z-Axis Rotation-

Let the new coordinates after rotation = (Xnew, Ynew, Znew).

Applying the rotation equations, we have-


 Xnew = Xold x cosθ – Yold x sinθ = 1 x cos90° – 2 x sin90° = 1 x 0 – 2 x 1 = -2
 Ynew = Xold x sinθ + Yold x cosθ = 1 x sin90° + 2 x cos90° = 1 x 1 + 2 x 0 = 1
 Znew = Zold = 3

New coordinates after rotation = (-2, 1, 3).

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.

Sx=Scaling factor in x-direction


Sy=Scaling factor in y-direction

Sz=Scaling factor in z-direction

Matrix for Scaling

Xl=sx.x
Yl=sy.y
Z1=sz*z

(Sx) scale object in x direction


(Sy) scale object in y direction
(Sz) scale object in z direction

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

For Coordinates A(0, 3, 3)


Let the new coordinates of A after scaling = (Xnew, Ynew, Znew).

Applying the scaling equations, we have-


 Xnew = Xold x Sx = 0 x 2 = 0
 Ynew = Yold x Sy = 3 x 3 = 9
 Znew = Zold x Sz = 3 x 3 = 9

Thus, New coordinates of corner A after scaling = (0, 9, 9).

For Coordinates B(3, 3, 6)

Let the new coordinates of B after scaling = (Xnew, Ynew, Znew).

Applying the scaling equations, we have-


 Xnew = Xold x Sx = 3 x 2 = 6
 Ynew = Yold x Sy = 3 x 3 = 9
 Znew = Zold x Sz = 6 x 3 = 18

Thus, New coordinates of corner B after scaling = (6, 9, 18).

For Coordinates C(3, 0, 1)

Let the new coordinates of C after scaling = (Xnew, Ynew, Znew).

Applying the scaling equations, we have-


 Xnew = Xold x Sx = 3 x 2 = 6
 Ynew = Yold x Sy = 0 x 3 = 0
 Znew = Zold x Sz = 1 x 3 = 3

Thus, New coordinates of corner C after scaling = (6, 0, 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.

 Reflection is a kind of rotation where the angle of rotation is 180 degree.


 The reflected object is always formed on the other side of mirror.
 The size of reflected object is same as the size of original object.

Consider a point object O has to be reflected in a 3D plane.


Let-
Initial coordinates of the object O = (Xold, Yold, Zold)
New coordinates of the reflected object O after reflection = (Xnew, Ynew,Znew)

In 3 dimensions, there are 3 possible types of reflection-

 Reflection relative to XY plane


 Reflection relative to YZ plane
 Reflection relative to XZ plane
Reflection Relative to XY Plane:

This reflection is achieved by using the following reflection equations-


 Xnew = Xold
 Ynew = Yold
 Znew = -Zold

In Matrix form, the above reflection equations may be represented as-

Reflection Relative to YZ Plane:

This reflection is achieved by using the following reflection equations-


 Xnew = -Xold
 Ynew = Yold
 Znew = Zold

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

For Coordinates A(3, 4, 1)

Let the new coordinates of corner A after reflection = (Xnew, Ynew, Znew).

Applying the reflection equations, we have-


 Xnew = Xold = 3
 Ynew = Yold = 4
 Znew = -Zold = -1

Thus, New coordinates of corner A after reflection = (3, 4, -1).

For Coordinates B(6, 4, 2)

Let the new coordinates of corner B after reflection = (Xnew, Ynew, Znew).

Applying the reflection equations, we have-


 Xnew = Xold = 6
 Ynew = Yold = 4
 Znew = -Zold = -2

Thus, New coordinates of corner B after reflection = (6, 4, -2).


For Coordinates C(5, 6, 3)

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

Thus, New coordinates of corner C after reflection = (5, 6, -3).


Thus, New coordinates of the triangle after reflection = A (3, 4, -1), B(6, 4, -2), C(5,
6, -3).

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).

Applying the reflection equations, we have-


 Xnew = Xold = 3
 Ynew = -Yold = -4
 Znew = Zold = 1

Thus, New coordinates of corner A after reflection = (3, -4, 1).

For Coordinates B(6, 4, 2)

Let the new coordinates of corner B after reflection = (Xnew, Ynew, Znew).

Applying the reflection equations, we have-


 Xnew = Xold = 6
 Ynew = -Yold = -4
 Znew = Zold = 2

Thus, New coordinates of corner B after reflection = (6, -4, 2).

For Coordinates C(5, 6, 3)

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

Thus, New coordinates of corner C after reflection = (5, -6, 3).


Thus, New coordinates of the triangle after reflection = A (3, -4, 1), B(6, -4, 2), C(5,
-6, 3).

3D Shearing

 Shearing in X direction
 Shearing in Y direction
 Shearing in Z direction

Consider a point object O has to be sheared in a 3D plane.

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 X axis is achieved by using the following shearing equations-


 Xnew = Xold
 Ynew = Yold + Shy x Xold
 Znew = Zold + Shz x Xold

In Matrix form, the above shearing equations may be represented as-

Shearing in Y Axis-

Shearing in Y axis is achieved by using the following shearing equations-


 Xnew = Xold + Shx x Yold
 Ynew = Yold
 Znew = Zold + Shz x Yold

In Matrix form, the above shearing equations may be represented as-


Shearing in Z Axis-

Shearing in Z axis is achieved by using the following shearing equations-


 Xnew = Xold + Shx x Zold
 Ynew = Yold + Shy x Zold
 Znew = Zold

In Matrix form, the above shearing equations may be represented as-


3D SHEARING IN COMPUTER GRAPHICS-
Given a 3D triangle with points (0, 0, 0), (1, 1, 2) and (1, 1, 3). Apply shear
parameter 2 on X axis, 2 on Y axis and 3 on Z axis and find out the new
coordinates of the object.

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-

For Coordinates A(0, 0, 0)


Let the new coordinates of corner A after shearing = (Xnew, Ynew, Znew).

Applying the shearing equations, we have-


 Xnew = Xold = 0
 Ynew = Yold + Shy x Xold = 0 + 2 x 0 = 0
 Znew = Zold + Shz x Xold = 0 + 3 x 0 = 0

Thus, New coordinates of corner A after shearing = (0, 0, 0).

For Coordinates B(1, 1, 2)

Let the new coordinates of corner B after shearing = (Xnew, Ynew, Znew).

Applying the shearing equations, we have-


 Xnew = Xold = 1
 Ynew = Yold + Shy x Xold = 1 + 2 x 1 = 3
 Znew = Zold + Shz x Xold = 2 + 3 x 1 = 5

Thus, New coordinates of corner B after shearing = (1, 3, 5).

For Coordinates C(1, 1, 3)

Let the new coordinates of corner C after shearing = (Xnew, Ynew, Znew).

Applying the shearing equations, we have-


 Xnew = Xold = 1
 Ynew = Yold + Shy x Xold = 1 + 2 x 1 = 3
 Znew = Zold + Shz x Xold = 3 + 3 x 1 = 6

Thus, New coordinates of corner C after shearing = (1, 3, 6).


Thus, New coordinates of the triangle after shearing in X axis = A (0, 0, 0), B(1, 3,
5), C(1, 3, 6).

Shearing in Y Axis-

For Coordinates A(0, 0, 0)

Let the new coordinates of corner A after shearing = (Xnew, Ynew, Znew).

Applying the shearing equations, we have-


 Xnew = Xold + Shx x Yold = 0 + 2 x 0 = 0
 Ynew = Yold = 0
 Znew = Zold + Shz x Yold = 0 + 3 x 0 = 0

Thus, New coordinates of corner A after shearing = (0, 0, 0).

For Coordinates B(1, 1, 2)

Let the new coordinates of corner B after shearing = (Xnew, Ynew, Znew).

Applying the shearing equations, we have-


 Xnew = Xold + Shx x Yold = 1 + 2 x 1 = 3
 Ynew = Yold = 1
 Znew = Zold + Shz x Yold = 2 + 3 x 1 = 5

Thus, New coordinates of corner B after shearing = (3, 1, 5).

For Coordinates C(1, 1, 3)

Let the new coordinates of corner C after shearing = (Xnew, Ynew, Znew).

Applying the shearing equations, we have-

 Xnew = Xold + Shx x Yold = 1 + 2 x 1 = 3


 Ynew = Yold = 1
 Znew = Zold + Shz x Yold = 3 + 3 x 1 = 6

Thus, New coordinates of corner C after shearing = (3, 1, 6).


Thus, New coordinates of the triangle after shearing in Y axis = A (0, 0, 0), B(3, 1,
5), C(3, 1, 6).

Shearing in Z Axis-

For Coordinates A(0, 0, 0)

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

Thus, New coordinates of corner A after shearing = (0, 0, 0).

For Coordinates B(1, 1, 2)

Let the new coordinates of corner B after shearing = (Xnew, Ynew, Znew).

Applying the shearing equations, we have-


 Xnew = Xold + Shx x Zold = 1 + 2 x 2 = 5
 Ynew = Yold + Shy x Zold = 1 + 2 x 2 = 5
 Znew = Zold = 2

Thus, New coordinates of corner B after shearing = (5, 5, 2).

For Coordinates C(1, 1, 3)

Let the new coordinates of corner C after shearing = (Xnew, Ynew, Znew).

Applying the shearing equations, we have-


 Xnew = Xold + Shx x Zold = 1 + 2 x 3 = 7
 Ynew = Yold + Shy x Zold = 1 + 2 x 3 = 7
 Znew = Zold = 3

Thus, New coordinates of corner C after shearing = (7, 7, 3).

Mid Point Circle Drawing Algorithm-

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-

 Centre Coordinates of Circle (X0, Y0) = (0, 0)


 Radius of Circle = 10

Step-01:
Assign the starting point coordinates (X0, Y0) as-
 X0 = 0
 Y0 = R = 10

Step-02:

Calculate the value of initial decision parameter P0 as-


P0 = 1 – R
P0 = 1 – 10
P0 = -9

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)

Mid Point Circle programme


#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=1-r;
while(x<=y)
{

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();
}
}

Bresenham’s circle drawing algorithm


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 values:-
a) d(decision variable)=3-2r
7) other values are(not initial values)
a)ds=4*x+6
b)dp=4(x-y)+10

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

Bresenham’s circle programme

#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();
}

General Pivot Point Rotation or Rotation about Fixed Point:

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

Scaling to fixed point:

For this following steps are performed:

Step1: The object is kept at desired location as shown in fig (a)

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)

Step4: Again translation is done. This translation is called as reverse


translation.
| || || |
1 0 xf sx 0 0 1 0 −xf
=0 1 yf ∗ 0 sy 0 ∗ 0 1 − yf ∗p
0 0 1 0 0 1 0 0 1

| |
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:

Lines are of three types:

1. Visible: A line or lines entirely inside the window is considered visible


2. Invisible: A line entirely outside the window is considered invisible
3. Clipped: A line partially inside the window and partially outside is clipped. For clipping
point of intersection of a line with the window is determined.
Clipping can be applied through hardware as well as software. In some computers, hardware
devices automatically do work of clipping. In a system where hardware clipping is not
available software clipping applied.

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. Cohen Sutherland Line Clipping Algorithm

Cohen Sutherland Line Clipping Algorithm:


In the algorithm, first of all, it is detected whether line lies inside the screen or it is outside the
screen. All lines come under any one of the following categories:

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.

Step1: Calculate positions of both endpoints of the line

Step2: Perform OR operation on both of these end-points

Step3:If the OR operation gives 0000 Then line is considered to be visible


Else
Perform and operation on both endpoints if and≠0000 then the line is invisible else
And=0000

Line is considered the clipped case.

Step4:If a line is clipped case, find an intersection with boundaries of the window
m=(y2-y1 )(x2-x1)

(a) If bit 1 is "1" line intersect with left boundary of


rectangle window
y3=y1+m(x-X1)
where X=Xwmin where Xwminis the minimum value of X co-ordinate of window

(b) If bit 2 is "1" line intersect with right boundary


y3=y1+m(X-X1)
where(X=Xwmax where X more is maximum value of X co-ordinate of the window

(c) If bit 3 is "1" line intersects with


bottom boundary
X3=X1+(y-y1)/m
where y=ywmi where ywmin is the minimum value of Y co-ordinate of the window

(d) If bit 4 is "1" line intersects with the top boundary


X3=X1+(y-y1)/m
where(y=ywmax) ywmax is the maximum value of Y co-ordinate of the window

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

Now we find x1 & y1

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

Representing an n-dimensional object into an n-1 dimension is known as projection. It is


process of converting a 3D object into 2D object, we represent a 3D object on a 2D plane.
When geometric objects are formed by the intersection of lines with a plane, the plane is
called the projection plane and the lines are called projections.
Types of Projections:
1. Parallel projections
2. Perspective 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:

In orthographic projection the direction of projection is normal to the projection of the


plane. In orthographic lines are parallel to each other making an angle 90 with view plane.
Orthographic parallel projections are done by projecting points along parallel lines that are
perpendicular to the projection line. Orthographic projections are most often used to
procedure the front, side, and top views of an object are called evaluations.

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

A common example is the circle, whose implicit representation is

x2 + y 2 - R 2 = 0

Explicit Curves

A mathematical function y = fx can be plotted as a curve. Such a function is the explicit


representation of the curve. The explicit representation is not general, since it cannot
represent vertical lines and is also single-valued. For each value of x, only a single value of y is
normally computed by the function.
Parametric 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 −

Pt = ft, gt or Pt= xt, yt

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.

Interpolation & Approximation splines






 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.

 A set of six control points approximate with piecewise continuous polynomial


section.

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

Types of Polynomial Functions


The name of a polynomial is determined by the number of terms in it. The three most
common polynomials we usually encounter are monomials, binomials, and trinomials.

 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

Zero polynomial function

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.

Linear polynomial 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.

Quadratic polynomial function

A quadratic polynomial function has a degree 2. It is of the form f(x) = ax 2 + bx + c.

Graphing Polynomial Functions


To graph a simple polynomial function, we usually make a table of values with some random
values of x and the corresponding values of f(x). Then we plot the points from the table and join
them by a curve. Let us draw the graph for the quadratic polynomial function f(x) = x2.
x -2 -1 0 1 2

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.

You might also like