SlideShare a Scribd company logo
1 of 492
Computer Graphics
Aoun-Haider
Introduction:
• Computer Graphics involves technology to access. The Process transforms and presents
information in a visual form. The role of computer graphics insensible. In today life, computer
graphics has now become a common element in user interfaces, T.V. commercial motion pictures.
• Computer Graphics is the creation of pictures with the help of a computer. The end product of the
computer graphics is a picture it may be a business graph, drawing, and engineering.
• In computer graphics, two or three-dimensional pictures can be created that are used for
research. Many hardware devices algorithm has been developing for improving the speed of
picture generation with the passes of time. It includes the creation storage of models and image
of objects. These models for various fields like engineering, mathematical and so on.
• Today computer graphics is entirely different from the earlier one. It is not possible. It is an
interactive user can control the structure of an object of various input devices.
Application:
• Education & Training
• Flight simulator
• Computational biology
• Computer generated maps
• Architect
• Presentation
• Computer art
• Entertainment
• Visualization
• printing technology
Types of CG:
• Non-interactive/passive graphics: user has no control over generated
graphics. In simple words, read only graphics are non-interactive
because user is unable to interact with like titles in TV. It is one way
communication. User cannot make changes in the available
resources.
• Interactive graphics: user have some controls over the picture, i.e.,
the user can make any change in the produced image. One example
of it is the ping-pong game. Interactive Computer Graphics require
two-way communication between the computer and the user. A User
can see the image and make any change by sending his command
with an input device.
Cont.
Display technologies:
• Shadow mark technology: also known as shadow X-ray or silhouette
X-ray, relies on the principle of image contrast. When an object is
placed between an X-ray source and a detector, the X-rays are
attenuated or blocked by the object, resulting in a shadow or
silhouette image(image void of internal details) on the detector. This
technique is commonly used for two-dimensional (2D) X-ray
inspection. Shadow Mask Method is commonly used in Raster-
Scan System because they produce a much wider range of
colors than the beam-penetration method.
• It is used in the majority of color TV sets and monitors.
Cont.
• Beam penetration technology: Beam penetration technology, also
known as penetrating X-ray or transmission X-ray, is based on the
principle of X-ray penetration through materials. This technique is
typically used for three-dimensional (3D) X-ray inspection. The Beam-
Penetration method has been used with random-scan monitors. In
this method, the CRT screen is coated with two layers of phosphor,
red and green and the displayed color depends on how far the
electron beam penetrates the phosphor layers. This method produces
four colors only, red, green, orange and yellow. A beam of slow
electrons excites the outer red layer only; hence screen shows red
color only. A beam of high-speed electrons excites the inner green
layer. Thus screen shows a green color. Only 4 colors are possible.
Direct view storage tubes:
• A Display Storage Tube (DST), also known as a Storage Tube or a Storage
Oscilloscope, is a specialized type of cathode ray tube (CRT) used in
electronic display systems. It was primarily used in older computer
terminals and oscilloscopes.
• The Display Storage Tube functions as a combination of a regular CRT and a
temporary storage medium. It allows the persistent display of an image
even after the original signal has been removed. This is accomplished by
introducing a phosphor coating on the screen that can retain the image for
an extended period, typically several minutes or longer.
• It is not possible to erase specific part of image.
• Not suitable for dynamic display devices.
• Slow processing rate but cheap.
Working:
• Electron Beam Scanning: Similar to a regular CRT, a Display
Storage Tube consists of an electron gun that emits an electron
beam. The beam is focused and accelerated towards the screen,
which is coated with a phosphor material.
• Phosphor Coating: The phosphor coating on the Display Storage
Tube screen is designed to have a longer persistence than the
phosphor used in regular CRTs. This allows the image to remain
visible for an extended period after the electron beam has
passed.
• Writing and Erasing: When an electrical signal is applied to the
electron beam, it scans across the screen, exciting the phosphor
and causing it to emit light. This creates the visible image. The
phosphor coating retains the charge and continues to emit light
even after the beam has moved to another location.
• Image Persistence: The stored image on the Display Storage Tube
screen remains visible until it is erased. Erasing is usually done by
either applying a blanking signal to the electron beam or by
flooding the screen with an intense light source that dissipates
the stored charge.
Flat Panel display:
• The Flat-Panel display refers to a class of video devices that
have reduced volume, weight and power requirement compared
to CRT.
• Example: Small T.V. monitor, calculator, pocket video games,
laptop computers, an advertisement board in elevator.
Cont.
• Emissive Display: The emissive displays are devices that
convert electrical energy into light. Examples are Plasma Panel,
thin film electroluminescent display and LED (Light Emitting
Diodes).
• Non-Emissive Display: The Non-Emissive displays use optical
effects to convert sunlight or light from some other source into
graphics patterns. Examples are LCD (Liquid Crystal Device).
Basic terminology:
• Pixel: smallest point in display
• Resolution: total number of pixel in picture or screen
Resolution = Width X Height
Width = number of horizontal pixels
Height = number of vertical pixels
• Pixel per inch (PPI): number of pixel per inch computed from diagonal distance
• Aspect ratio: ratio of height and width commonly 4:3
• Frame buffer: storage area used to display graphics content (picture, image)
• Persistence: Amount of time a frame takes to be displayed before refreshing.
Illustration:
Width = 1920
Height = 1080
Resolution = 1920 x 1080
PPI =√ a2 + b2
= √ 19202 + 10802
√ 3686400 + 1166400
= 2202/5 inch
= 440 PPI
Graphic processing unit (GPU):
Cathode ray tube:
• A cathode ray tube (CRT) is a specialized vacuum tube in which
images are produced when an electron beam strikes a
phosphorescent surface. It modulates, accelerates, and deflects
electron beam(s) onto the screen to create the images. Most desktop
computer displays make use of CRT for image-displaying purposes.
Working:
Electron Beam Generation:
Inside the CRT, an electron gun emits a focused beam of electrons. The electron gun consists
of a cathode that emits electrons and an anode that accelerates and focuses the electrons
into a narrow beam.
Deflection:
The electron beam is then deflected by electromagnetic coils or plates located around the
neck of the CRT. These electromagnetic fields steer the beam horizontally and vertically,
allowing it to scan across the entire screen.
Phosphor-Coated Screen:
The front of the CRT screen is coated with a layer of phosphors. Phosphors are chemical
compounds that emit light when struck by electrons. Different phosphors can emit different
colors of light.
Pixel Intensity Control:
The pixel intensity is controlled by modulating the strength of the electron beam. A higher
intensity results in a brighter pixel, while a lower intensity results in a dimmer pixel.
Cont.
Scanning the Screen:
The electron beam scans the screen line by line, starting from the top left
corner and moving horizontally across each line. As the beam moves, it emits
electrons that strike the phosphor-coated screen.
Light Emission:
When the electron beam hits the phosphor-coated screen, the phosphors
emit light in response to the energy transferred by the electrons. The
emitted light corresponds to the color of the phosphor and the intensity of
the electron beam.
Persistence:
Phosphors have a property called persistence, which means they continue to
emit light for a short period even after the electron beam has moved away.
This persistence helps maintain the image on the screen until the next scan.
CRT diagram:
Scanning techniques
There are different strategies followed by different system.
1) Vector/Random scan display
2) Raster scan display
Vector/random scan display:
• In Random-Scan Display electron beam is directed only to the areas of
screen where a picture has to be drawn. It is also called vector display, as it
draws picture one line at time. It can draw and refresh component lines of
a picture in any specified sequence. Pen plotter is an example of random-
scan displays.
• The number of lines regulates refresh rate on random-scan displays. An
area of memory called refresh display files stores picture definition as a set
of line drawing commands. The system returns back to first-line command
in the list, after all the drawing commands have been processed. High-
quality vector systems can handle around 100, 00 short lines at this refresh
rate. Faster refreshing can burn phosphor. To avoid this every refresh cycle
is delayed to prevent refresh rate greater than 60 frames per second.
Cont.
ADVANTAGES:
• Higher resolution as compared to raster scan display.
• Produces smooth line drawing.
• Less Memory required.
DISADVANTAGES:
• Realistic images with different shades cannot be drawn.
• Color limitations.
Raster scan display:
• Raster Scan Displays are most common type of graphics monitor which employs CRT. It
is based on television technology. In raster scan system electron beam sweeps across
the screen, from top to bottom covering one row at a time. A pattern of illuminated
pattern of spots is created by turning beam intensity on and off as it moves across
each row. A memory area called refresh buffer or frame buffer stores picture
definition. This memory area holds intensity values for all screen points. Stored
intensity values are restored from frame buffer and painted on screen taking one row
at a time. Each screen point is referred to as pixels.
• In raster scan systems refreshing is done at a rate of 60-80 frames per second. Refresh
rates are also sometimes described in units of cycles per second / Hertz (Hz). At the
end of each scan line, electron beam begins to display next scan line after returning to
left side of screen. The return to the left of screen after refresh of each scan line is
known as horizontal retrace of electron beam. At the end of each frame electron
beam returns to top left corner and begins the next frame.
Cont.
ADVANTAGES:
• Real life images with different shades can be displayed.
• Color range available is bigger than random scan display.
DISADVANTAGES:
• Resolution is lower than random scan display.
• More memory is required.
• Data about the intensities of all pixel has to be stored.
Interlaced scan display:
Interlaced scan is a display technique where the image is split
into two fields, displaying odd-numbered lines in one pass
(called the odd field) and even-numbered lines in the next pass
(called the even field). The screen is scanned in an alternating
pattern, filling in the missing lines with each pass. Interlaced
scan was more prevalent in older display technologies like CRT
televisions and some computer monitors. While it requires
fewer video resources, interlaced scan can sometimes result in
flickering and reduced image quality, especially with fast-
moving content.
Progressive scan display:
• Progressive scan display is a way of showing images on a screen in a
smooth and continuous manner. It works by displaying all the lines of
an image one after another, from top to bottom, in a sequence. This
happens very quickly, with each line appearing so fast that our eyes
perceive it as a complete image.
• Imagine you're drawing a picture by filling it in line by line. With
progressive scan, you start at the top of the picture and draw each
line until you reach the bottom. This method ensures that the entire
image is displayed at once, creating a clear and seamless picture.
Line drawing algorithms
Digital differential analyzer (DDA)
Bresenhams’ Line generation algorithm
Digital differential analyzer:
• DDA (Digital Differential Analyzer) 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.
Slope values
• Case#01: Draw horizontal line: m = 0
Slope values
• Case#02: Draw vertical line: m = undefined
Slope values
• Case#03: Draw diagonal line: m = 1
Important concept:
m = 1, Angle = 45 degree
m < 1
m > 1
∆x = x2 – x1
∆y = y2 – y1
Algorithm:
• Input the two endpoints of the line segment, (x1,y1) and (x2,y2).
• Calculate the difference between the x-coordinates and y-coordinates
of the endpoints as dx and dy respectively.
• Calculate the slope of the line as m = dy/dx.
• Set the initial point of the line as (x1,y1).
• 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(x – x1).
• Plot the pixel at the calculated (x,y) coordinate.
• Repeat steps 5 and 6 until the endpoint (x2,y2) is reached.
The line of equation for step i
yi=mxi+b......................equation 1
Next value will be
m = y2-y1 / x2 – x1 => ∆y / ∆x
We can also extract ∆x and ∆y from above equation
∆y=m∆x
∆x=∆y/m
Rules:
Case1: When |∆x| >= |∆y|
Then: Assign ∆x = 1
Xi+1 = xi + ∆x = xi + 1
yi+1 = yi + ∆y = yi + m ∆x = yi + m
Case2: When |∆x| < |∆y|
Then: Assign ∆y = 1
yi+1 = yi + ∆y = yi + 1
xi+1 = xi + ∆x = xi + ∆y / m = xi + 1/m
Example:
• Draw a line from (1,1) to (3,3) ??
Solution:
Draw a line from (1,1) to (3,3)
X1 = 1, y1 = 1 & x2 =3, y2 = 3
m = y2-y1 / x2 – x1 => ∆y / ∆x = 3 – 1/ 3 – 1 = 2/2 = 1
Find ∆x & ∆y:
∆y=m∆x = 1 X 2 = 2
∆x=∆y/m = 2/1 = 2
Cont.
xi yi xi+1 Yi+1
1 1
Xi, yi = current value , xi+1, yi+1 = next computed value
m = 1
∆x =2 , ∆y = 2
|∆x| >= |∆y| (Case#01) 2 = 2
Xi+1 = xi + ∆x = xi + 1 = 1 + 1 = 2
yi+1 = yi + ∆y = yi + m ∆x = yi + m = 1 + 1 = 2
1 2 3 4
3
2
1
0
Cont.
xi yi xi+1 Yi+1
1 1 2 2
2 2
m = 1
∆x =2 , ∆y = 2
|∆x| >= |∆y| (Case#01) 2 = 2
Xi+1 = xi + ∆x = xi + 1 = 1 + 1 = 2
yi+1 = yi + ∆y = yi + m ∆x = yi + m = 1 + 1 = 2
1 2 3 4
3
2
1
0
*
Cont.
xi yi xi+1 Yi+1
1 1 2 2
2 2
m = 1
∆x =2 , ∆y = 2
|∆x| >= |∆y| (Case#01) 2 = 2
Xi+1 = xi + ∆x = xi + 1 = 2 + 1 = 3
yi+1 = yi + ∆y = yi + m ∆x = yi + m = 2 + 1 = 3
1 2 3 4
3
2
1
0
*
*
Cont.
xi yi xi+1 Yi+1
1 1 2 2
2 2 3 3
m = 1
∆x =2 , ∆y = 2
|∆x| >= |∆y| (Case#01) 2 = 2
Xi+1 = xi + ∆x = xi + 1 = 2 + 1 = 3
yi+1 = yi + ∆y = yi + m ∆x = yi + m = 2 + 1 = 3
1 2 3 4
3
2
1
0
*
*
*
Cont.
xi yi xi+1 Yi+1
1 1 2 2
2 2 3 3
m = 1
∆x =2 , ∆y = 2
|∆x| >= |∆y| (Case#01) 2 = 2
Xi+1 = xi + ∆x = xi + 1 = 2 + 1 = 3
yi+1 = yi + ∆y = yi + m ∆x = yi + m = 2 + 1 = 3
Done!!
1 2 3 4
3
2
1
0
*
*
*
Practice:
• Draw a line from (3,1) to (5,7) ??
Solution:
Draw a line from (3,1) to (5,7)
X1 = 3, y1 = 1 & x2 =5, y2 = 7
m = y2-y1 / x2 – x1 => ∆y / ∆x = 7 – 1/ 5 – 3 = 6/2 = 3
Find ∆x & ∆y:
∆y=m∆x = 3 X 2 = 6
∆x=∆y/m = 6/3 = 2
Cont.
xi yi xi+1 Yi+1
3 1
Xi, yi = current value , xi+1, yi+1 = next computed value
m = 3
∆x =2 , ∆y = 6
|∆x| < |∆y| (Case#02) 2 = 2
∆y = 1
yi+1 = yi + ∆y = yi + 1 = 1 + 1 = 2
xi+1 = xi + ∆x = xi + ∆y / m = xi + 1/m = 3 + 1/3 = 3.3
1 2 3 4 5 6 7
3
2
1
0
4
5
6
7
*
Cont.
xi yi xi+1 Yi+1
3 1 3.3 2
3.3 2
Xi, yi = current value , xi+1, yi+1 = next computed value
m = 3
∆x =2 , ∆y = 6
|∆x| < |∆y| (Case#02) 2 = 2
∆y = 1
yi+1 = yi + ∆y = yi + 1 = 1 + 1 = 2
xi+1 = xi + ∆x = xi + ∆y / m = xi + 1/m = 3 + 1/3 = 3.3
1 2 3 4 5 6 7
3
2
1
0
4
5
6
7
*
*
Cont.
xi yi xi+1 Yi+1
3 1 3.3 2
3.3 2 3.8 3
3.8 3
Xi, yi = current value , xi+1, yi+1 = next computed value
m = 3
∆x =2 , ∆y = 6
|∆x| < |∆y| (Case#02) 2 = 2
∆y = 1
yi+1 = yi + ∆y = yi + 1 = 2 + 1 = 3
xi+1 = xi + ∆x = xi + ∆y / m = xi + 1/m = 3.5 + 0.3 = 3.8
1 2 3 4 5 6 7
3
2
1
0
4
5
6
7
*
*
*
Cont.
xi yi xi+1 Yi+1
3 1 3.3 2
3.3 2 3.8 3
3.8 3 4.1 4
Xi, yi = current value , xi+1, yi+1 = next computed value
m = 3
∆x =2 , ∆y = 6
|∆x| < |∆y| (Case#02) 2 = 2
∆y = 1
yi+1 = yi + ∆y = yi + 1 = 3 + 1 = 4
xi+1 = xi + ∆x = xi + ∆y / m = xi + 1/m = 3.8 + 0.3 = 4.1
1 2 3 4 5 6 7
3
2
1
0
4
5
6
7
*
*
*
*
Cont.
xi yi xi+1 Yi+1
3 1 3.3 2
3.3 2 3.8 3
3.8 3 4.1 4
4 4.1 4.4 5
4.4 5
Xi, yi = current value , xi+1, yi+1 = next computed value
m = 3
∆x =2 , ∆y = 6
|∆x| < |∆y| (Case#02) 2 = 2
∆y = 1
yi+1 = yi + ∆y = yi + 1 = 4 + 1 = 5
xi+1 = xi + ∆x = xi + ∆y / m = xi + 1/m = 4.1 + 0.3 = 4.4
1 2 3 4 5 6 7
3
2
1
0
4
5
6
7
*
*
*
*
*
Cont.
xi yi xi+1 Yi+1
3 1 3.3 2
3.3 2 3.8 3
3.8 3 4.1 4
4 4.1 4.4 5
4.4 5 4.7 6
4.7 6 5 7
Xi, yi = current value , xi+1, yi+1 = next computed value
m = 3
∆x =2 , ∆y = 6
|∆x| < |∆y| (Case#02) 2 = 2
∆y = 1
yi+1 = yi + ∆y = yi + 1 = 6 + 1 = 7
xi+1 = xi + ∆x = xi + ∆y / m = xi + 1/m = 4.7 + 0.3 = 5
1 2 3 4 5 6 7
3
2
1
0
4
5
6
7
*
*
*
*
*
*
Cont.
xi yi xi+1 Yi+1
3 1 3.3 2
3.3 2 3.8 3
3.8 3 4.1 4
4 4.1 4.4 5
4.4 5 4.7 6
4.7 6 5 7
Xi, yi = current value , xi+1, yi+1 = next computed value
m = 3
∆x =2 , ∆y = 6
|∆x| < |∆y| (Case#02) 2 = 2
∆y = 1
yi+1 = yi + ∆y = yi + 1 = 6 + 1 = 7
xi+1 = xi + ∆x = xi + ∆y / m = xi + 1/m = 4.7 + 0.3 = 5
1 2 3 4 5 6 7
3
2
1
0
4
5
6
7
*
*
*
*
*
*
*
Cont.
xi yi xi+1 Yi+1
3 1 3.3 2
3.3 2 3.8 3
3.8 3 4.1 4
4 4.1 4.4 5
4.4 5 4.7 6
4.7 6 5 7
Xi, yi = current value , xi+1, yi+1 = next computed value
m = 3
∆x =2 , ∆y = 6
|∆x| < |∆y| (Case#02) 2 = 2
∆y = 1
yi+1 = yi + ∆y = yi + 1 = 6 + 1 = 7
xi+1 = xi + ∆x = xi + ∆y / m = xi + 1/m = 4.7 + 0.3 = 5
Done!! 1 2 3 4 5 6 7
3
2
1
0
4
5
6
7
*
*
*
*
*
*
*
Bresenhams’ algorithm:
• The problem with DDA algorithm is that it considers float values
which require extra computation and straight line is not achieved
properly. But bresenham algorithm takes maximum distance b/w two
pixels and generates a smooth and straight line.
Algorithm:
1. Compute slop of line ‘m’, ∆x = dy, ∆y = dy, pk = 2dy - dx
2. If m<1:
if p<0:
xi+1 = xi + 1
yi+1 = yi
pk+1 = pk + 2dy
if p>=0:
xi+1 = xi+1
yi+1 = yi+1
pk+1 = pk + 2dy – 2dx
Cont.
If m>=1:
if p<0:
xi+1 = xi
yi+1 = yi+1
pk+1 = pk + 2dx
if p>=0:
xi+1 = xi+1
yi+1 = yi+1
pk+1 = pk + 2dx – 2dy
Example:
Draw line from (1,1) to (5,3)
m = ∆y/∆x = 3 – 1/ 5 – 1 = 2/4 = 0.5
dx = x2 – x1 = 5 – 1 = 4
dy = y2 – y1 = 3 – 1 = 2
Pk = 2dy – dx = 2(2) – 4 = 0
m<1 (Condition#01)
Implementation:
pk xi yi xi+1 yi+1
0 1 1 2 2
-4 2 2
m<1 && pk>=0 (Case#02 of condition#01)
xi+1 = xi + 1 = 1 + 1 = 2
yi+1 = yi +1 = 1 + 1 = 2
Pk+1 = pk + 2dy -2dx = 0 + 2(2) - 2(4) = -4
1 2 3 4 5
1
2
4
3
0
*
Implementation:
pk xi yi xi+1 yi+1
0 1 1 2 2
-4 2 2
m<1 && pk>=0 (Case#02 of condition#01)
xi+1 = xi + 1 = 1 + 1 = 2
yi+1 = yi +1 = 1 + 1 = 2
Pk+1 = pk + 2dy -2dx = 0 + 2(2) - 2(4) = -4
1 2 3 4 5
1
2
4
3
0
*
*
Implementation:
pk xi yi xi+1 yi+1
0 1 1 2 2
-4 2 2 3 2
0 3 2
m<1 && pk<0 (Case#01 of condition#01)
xi+1 = xi + 1 = 2 + 1 = 3
yi+1 = yi = 2
Pk+1 = pk + 2dx = -4 + 2(2) = 0
1 2 3 4 5
1
2
4
3
0
*
* *
Implementation:
pk xi yi xi+1 yi+1
0 1 1 2 2
-4 2 2 3 2
0 3 2 4 3
-4 4 3
m<1 && pk>=0 (Case#02 of condition#01)
xi+1 = xi + 1 = 3 + 1 = 4
yi+1 = yi + 1 = 2 + 1 = 3
Pk+1 = pk + 2dy – 2dx = 0 + 2(2) – 2(4) = -4
1 2 3 4 5
1
2
4
3
0
*
* *
*
Implementation:
pk xi yi xi+1 yi+1
0 1 1 2 2
-4 2 2 3 2
0 3 2 4 3
-4 4 3 5 3
m<1 && pk<0 (Case#01 of condition#01)
xi+1 = xi + 1 = 4 + 1 = 5
yi+1 = yi = 3
Pk+1 = pk + 2dy = -4 + 2(2) = 0
1 2 3 4 5
1
2
4
3
0
*
* *
* *
Implementation:
pk xi yi xi+1 yi+1
0 1 1 2 2
-4 2 2 3 2
0 3 2 4 3
-4 4 3 5 3
m<1 && pk<0 (Case#01 of condition#01)
xi+1 = xi + 1 = 4 + 1 = 5
yi+1 = yi = 3
Pk+1 = pk + 2dy = -4 + 2(2) = 0
Done!!
1 2 3 4 5
1
2
4
3
0
*
* *
* *
Circle drawing algorithms
Bresenham circle drawing algorithm:
• We only need to compute one slice b/w 90 and 45 degree. All other
values will be computed by just mirroring and swapping x and y co-
ordinate.
Algorithm:
1. Compute x0 = starting point, y0 = radius = r
2. Compute decision parameter(P):
p = 3 – 2*R
3. If p<0:
xi+1 = xi + 1
yi+1 = yi
pi+1 = pi + 4xi+1 + 6
If p>=0:
xi+1 = xi + 1
yi+1 = yi - 1
pi+1 = pi + 4(xi+1 – yi+1) + 10
Example:
• Generate a circle from origin (0,0) with r = 8.
X0 = 0
Y0 = r = 8
• Calculate the value of initial decision parameter P0 as-
P0 = 3 – 2 x R
P0 = 3 – 2 x 8
P0 = -13
Cont.
• As Pinitial < 0, so case-01 is satisfied.
Xk+1 = Xk + 1 = 0 + 1 = 1
Yk+1 = Yk = 8
Pk+1 = Pk + 4 x Xk+1 + 6 = -13 + (4 x 1) + 6 = -3
Step-03 is executed similarly until Xk+1 >= Yk+1
Algorithm calculates all the points of octant-1 and terminates!!
Cont.
• Just take mirror of upper slice of one quadrant. Change the signs in
another quadrant accordingly.
Swapped
values
Mirror of upper
slice
Quadrant 2, 3 & 4 are
copy of quadrant-1
with sign changed
accordingly!!
Practice:
• Given the center point coordinates (10, 10) and radius as 10,
generate all the points to form a circle.
• Hint: Don’t apply hint here because origin is not (0,0)
Solution:
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 = 3 – 2 x R
P0 = 3 – 2 x 10
P0 = -17
Cont.
Step-03:
As Pinitial < 0, so case-01 is satisfied.
Thus,
Xk+1 = Xk + 1 = 0 + 1 = 1
Yk+1 = Yk = 10
Pk+1 = Pk + 4 x Xk+1 + 6 = -17 + (4 x 1) + 6 = -7
Step-04:
This step is applicable here as the given centre point coordinates is
(10, 10).
Xplot = Xc + X0 = 1 + 10 = 11
Yplot = Yc + Y0 = 10 + 10 = 20
Cont.
• Step-03 and Step-04 are executed similarly until Xplot => Yplot as
follows-
Other columns have
subtracted actual value from
20 because origin is 10 and
radius is double or 20
Bresenham midpoint circle drawing algorithm:
dk = distance between above and below axis
xk = x-coordinate
yk = y-coordinate
r = radius
Step#01: Compute dk = r-1
While xk < yk:
If dk < 0:
xk+1 = xk + 1
yk+1 = yk
dk+1 = dk + 2xk + 3
If dk > 0:
xk+1 = xk + 1
yk+1 = yk – 1
dk+1 = dk + 2xk – 2yk + 5
Cont.
Problem-1:
• Given the center point coordinates (0, 0) and radius as 10,
generate all the points to form a circle.
Solution:
Assign the starting point coordinates (X0, Y0) as-
X0 = 0
Y0 = R = 10
P0 = 1 – R
P0 = 1 – 10
P0 = -9
Pinitial < 0, so case-01 is satisfied.
Xk+1 = Xk + 1 = 0 + 1 = 1
Yk+1 = Yk = 10
Pk+1 = Pk + 2 x Xk+1 + 1 = -9 + (2 x 1) + 1 = -6
Note: dk is pk here
Cont.
• We can compute all the points in the same way:
Cont.
• Hence, all other points using first quadrant are:
Problem-2:
• Given the center point coordinates (4, -4) and radius as 10,
generate all the points to form a circle.
Solution:
• As the origin is other than (0,0), we find co-ordinates by assuming
center as (0,0). After computing, we will add the points.
• Just add 4 in every point
• If quadrant is negative like 2nd one, then subtract
original value from 4.
For example, in 1st row, 4 – 0 = 0 then (4, 14) are
the points of 1st row.
Cont.
Polygons
Lecture 3
Polygon:
• Shape having more than two points connected with each other. Line
segment which forms the boundary of polygon is known as edge
which end sides are vertices. It can be of any shape.
Types:
• Simple
• Complex
• Concave
• Convex
Simple polygon:
• Polygon having shape such that no line intersect other.
Not simple due to
intersecting lines
Simple
Complex polygon:
• Opposite of simple polygon.
• Shape having lines intersecting other (at least one)
Complex
Convex polygon:
• Such shape in which if we take any points which are surely inside the
polygon and if we draw a line joining these points and if all the points
lie inside the polygon, then such a polygon is convex. All the angles of
edges must be less then 180 degree.
Concave polygon:
• Such polygon in which if we take two points which are surely inside
the polygon and if we draw a line joining these points and if all the
points are not lying inside the polygon, then such a polygon is
concave polygon. Angle of edges > 180 (at least one)
Inside test of polygon:
• It is very important to know if a point is inside or outside the polygon
before starting to fill the polygon. Draw a horizontal line from point
left or right which is required to determined inside, if number of
points intersected by line are even, it is outside the polygon. If odd, it
is inside. There are two rare cases also need to consider discussed
next.
Odd – inside
Even - outside
Example:
• Let below point is need to determine whether it is inside or outside
the polygon.
• 1- put the point where required to determine.
Cont.
• Draw a horizontal line from point to left or right. Count number of
points intersected by line. In this case, total points are 3. So, point is
inside the polygon.
Cont.
• Let check another point in the same shape.
Number of intersected
points are 2(even). So, its
outside the polygon.
Issue with inside test method:
• Consider the point g which is outside the polygon, by checking via
algorithm, number of points intersected are 1 or 2??
Solution:
• Add extra step in the algorithm that if line is passed from such point
connected two or more line, check whether all the joined lines are
not same side of the or one above and one below or one left and one
right.
• If lines connected with intersected point are on the same side,
consider point as odd otherwise even.
Same side – even
Different side – odd
• Now apply this scheme on previous diagram.
Practice:
• Apply the updated algorithm of inside test on point-3.
Solution:
• As 1st intersected point joins two lines which are on the same side of
point-3, so considering it as even let say 2 and one more point is
intersecting. Total is 3, hence it is inside the polygon.
Winding number method:
• Draw a horizontal line on left or right side of point
• Traverse whole shape anti-clockwise and assign +1 if
direction is bottom to top otherwise -1.
• Find the sum of vertices from which point line is passing.
• If sum is non-zero, it is inside the shape otherwise it is outside.
Example:
• Consider the point ‘p’ in the diagram
• Sum = (-1) + (1) + (-1) + (1) = 0 (outside the shape)
Polygon filling algorithm:
4-connected algorithm:
• Initially we need to check boundary color not be same to the color
which is filled in the shape and that color is not already filled inside
the boundary.
8-connected algorithm:
8-connected vs 4-
connected:
• 4-connected algorithm fails to fill the
below shape which is filled by 8-
connected algorithm properly.
Limitations of boundary fill algorithm:
• We are restricted to the different color from boundary.
• Boundary color must be one.
Flood fill/seed fill algorithm:
This algorithm works if boundary pixels have different color. It checks
if old color (color inside the boundary) is the color or targeted pixel,
change color.
Limitation: If more than one color exist inside boundary, this
algorithm will fail.
Solution: Use a data structure containing list of old colors exist inside
the boundary and check. This method can be slow.
Implementation:
G G B B
G G B
G B B
R R
B R
B B R R R
R R
R
Old Color = White
New color = Yellow
Implementation:
G G B B
G G B
G B B
R R
B R
B B R R R
R R
R
Visit 8-neighbours
White != Green
Implementation:
G G B B
G G Y B
G B B
R R
B R
B B R R R
R R
R
Implementation:
G G B B
G G Y B
G B B
R R
B R
B B R R R
R R
R
Implementation:
G G B B
G G Y Y B
G B B
R R
B R
B B R R R
R R
R
Implementation:
G G B B
G G Y Y Y B
G B B
R R
B R
B B R R R
R R
R
Implementation:
G G B B
G G Y Y Y B
G B B
R R
B R
B B R R R
R R
R
Implementation:
G G B B
G G Y Y Y B
G Y B B
R R
B R
B B R R R
R R
R
Implementation:
G G B B
G G Y Y Y B
G Y B B
R R
B R
B B R R R
R R
R
Implementation:
G G B B
G G Y Y Y B
G Y Y B B
R R
B R
B B R R R
R R
R
Implementation:
G G B B
G G Y Y Y B
G Y Y B B
R R
B R
B B R R R
R R
R
Implementation:
G G B B
G G Y Y Y B
G Y Y Y Y B B
R Y Y Y Y R
B Y Y Y Y R
B B R Y Y R R
R Y R
R
Implementation:
G G B B
G G Y Y Y B
G Y Y Y Y B B
R Y Y Y Y R
B Y Y Y Y R
B B R Y Y R R
R Y R
R
Implementation:
G G B B
G G Y Y Y B
G Y Y Y Y B B
R Y Y Y Y R
B Y Y Y Y R
B B R Y Y R R
R Y R
R
Scan line polygon fill algorithm:
Basic terms:
Implementation:
0 1 2 3 4 5 6 7 8 9 10 11
11
10
9
8
7
6
5
4
3
2
1
0
Y11 = []
Y10 = []
Y9 = []
Y8 = []
Y7 = []
Y6 = []
Y5 = []
Y4 = []
Y3 = []
Y2 = []
Y1 = []
Y0 = []
Cont.
0 1 2 3 4 5 6 7 8 9 10 11
11
10
9
8
7
6
5
4
3
2
1
0
Y11 = []
Y10 = [(8,8)]
Y9 = []
Y8 = []
Y7 = []
Y6 = []
Y5 = []
Y4 = []
Y3 = []
Y2 = []
Y1 = []
Y0 = []
Cont.
0 1 2 3 4 5 6 7 8 9 10 11
11
10
9
8
7
6
5
4
3
2
1
0
Y11 = []
Y10 = [(8,8)]
Y9 = [(7,8)]
Y8 = []
Y7 = []
Y6 = []
Y5 = []
Y4 = []
Y3 = []
Y2 = []
Y1 = []
Y0 = []
Cont.
0 1 2 3 4 5 6 7 8 9 10 11
11
10
9
8
7
6
5
4
3
2
1
0
Y11 = []
Y10 = [(8,8)]
Y9 = [(7,8)]
Y8 = [(6,8)]
Y7 = []
Y6 = []
Y5 = []
Y4 = []
Y3 = []
Y2 = []
Y1 = []
Y0 = []
Cont.
0 1 2 3 4 5 6 7 8 9 10 11
11
10
9
8
7
6
5
4
3
2
1
0
Y11 = []
Y10 = [(8,8)]
Y9 = [(7,8)]
Y8 = [(6,8)]
Y7 = [(5,8)]
Y6 = []
Y5 = []
Y4 = []
Y3 = []
Y2 = []
Y1 = []
Y0 = []
Cont.
0 1 2 3 4 5 6 7 8 9 10 11
11
10
9
8
7
6
5
4
3
2
1
0
Y11 = []
Y10 = [(8,8)]
Y9 = [(7,8)]
Y8 = [(6,8)]
Y7 = [(5,8)]
Y6 = [(4,8)]
Y5 = []
Y4 = []
Y3 = []
Y2 = []
Y1 = []
Y0 = []
Cont.
0 1 2 3 4 5 6 7 8 9 10 11
11
10
9
8
7
6
5
4
3
2
1
0
Y11 = []
Y10 = [(8,8)]
Y9 = [(7,8)]
Y8 = [(6,8)]
Y7 = [(5,8)]
Y6 = [(4,8)]
Y5 = [(3,9)]
Y4 = []
Y3 = []
Y2 = []
Y1 = []
Y0 = []
Cont.
0 1 2 3 4 5 6 7 8 9 10 11
11
10
9
8
7
6
5
4
3
2
1
0
Y11 = []
Y10 = [(8,8)]
Y9 = [(7,8)]
Y8 = [(6,8)]
Y7 = [(5,8)]
Y6 = [(4,8)]
Y5 = [(3,9)]
Y4 = [(2,9)]
Y3 = []
Y2 = []
Y1 = []
Y0 = []
Cont.
0 1 2 3 4 5 6 7 8 9 10 11
11
10
9
8
7
6
5
4
3
2
1
0
Y11 = []
Y10 = [(8,8)]
Y9 = [(7,8)]
Y8 = [(6,8)]
Y7 = [(5,8)]
Y6 = [(4,8)]
Y5 = [(3,9)]
Y4 = [(2,9)]
Y3 = [(1,2),(2,9)]
Y2 = []
Y1 = []
Y0 = []
Cont.
0 1 2 3 4 5 6 7 8 9 10 11
11
10
9
8
7
6
5
4
3
2
1
0
Y11 = []
Y10 = [(8,8)]
Y9 = [(7,8)]
Y8 = [(6,8)]
Y7 = [(5,8)]
Y6 = [(4,8)]
Y5 = [(3,9)]
Y4 = [(2,9)]
Y3 = [(1,2),(2,9)]
Y2 = [(3,6),(6,9)]
Y1 = []
Y0 = []
Cont.
0 1 2 3 4 5 6 7 8 9 10 11
11
10
9
8
7
6
5
4
3
2
1
0
Y11 = []
Y10 = [(8,8)]
Y9 = [(7,8)]
Y8 = [(6,8)]
Y7 = [(5,8)]
Y6 = [(4,8)]
Y5 = [(3,9)]
Y4 = [(2,9)]
Y3 = [(1,2),(2,9)]
Y2 = [(3,6),(6,9)]
Y1 = [(7,9)]
Y0 = []
Cont.
0 1 2 3 4 5 6 7 8 9 10 11
11
10
9
8
7
6
5
4
3
2
1
0
Y11 = []
Y10 = [(8,8)]
Y9 = [(7,8)]
Y8 = [(6,8)]
Y7 = [(5,8)]
Y6 = [(4,8)]
Y5 = [(3,9)]
Y4 = [(2,9)]
Y3 = [(1,2),(2,9)]
Y2 = [(3,6),(6,9)]
Y1 = [(7,9)]
Y0 = []
Cont.
0 1 2 3 4 5 6 7 8 9 10 11
11
10
9
8
7
6
5
4
3
2
1
0
Y11 = []
Y10 = [(8,8)]
Y9 = [(7,8)]
Y8 = [(6,8)]
Y7 = [(5,8)]
Y6 = [(4,8)]
Y5 = [(3,9)]
Y4 = [(2,9)]
Y3 = [(1,2),(2,9)]
Y2 = [(3,6),(6,9)]
Y1 = [(7,9)]
Y0 = []
Cont.
0 1 2 3 4 5 6 7 8 9 10 11
11
10
9
8
7
6
5
4
3
2
1
0
Y11 = []
Y10 = [(8,8)]
Y9 = [(7,8)]
Y8 = [(6,8)]
Y7 = [(5,8)]
Y6 = [(4,8)]
Y5 = [(3,9)]
Y4 = [(2,9)]
Y3 = [(1,2),(2,9)]
Y2 = [(3,6),(6,9)]
Y1 = [(7,9)]
Y0 = []
Cont.
0 1 2 3 4 5 6 7 8 9 10 11
11
10
9
8
7
6
5
4
3
2
1
0
Y11 = []
Y10 = [(8,8)]
Y9 = [(7,8)]
Y8 = [(6,8)]
Y7 = [(5,8)]
Y6 = [(4,8)]
Y5 = [(3,9)]
Y4 = [(2,9)]
Y3 = [(1,2),(2,9)]
Y2 = [(3,6),(6,9)]
Y1 = [(7,9)]
Y0 = []
Cont.
0 1 2 3 4 5 6 7 8 9 10 11
11
10
9
8
7
6
5
4
3
2
1
0
Y11 = []
Y10 = [(8,8)]
Y9 = [(7,8)]
Y8 = [(6,8)]
Y7 = [(5,8)]
Y6 = [(4,8)]
Y5 = [(3,9)]
Y4 = [(2,9)]
Y3 = [(1,2),(2,9)]
Y2 = [(3,6),(6,9)]
Y1 = [(7,9)]
Y0 = []
Cont.
0 1 2 3 4 5 6 7 8 9 10 11
11
10
9
8
7
6
5
4
3
2
1
0
Y11 = []
Y10 = [(8,8)]
Y9 = [(7,8)]
Y8 = [(6,8)]
Y7 = [(5,8)]
Y6 = [(4,8)]
Y5 = [(3,9)]
Y4 = [(2,9)]
Y3 = [(1,2),(2,9)]
Y2 = [(3,6),(6,9)]
Y1 = [(7,9)]
Y0 = []
Cont.
0 1 2 3 4 5 6 7 8 9 10 11
11
10
9
8
7
6
5
4
3
2
1
0
Y11 = []
Y10 = [(8,8)]
Y9 = [(7,8)]
Y8 = [(6,8)]
Y7 = [(5,8)]
Y6 = [(4,8)]
Y5 = [(3,9)]
Y4 = [(2,9)]
Y3 = [(1,2),(2,9)]
Y2 = [(3,6),(6,9)]
Y1 = [(7,9)]
Y0 = []
Cont.
0 1 2 3 4 5 6 7 8 9 10 11
11
10
9
8
7
6
5
4
3
2
1
0
Y11 = []
Y10 = [(8,8)]
Y9 = [(7,8)]
Y8 = [(6,8)]
Y7 = [(5,8)]
Y6 = [(4,8)]
Y5 = [(3,9)]
Y4 = [(2,9)]
Y3 = [(1,2),(2,9)]
Y2 = [(3,6),(6,9)]
Y1 = [(7,9)]
Y0 = []
Cont.
0 1 2 3 4 5 6 7 8 9 10 11
11
10
9
8
7
6
5
4
3
2
1
0
Y11 = []
Y10 = [(8,8)]
Y9 = [(7,8)]
Y8 = [(6,8)]
Y7 = [(5,8)]
Y6 = [(4,8)]
Y5 = [(3,9)]
Y4 = [(2,9)]
Y3 = [(1,2),(2,9)]
Y2 = [(3,6),(6,9)]
Y1 = [(7,9)]
Y0 = []
Cont.
0 1 2 3 4 5 6 7 8 9 10 11
11
10
9
8
7
6
5
4
3
2
1
0
Y11 = []
Y10 = [(8,8)]
Y9 = [(7,8)]
Y8 = [(6,8)]
Y7 = [(5,8)]
Y6 = [(4,8)]
Y5 = [(3,9)]
Y4 = [(2,9)]
Y3 = [(1,2),(2,9)]
Y2 = [(3,6),(6,9)]
Y1 = [(7,9)]
Y0 = []
Done!!
Coherence property:
• There can be such a shape where we have to pass through same edge
again and again, we can save time by saving the sorted pairs.
• m = y2 – y1 / x2 – x1
• y2 is always 1 in this algorithm. For example, we have visited from top
to bottom in a scan line with a different in y-axis as 1. y12 to y11 to y10
… y So, Δy is always one. Let x1 = xk and x2 = xk+1
• m = 1/ Δx = 1/xk+1 – xk
• Xk+1 = 1/m + xk
2D operations
Lecture 4
2D operations:
• It is the straight-line movement of an object from one position to
another is called Translation.
• Possible operations:
• Translation
• Rotation
• Scaling
• Shear
• Reflection
Translation:
• To translate a point from coordinate position (x, y) to another
(x’, y’), we add algebraically the translation distances Tx and
Ty to original coordinate.
x’=x+Tx
y’=y+Ty (x’, y’)
(x, y)
Translated position
Problem-1:
• Given a circle C with radius 10 and center coordinates (1, 4).
Apply the translation with distance 5 towards X axis and 1
towards Y axis. Obtain the new coordinates of C without
changing its radius.
Solution: Applying the translation equations, we
have-
Xnew = Xold + Tx = 1 + 5 = 6
Ynew = Yold + Ty = 4 + 1 = 5
Thus, New center coordinates of C = (6, 5).
Problem-2:
• Given a square with coordinate points A(0, 3), B(3, 3), C(3, 0),
D(0, 0). Apply the translation with distance 1 towards X axis and
1 towards Y axis. Obtain the new coordinates of the square.
Solution:
For A(0,3):
Xnew = Xold + Tx = 0 + 1 = 1
Ynew = Yold + Ty = 3 + 1 = 4
For B(3,3):
Xnew = Xold + Tx = 3 + 1 = 4
Ynew = Yold + Ty = 3 + 1 = 4
For C(3,0):
Xnew = Xold + Tx = 3 + 1 = 4
Ynew = Yold + Ty = 0 + 1 = 1
For D(0,0):
Xnew = Xold + Tx = 0 + 1 = 1
Ynew = Yold + Ty = 0 + 1 = 1
2D Scaling:
• Scaling is a process of modifying or altering the size of objects.
• Scaling may be used to increase or reduce the size of object.
• Scaling subjects the coordinate points of the original object to
change.
• Scaling factor determines whether the object size is to be increased
or reduced.
• If scaling factor > 1, then the object size is increased.
• If scaling factor < 1, then the object size is reduced.
Cont.
• Let-
• Initial coordinates of the object O = (Xold, Yold)
Scaling factor for X-axis = Sx
Scaling factor for Y-axis = Sy
• New coordinates of the object O after scaling = (Xnew, Ynew)
• This scaling is achieved by using the following scaling equations-
Xnew = Xold x Sx
Ynew = Yold x Sy
Cont.
• Why we take 2x2 matrix in case of scaling while 2x1 in case of
translation??
• If we take 2x1 matrix, both values of scaling will be added in both new
coordinates. Putting zero will avoid this and adds Sx to new x-axis and
Sy to new y-axis.
Problem-1:
• Given a square object with coordinate points A(0, 3), B(3, 3),
C(3, 0), D(0, 0). Apply the scaling parameter 2 towards X axis
and 3 towards Y axis and obtain the new coordinates of the
object.
Solution:
• For A(0,3):
Xnew = Xold x Sx = 0 x 2 = 0
Ynew = Yold x Sy = 3 x 3 = 9
• For B(3,3):
Xnew = Xold x Sx = 3 x 2 = 6
Ynew = Yold x Sy = 3 x 3 = 9
• For C(3,0):
Xnew = Xold x Sx = 3 x 2 = 6
Ynew = Yold x Sy = 0 x 3 = 0
• For D(0,0):
Xnew = Xold x Sx = 0 x 2 = 0
Ynew = Yold x Sy = 0 x 3 = 0
Rotation:
• 2D Rotation is a process of rotating an object with respect to an angle
in a two-dimensional plane.
Consider a point object O has to be rotated from one angle to
another in a 2D plane.
Let-
Initial coordinates of the object O = (Xold, Yold)
Initial angle of the object O with respect to origin = Φ
Rotation angle = θ
New coordinates of the object O after rotation = (Xnew, Ynew)
Derivation of formula:
Cosθ = x/r
x = rCosθ
Sinθ = y/r
y = rSinθ
For anti-clockwise(+ive):
x’ = rCos(θ+Φ) = rCosθCosΦ - rSinθSinΦ = xCosΦ - ySinΦ
y’ = rSin(θ+Φ) = rSinθCosΦ + rCosθSinΦ = yCosΦ + xSinΦ
For clockwise(-ive):
x’ = rCos(θ-Φ) = rCosθCos(-Φ) - rSinθSin(-Φ)
= rCos(θ-Φ) = rCosθCosΦ – rSinθSinΦ = xCosΦ + ySinΦ
y’ = rSin(θ-Φ) = rSinθCos(-Φ) + rCosθSin(-Φ)
= rSin(θ-Φ) = rSinθCosΦ - rCosθSinΦ = yCosΦ – xSinΦ
Formula:
Xnew = Xold x cosθ – Yold x sinθ
Ynew = Xold x sinθ + Yold x cosθ
+
-
For anti-clockwise rotation:
For clockwise rotation:
Problem-1:
• Given a line segment with starting point as (0, 0) and ending
point as (4, 4). Apply 30degree rotation anticlockwise direction
on the line segment and find out the new coordinates of the line.
Solution:
Problem-2:
• Given a triangle with corner coordinates (0, 0), (1, 0) and (1, 1).
Rotate the triangle by 90degree anticlockwise direction and find
out the new coordinates.
Solution:
• For A =(0,0):
Xnew= Xold x cosθ – Yold x sinθ = 0 x cos90º – 0 x sin90º = 0
Ynew= Xold x sinθ + Yold x cosθ = 0 x sin90º + 0 x cos90º = 0
• For B(1,0):
Xnew= Xold x cosθ – Yold x sinθ= 1 x cos90º – 0 x sin90º= 0
Ynew= Xold x sinθ + Yold x cosθ= 1 x sin90º + 0 x cos90º= 1 + 0=
1
• For C(1,1):
Xnew= Xold x cosθ – Yold x sinθ= 1 x cos90º – 1 x sin90º= 0 –
1= -1
Shear:
• Shearing is an ideal technique to change the shape of an existing object. There are two
versions of shearing:
• Shearing in x-axis:
Xnew = Xold + Shx x Yold
Ynew = Yold
• Shearing in y-axis:
Xnew = Xold
Ynew = Yold + Shy x Xold
Matrix representation:
• We can also adjust the formula of previous ppt in matrix form:
Problem-1:
• 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:
Shearing along x-axis:
• For A(1,1):
Xnew = Xold + Shx x Yold = 1 + 2 x 1 = 3
Ynew = Yold = 1
• For B(0,0):
Xnew = Xold + Shx x Yold = 0 + 2 x 0 = 0
Ynew = Yold = 0
• For C(1,0):
Xnew = Xold + Shx x Yold = 1 + 2 x 0 = 1
Ynew = Yold = 0
Cont.
Shearing along y-axis:
• For A(1,1):
Xnew = Xold = 1
Ynew = Yold + Shy x Xold = 1 + 2 x 1 = 3
• For B(0,0):
Xnew = Xold = 0
Ynew = Yold + Shy x Xold = 0 + 2 x 0 = 0
• For C(1,0):
Xnew = Xold = 1
Ynew = Yold + Shy x Xold = 0 + 2 x 1 = 2
Illustration:
Reflection:
• Reflection is a kind of rotation where the angle of rotation is 180.
• The reflected object is always formed on the other side of the mirror.
• The size of reflected object is same as the size of original object.
• Reflection along x-axis:
Xnew = Xold
Ynew = -Yold
• Reflection along y-axis:
Xnew = -Xold
Ynew = Yold
Matrix representation:
Problem-1:
• Given a triangle with coordinate points A(3, 4), B(6, 4), C(5, 6).
Apply the reflection on the X axis Y axis and obtain the new
coordinates of the object.
Solution:
Reflection along x-axis:
• For A(3,4):
Xnew = Xold = 3
Ynew = -Yold = -4
• For B(6,4):
Xnew = Xold = 6
Ynew = -Yold = -4
• For C(5,6):
Xnew = Xold = 5
Ynew = -Yold = -6
Cont.
Reflection along y-axis:
• For A(3,4):
Xnew = -Xold = -3
Ynew = Yold = 4
• For B(6,4):
Xnew = -Xold = -6
Ynew = Yold = 4
• For C(5,6):
Xnew = -Xold = -5
Ynew = Yold = 6
Illustration:
Along y-axis
Along x-axis
Homogeneous co-ordinate system for
composite transformation:
• If we must apply set of operations one after another, it is difficult to
compute separately one by one using previously discussed methods.
Those methods are suitable where only single operation is required.
• For example, rotation of straight line or any other shape is achieved
by first moving object towards rotation (translation), perform rotation
and then move object to the old origin (translation). So, three
operations are required to compute which are translation, rotation
and then again translation.
• In order to save time, we can just multiply three matrices of required
task and multiplied by original object coordinate matrix.
Transformation matrix:
3D Transformations
Lecture 5
Transformation:
• All the operations are similar but just a new axis named z-axis is
added.
Translation:
Xnew = Xold + Tx (This denotes translation towards X axis)
Ynew = Yold + Ty (This denotes translation towards Y axis)
Znew = Zold + Tz (This denotes translation towards Z axis)
• Matrix representation:
Problem-1:
• Given a 3D object with coordinate points A(0, 3, 1), B(3, 3, 2),
C(3, 0, 0), D(0, 0, 0). Apply the translation with the distance 1
towards X axis, 1 towards Y axis and 2 towards Z axis and
obtain the new coordinates of the object.
Solution:
• For A(0,3,1):
Xnew = Xold + Tx = 0 + 1 = 1
Ynew = Yold + Ty = 3 + 1 = 4
Znew = Zold + Tz = 1 + 2 = 3
• For B(3,3,2):
Xnew = Xold + Tx = 3 + 1 = 4
Ynew = Yold + Ty = 3 + 1 = 4
Znew = Zold + Tz = 2 + 2 = 4
• For C(3,0,0):
Xnew = Xold + Tx = 3 + 1 = 4
Ynew = Yold + Ty = 0 + 1 = 1
Znew = Zold + Tz = 0 + 2 = 2
• For D(0,0,0):
Xnew = Xold + Tx = 0 + 1 = 1
Ynew = Yold + Ty = 0 + 1 = 1
Znew = Zold + Tz = 0 + 2 = 2
Scaling:
Cont.
Cont.
Cont.
Mathematical representation:
• This scaling is achieved by using the following scaling
equations-
Xnew = Xold x Sx
Ynew = Yold x Sy
Znew = Zold x Sz
• Matrix representation:
Problem-1:
• 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.
Solution:
• For A(0,3,3):
Xnew = Xold x Sx = 0 x 2 = 0
Ynew = Yold x Sy = 3 x 3 = 9
Znew = Zold x Sz = 3 x 3 = 9
• For B(3,3,6):
Xnew = Xold x Sx = 3 x 2 = 6
Ynew = Yold x Sy = 3 x 3 = 9
Znew = Zold x Sz = 6 x 3 = 18
• For C(3,0,1):
Xnew = Xold x Sx = 3 x 2 = 6
Ynew = Yold x Sy = 0 x 3 = 0
Znew = Zold x Sz = 1 x 3 = 3
• For D(0,0,0):
Xnew = Xold x Sx = 0 x 2 = 0
Ynew = Yold x Sy = 0 x 3 = 0
Znew = Zold x Sz = 0 x 3 = 0
Shearing:
• Shearing in X axis is achieved by using the following shearing equations-
Xnew = Xold
Ynew = Yold + Shy x Xold
Znew = Zold + Shz x Xold
• Shearing in Y axis is achieved by using the following shearing equations-
Xnew = Xold + Shx x Yold
Ynew = Yold
Znew = Zold + Shz x Yold
• Shearing in Z axis is achieved by using the following shearing equations-
Xnew = Xold + Shx x Zold
Ynew = Yold + Shy x Zold
Znew = Zold
Problem-1:
• 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:
Shearing along x-axis:
• For A(0,0,0):
Xnew = Xold = 0
Ynew = Yold + Shy x Xold = 0 + 2 x 0 = 0
Znew = Zold + Shz x Xold = 0 + 3 x 0 = 0
• For B(1,1,2):
Xnew = Xold = 1
Ynew = Yold + Shy x Xold = 1 + 2 x 1 = 3
Znew = Zold + Shz x Xold = 2 + 3 x 1 = 5
• For C(1,1,3):
Xnew = Xold = 1
Ynew = Yold + Shy x Xold = 1 + 2 x 1 = 3
Znew = Zold + Shz x Xold = 3 + 3 x 1 = 6
Cont.
Shearing along y-axis:
• For A(0,0,0):
Xnew = Xold + Shx x Yold = 0 + 2 x 0 = 0
Ynew = Yold = 0
Znew = Zold + Shz x Yold = 0 + 3 x 0 = 0
• For B(1,1,2):
Xnew = Xold + Shx x Yold = 1 + 2 x 1 = 3
Ynew = Yold = 1
Znew = Zold + Shz x Yold = 2 + 3 x 1 = 5
• For C(1,1,3):
Xnew = Xold + Shx x Yold = 1 + 2 x 1 = 3
Ynew = Yold = 1
Znew = Zold + Shz x Yold = 3 + 3 x 1 = 6
Cont.
Shearing along z-axis:
• For A(0,0,0):
Xnew = Xold + Shx x Zold = 0 + 2 x 0 = 0
Ynew = Yold + Shy x Zold = 0 + 2 x 0 = 0
Znew = Zold = 0
• For B(1,1,2):
Xnew = Xold + Shx x Zold = 1 + 2 x 2 = 5
Ynew = Yold + Shy x Zold = 1 + 2 x 2 = 5
Znew = Zold = 2
• For C(1,1,3):
Xnew = Xold + Shx x Zold = 1 + 2 x 3 = 7
Ynew = Yold + Shy x Zold = 1 + 2 x 3 = 7
Znew = Zold = 3
Rotation:
Cont.
Mathematical representation:
• This rotation is achieved by using the following rotation equations-
Xnew = Xold
Ynew = Yold x cosθ – Zold x sinθ
Znew = Yold x sinθ + Zold x cosθ
• This rotation is achieved by using the following rotation equations-
Xnew = Zold x sinθ + Xold x cosθ
Ynew = Yold
Znew = Yold x cosθ – Xold x sinθ
• This rotation is achieved by using the following rotation equations-
Xnew = Xold x cosθ – Yold x sinθ
Ynew = Xold x sinθ + Yold x cosθ
Znew = Zold
This is for clockwise rotation. For anti-clockwise, just revert the sign of Sinθ
Problem-1:
• 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:
• Along x-axis:
Xnew = Xold = 1
Ynew = Yold x cosθ – Zold x sinθ = 2 x cos90° – 3 x sin90° = 2 x 0 – 3 x 1 = -3
Znew = Yold x sinθ + Zold x cosθ = 2 x sin90° + 3 x cos90° = 2 x 1 + 3 x 0 = 2
• Along y-axis:
Xnew = Zold x sinθ + Xold x cosθ = 3 x sin90° + 1 x cos90° = 3 x 1 + 1 x 0 = 3
Ynew = Yold = 2
Znew = Yold x cosθ – Xold x sinθ = 2 x cos90° – 1 x sin90° = 2 x 0 – 1 x 1 = -1
• Along z-axis:
Xnew = Xold x cosθ – Yold x sinθ
Ynew = Xold x sinθ + Yold x cosθ
Znew = Zold
Reflection:
• Along xy-plane:
Xnew = Xold
Ynew = Yold
Znew = -Zold
• Along yz-plane:
Xnew = -Xold
Ynew = Yold
Znew = Zold
• Along xz-plane:
Xnew = Xold
Ynew = -Yold
Znew = Zold
Problem-1:
• 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:
• For A(3,4,1):
Xnew = Xold = 3
Ynew = Yold = 4
Znew = -Zold = -1
• For B(6,4,2):
Xnew = Xold = 6
Ynew = Yold = 4
Znew = -Zold = -2
• For C(5,6,3):
Xnew = Xold = 5
Ynew = Yold = 6
Znew = -Zold = -3
Problem-2:
• 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:
• For A(3,4,1):
Xnew = Xold = 3
Ynew = -Yold = -4
Znew = Zold = 1
• For B(6,4,2):
Xnew = Xold = 6
Ynew = -Yold = -4
Znew = Zold = 2
• For C(5,6,3):
Xnew = Xold = 5
Ynew = -Yold = -6
Znew = Zold = 3
Inverse transformation:
• Like linear algebra matrix transformation, we can use this feature to
save a lot of computations but just computing inverse transformation.
For example, I have rotated a shape anti-clockwise and want to return
it to its original place in game to fulfill reset requirement. I can just
rotate the matrix in opposite direction without measuring the
coordinates again.
• Just put change the sign of the respective parameter in matrix like Shy
in shear, Sx in scaling, Tx in translation and many more patterns.
Example:
Character generation
techniques
Lecture 6
Character generation:
• In computer graphics, character can be generated using software or
hardware.
• Software provides a lot of options as compared to hardware.
• Three basic methods are:
1) Stroke method
2) Vector method or bitmap method
3) Starbust method
Stroke method:
• In this method, different shapes especially lines are combined to
generate character. Shapes can be circle, curve, lines or any other.
• We can change the size of character in this method.
• Font faces are few one.
Word generated by combining lines
and circle.
Bitmap/vector method:
• This method uses a data-structure commonly a matrix to store zero’s
and one’s. while scanning of each pixel intensity is done while reading
the data and displayed on screen. Matrix can be of rbg format.
• For example, a matrix of zero’s and one generate a pattern where
there are ones in the matrix and ignore that place (black by default)
where zeros are encountered.
Problem-1:
• Generate a bitmap matrix based on the given picture.
Solution:
Cont.
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Bitmap:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 0 1 0 0 1 0 0 1 1 0 0 1 0 0 1 0 1 0 0 1
0 0 1 0 0 0 1 0 0 1 0 1 0 0 1 0 1 1 0 1 0 1 0 1 0
0 0 1 0 0 0 1 1 1 1 0 1 1 1 1 0 1 0 0 1 0 1 1 0 0
0 0 1 0 0 0 1 0 0 1 0 1 0 0 1 0 1 0 1 1 0 1 0 1 0
0 0 1 0 0 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 1 0 0 0 1 0 0 1 1 0 0 1 0 0 1 0 0 0 0 0
0 0 0 0 0 0 1 0 1 0 0 1 0 0 1 0 1 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0 0 1 0 0 1 0 1 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0 0 1 0 0 1 0 1 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0 0 0 1 1 0 0 0 1 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Starbust method:
• In this method, a fixed pattern of lines is used to generate the
character.
• In this method, we use combination of 24 bit line segment.
• In 24-bit line segment, each bit represent a single line.
• To highlight a line, we put bit 1 in 24 bit line segment code and 0
otherwise.
Cont.
• To generate ‘U’ character we need to active given line segments:
Problem-1:
• Given a segment array, produce the corresponding pattern from given
star-bust pattern.
Solution:
Clipping
Lecture 7
Clipping:
“The process of ensuring whether a certain shape or component is inside or
outside the viewport.”
• Clipping is a fundamental concept in computer graphics that refers to the
process of determining which portions of an object or primitive should be
displayed or rendered on the screen. It is essential for efficiently displaying
graphics on a two-dimensional display device, such as a monitor, while
working with three-dimensional objects or primitives.
• When rendering 3D objects, it is common for portions of those objects to
extend beyond the boundaries of the display window or viewport. Clipping
ensures that only the visible parts of these objects are drawn, while the
portions outside the viewing window are discarded.
Point clipping:
• Point Clipping is used to determining, whether the point is inside the
window or not. For this following conditions are checked.
if (x >= xmin) && (x <= xmax) && (y >= ymin) && (y <= ymax)
Point is inside
else
Point is outside the viewport!!
Text Clipping:
• Several methods are available for clipping of text. Clipping method is
dependent on the method of generation used for characters. A simple
method is completely considered, or nothing considers method. This
method is also called as all or none. If all characters of the string are inside
window, then we will keep the string, if a string character is outside then
whole string will be discarded.
• Two methods are used: 1) Based on whole string 2) Based on individual
character
• Based on whole string, if whole half string is outside, whole will be
rejected.
• Based on individual character, if few characters are outside the window,
then only those characters will be rejected.
Text Clipping:
Identify type of text clipping, individual character based, or entire string based??
Example:
if (x >= xmin) && (x <= xmax) && (y >= ymin) && (y <= ymax)
Determine whether point (x1, y2) is inside or outside the
window?? (Xmin , ymin) Xmax
Ymax
2 3 4
2
3
4
(x1,y2)
Example:
if (x >= xmin) && (x <= xmax) && (y >= ymin) && (y <= ymax)
(xmin, ymin) -> (xmax, ymax) = (2,2) -> (4,4)
Point (x1,y1) = (3,1) ??
If (3 >= 2) && (3 <= 4) && (1 >= 2) && (1 <= 4)
(Xmin , ymin) Xmax
Ymax
2 3 4
2
3
4
(x1,y2)
Example:
if (x >= xmin) && (x <= xmax) && (y >= ymin) && (y <= ymax)
(xmin, ymin) -> (xmax, ymax) = (2,2) -> (4,4)
Point (x1,y1) = (3,1) ??
If (3 >= 2) && (3 <= 4) && (1 >= 2) && (1 <= 4)
So, point is outside the window!!
(Xmin , ymin) Xmax
Ymax
2 3 4
2
3
4
(x1,y2)
Cohn Sutherland line clipping algorithm:
• It is used to determine a line outside, inside or partially inside the
window.
Bit code assignment:
• Window is divided into 9 different parts to detect at which portion
line is available. A TBRL (Top, Bottom, Right, Left)rule is used to check
the availability.
Algorithm:
1) Assign the region codes to both endpoints.
2) Perform OR operation on both of these endpoints.
3) if OR = 0000, then it is completely visible (inside the window).
else
Perform AND operation on both these endpoints.
i) if AND ≠ 0000, then the line is invisible and not inside the window.
Also, it can’t be considered for clipping.
ii) else
AND = 0000, the line is partially inside the window and considered for
clipping.
Cont.
• 4) After confirming that the line is partially inside the window, then we find the intersection with
the boundary of the window. By using the following formula:-
Slope:- m= (y2-y1)/(x2-x1)
a) If the line passes through top or the line intersects with the top boundary of the window.
x = x + (y_wmax – y)/m
y = y_wmax
b) If the line passes through the bottom or the line intersects with the bottom boundary of the
window.
x = x + (y_wmin – y)/m
y = y_wmin
c) If the line passes through the left region or the line intersects with the left boundary of the
window.
y = y+ (x_wmin – x)*m
x = x_wmin
Cont.
d) If the line passes through the right region or the line intersects with
the right boundary of the window.
y = y + (x_wmax -x)*m
x = x_wmax
5) Now, overwrite the endpoints with a new one and update it.
6) Repeat the 4th step till your line doesn’t get completely clipped
Derivation:
• Left:
x = xmin
m = y2- y1 / x2 – x1 = y – y1/ x – x1 = y- y1 / xmin – x1
y = y1 + m( xmin - x1)
• Right:
x = xmax
m = y2- y1 / x2 – x1 = y – y1/ x – x1 = y- y1 / xmax – x1
y = y1 + m( xmax - x1)
Cont.
• Top:
y = ymax
m = y2- y1 / x2 – x1 = y – y1/ x – x1 = ymax- y1 / x2 – x1
x = x1 + (ymax – y1)/m
• Bottom:
y = ymin
m = y2- y1 / x2 – x1 = y – y1/ x – x1 = ymin- y1 / x2 – x1
x = x1 + (ymin – y1)/m
Example:
1 2 3 4 5 6 7 8 9
9
8
7
6
5
4
3
2
1
(9,6)
(5,2)
Let A = (x1, y1) = (5,2), B = (x2, y2) = (9,6)
1) Applying TBLR rule
A = 0000, B = 0001
A AND B = 0 (Partially outside)
2) Applying right formula:
x = xmax= 1
y = y1 + m( xmax - x1)
m = 6 – 2 / 9 – 5 = 4/4 = 1
y = 2 + 1(7 – 5) = 4
So, intersection point is (1,4)
Ignore the remaining part from (1,4) to (9,6).
Possible cases:
Visible Partially outside Not visible Partially inside,
No operation required Find intersection Ignore find intersection
and ignore line for two points
outside the box
Cont.
1 2 3 4 5 6 7 8 9
8
7
6
5
4
3
2
1
What if line passes through
diagonal??
In the given case,
(xmax, ymax) are the points
intersecting. So, we already
have values in case of diagonal
intersection.
Sutherland hodgeman polygon clipping
algorithm:
• This algorithm is used for the clipping of polygons. We start from left
side of window and then clip all the sides.
Example:
• Apply Sutherland polygon clipping algorithm.
Cont.
• Starting from left side, Take an edge an check whether it is inside or
not.
• Outside from outside -> Ignore
Cont.
• Taking next edge
• inside from inside -> Save
Cont.
• Taking next edge
• inside from inside -> Save
Cont.
• Taking next edge
• inside from inside -> Save
Cont.
• Taking next edge
• Outside from outside -> Ignore
Cont.
• Taking next edge
Done!!
Example-2:
Limitations:
• This algorithm gives invalid result for concave polygon.
• Weiler Atherton algorithm was devised to solve this issue.
Problem-1:
• Apply Sutherland hodgeman algorithm to clip the polygon.
Problem-2:
• Apply Sutherland hodgeman algorithm to clip the polygon and apply
cohn Sutherland line clipping algorithm on the edge C to D. (Assume
coordinates on your own).
Weiler Athorton polygon clipping algorithm:
• This algorithm maintains two list one for path and other for
intersection points. It also handles the issue of Sutherland hodgeman
algorithm.
Algorithm:
Example:
• Let's say we want to clip the below shape:
Cont.
• Assigning label to intersection points:
Cont.
• Maintain two lists for traversed path:
Cont.
• Tracing the intersection path to join lines:
Cont.
Cont.
Problem-1:
• Clip the given polygon using weiler athorton algorithm.
Solution:
Cont.
Cont.
Cont.
Cont.
Cont.
Cont.
Cont.
Done!!
Cyrus beck line clipping algorithm:
• Cohn Sutherland algorithm works only for rectangular window. But If
we have window of any other pattern, this algorithm fails.
• Cyrus beck line clipping algorithm works for all kind of windows.
• Normal for every edge is computed
• Vector for the clipping line is computed
• This algorithm uses one parametric equation and find the intersection
points through this.
Algorithm:
1) Draw and compute normal vector for each edge.
2) Find the edge points of the shape if not given already.
3) Compute all the values of ‘t’ for each edge using formula:
P(t) = P0 + t(P1 – P0)
x = Ni (P(t)- Pei)
X > 0 -> Outside the clipping window, x<0 -> Inside the clipping window, X = 0 -> Intersection point
4) We have to find the intersection point, so we will take equation x = 0
Ni(P(t) - Pei) = 0
Ni ( P0 + t(P1 – P0) - Pei ) = 0
NiP0 + NitP1 – NitP0 – NiPei = 0
NitP1 – NitP0 = NiPei - NiP0
t( NiP1 – NiP0) = Ni(Pei – P0)
t = Ni(Pei – P0) / Ni (P1 – P0)
5) Compute value of t for each edge.
6) If denominator < 0 (Entering edge), If denominator > 0 (Leaving edge
7) Find maximum from entering edge and minimum from leaving edge
8) Two ‘t’ coordinates came out, then put them into formula P(t) = P0 + t(P1 – P0) one by one
P0 = starting point of intersecting line
P1 = ending point of intersecting line
Ni = Normal to the selected edge
Pei = edge coordinates
Example:
• Find the intersection points from given pentagon window.
Cont.
1) Normal points are N1, …N6
2) N1 = (-1, -1), N2 = (-1, 0), N3 = (-1, 1), N4 = (1, 1), N5 = (1, 0), N6 = (1, -1)
Pe1 = (3,0), Pe2 = (1,2), Pe3 = (1,4), Pe4 = (3,6), Pe5 = (5,4), Pe6 = (5,2)
3) t1 = N1 (Pe1 – P0)/ N1 (P1 – P0)
= (-1,-1)[(3,0) – (-2,1)] / (-1,-1)[(6,3) – (-2,1)] = -4/-10
t2 = N2 (Pe2 – P0)/ N2 (P1 – P0)
= (-1,0)[(1,2) – (-2,1)] / (-1,0)[(6,3) – (-2,1)] = -3/-8
t3 = N3 (Pe3 – P0)/ N3 (P1 – P0)
= (-1,1)[(1,4) – (-2,1)] / (-1,1)[(6,3) – (-2,1)] = 0/-6
t4 = N4 (Pe4 – P0)/ N4 (P1 – P0)
= (1,1)[(3,6) – (-2,1)] / (1,1)[(6,3) – (-2,1)] = 10/10
Cont.
t5 = N5 (Pe5 – P0)/ N5 (P1 – P0)
= (1,0)[(5,4) – (-2,1)] / (1,0)[(6,3) – (-2,1)] = 7/8
t6 = N6 (Pe6 – P0)/ N6 (P1 – P0)
= (1,-1)[(5,2) – (-2,1)] / (1,-1)[(6,3) – (-2,1)] = 6/6
So, values of t1,…t6 are computed
Finding entering and leaving edges
Entering = -ive denominator, Leaving = +ive denominator
Entering = [t1, t2 , t3], Leaving = [t4, t5, t6]
Cont.
Find maximum from entering list and minimum from leaving list
Max(Entering) = t1 = -4/-10 = 2/5
Min(Leaving) = t5 = 7/8
Put values into equation: P(t) = P0 + t(P1 – P0)
Let t0 = t1, t1 = t5
P(t0) = (-2, 1) + 2/5 [(6,3) – (-2,1)] = (-2,1) + 2/5 (8,2) = (6/5, 9/5)
P(t1) = (-2, 1) + 7/8 [(6,3) – (-2,1)] = (-2,1) + 7/8 (8,2) = (5, 11/4)
So, intersection points are (6/5, 9/5) & (5, 11/4).
Problem-1:
• Let a clipping polygon be defined by the vertices (5, 5), (20, 2), (16,
10), (10, 10). Find intersection point using cyrus beck algorithm.
Solution:
• After computing all the stuff, values are:
Liang barsky line clipping algorithm:
• Like cohn Sutherland algorithm, this algorithm also works only for
rectangular window but faster and more efficient. While cyrus beck is
more general and work for all kinds of windows.
• This algorithm uses parametric equations and solves 4 inequalities.
Cont.
Algorithm:
Cont.
Cont.
Cont.
Example:
• Find intersection points of window (5,5) & (9,9) with line having
p1(4,12) & p2(8,8).
Solution:
• Find intersection points of window (5,5) & (9,9) with line having
p1(4,12) & p2(8,8).
1) Xmin = 5, Ymin = 5, Xmax = 9, Ymax = 9
2) Δx = x2 – x1 = 8 – 4 = 4, Δy = y2 – y1 = 8 – 12 = -4
3) P1 = -Δx = -4, P2 = Δx = 4, P3 = -Δy = 4, P4 = Δy = -4
4) q1 = X1 – Xmin = 4 – 5 = -1, q2 = Xmax – X1 = 9 – 4 = 5
5) q3 = Y1 – Ymin = 12 – 5 = 7, q4 = Ymax – Y1 = 9 – 12 = -3
6) Pk = 0 (false)
7) Pk = 0 && qk < 0 (false)
Cont.
7) Pk < 0:
P1, P4
t1 = max(0, qk/pk) = max(0, -1/-4, -3/-4) = ¾
8) Pk >0:
P2, P3
t2 = min(1, qk/pk) = min(1, 5/4, 7/4) = 1
9) t1> t2 (false)
10) t2 > t2:
x = x1 + t Δx = 4 + 4(3/4) = 7, y = y1 + t Δy = 12 + (-4)(3/4) = 9
So, intersection point is (7,9)
Example:
• Find intersection points of window (5,5) & (9,9) with line having
p1(2,6) & p2(12, 8).
Solution:
• Find intersection points of window (5,5) & (9,9) with line having
p1(2,6) & p2(12, 8).
1) Xmin = 5, Ymin = 5, Xmax = 9, Ymax = 9
2) Δx = x2 – x1 = 12 – 2 = 10, Δy = y2 – y1 = 8 – 6 = 2
3) P1 = -Δx = -10, P2 = Δx = 10, P3 = -Δy = -2, P4 = Δy = 2
4) q1 = X1 – Xmin = 2 - 5 = -3, q2 = Xmax – X1 = 9 – 2 = 7
5) q3 = Y1 – Ymin = 6 – 5 = 1, q4 = Ymax – Y1 = 9 – 6 = 3
6) Pk = 0 (false)
7) Pk = 0 && qk < 0 (false)
Cont.
7) Pk < 0:
P1, P3
t1 = max(0, qk/pk) = max(0, -30/-10, 1/-2) = 3/10
8) Pk >0:
P2, P4
t2 = min(1, qk/pk) = min(1, 7/10, 3/2) = 7/10
9) t1> t2 (false)
10) t2 > t2:
A: x = x1 + t Δx = 2 + 10(3/10) = 5, y = y1 + t Δy = 6 + (2)(3/10) = 6.6
B: x = x1 + t Δx = 2 + 10(7/10) = 9, y = y1 + t Δy = 6 + (2)(7/10) = 7.4
So, intersection point are (5,6.6) & (9,7.4)
Problem-1:
• Find intersection points of window (5,5) & (9,9) with line having
p1(4,9) & p2(4,2).
Solution:
• Find intersection points of window (5,5) & (9,9) with line having p1(4,9) &
p2(4,2).
1) Xmin = 5, Ymin = 5, Xmax = 9, Ymax = 9
2) Δx = x2 – x1 = 4 – 4 = 10, Δy = y2 – y1 = 9 – 2 = 7
3) P1 = -Δx = 0, P2 = Δx = 0, P3 = -Δy = -7, P4 = Δy = 7
4) q1 = X1 – Xmin = 4 - 5 = -1, q2 = Xmax – X1 = 9 – 4 = 5
5) q3 = Y1 – Ymin = 2 – 5 = -3, q4 = Ymax – Y1 = 9 – 2 = 7
6) Pk = 0 (true)
7) Pk = 0 && qk < 0 (true)
So, there is no intersection point. Line is outside the window!
Problem-2:
• Find intersection points:
Solution:
• Intersection points are p1(-1.4, -3) & p2(3, -1).
Fractals
Lecture 8
Introduction:
• Fractals are intricate and infinitely complex mathematical patterns
that exhibit self-similarity at various scales. They are often
characterized by repeating patterns that can be observed regardless
of the level of magnification. Fractals can be found in nature, art, and
various scientific fields, and they have gained popularity in computer
graphics and digital art due to their visually appealing and fascinating
properties.
Properties:
• Self similarity: When broken into smaller and smaller pieces, the new
piece look exactly the same as the original
• Dimension: How much an object fills the space
• ‘S’ represents scaling factor and is always a natural number
• ‘N’ represents the number of smaller self similar figures
Dimension of a line:
Dimension of a square:
Dimension of a cube:
Sierpinski triangle:
Sierpinski carpet:
Kock snowflake:
Kock snowflake - Dimension
Iterated function system:
• IFS (iterated function system) is another way of generating fractals. It
is based on the taking a point or figure and substituting it with several
other identical ones.
Naturally occurring fractals:
• Trees and plants
• In the human body
- Blood vessels
- Alveoli in lungs
Some famous fractals:
Problem-1:
• Given sierpinski carpet pattern, what could be dimension of the 2nd
shape generate by this pattern. (Hint: Reverse back to small size to
compute)
Problem-2:
• Apply iterative function system to create dragon curve.
Curves
Lecture 9
Curve:
• Shape formed by sketching without lifting the pen.
• In computer graphics, shape formed without any gap is curve.
• Fact: Straight line is also curve.
Types:
• Implicit curves
• Explicit curves
• Parametric curves
• Spline curves (Bezier, B-spline(periodic, non-periodic))
• NURBS (Non-uniform rational b-spline curves)
• Catmul-Rom splines
• Hermite curves
Implicit curves:
• Implicit curves are defined by an implicit equation that relates the
coordinates (x, y, z) of a point on the curve. The equation typically
involves a polynomial or algebraic expression. When evaluating the
equation for a given point, it results in a value that determines
whether the point is on the curve (value equals zero) or outside the
curve (value greater or less than zero). Implicit curves can represent a
wide range of shapes, including complex and irregular curves.
f(x,y) = 0
Explicit curves:
• Explicit curves, also known as parametric curves, are defined by
explicit equations that directly describe the coordinates (x, y, z) of
points on the curve as functions of one or more parameters, such as
time or a parameter t. The equations provide explicit formulas for the
x, y, and z coordinates at any given point along the curve. Parametric
curves are often used to represent smoothly varying curves and allow
for more intuitive control over the curve's shape and behavior.
y = f(x)
‘y’ is dependent of on the value of ‘x’, while ‘x’ is independent.
Parametric curves:
• Parametric curves are defined by a set of equations that describe the
position of points along the curve as a function of one or more parameters.
These curves allow for precise control over shape and are used in various
applications, such as animation and curve fitting.
• Peace-wise – linear, polynomial
• Linear equation curve – less smooth and abrupt change
• Polynomial curves – more smooth and flexible with less abrupt changes
x(t) = a3t3 + a2t2 + a1t + a0
y(t) = b3t3 + b2t2 + b1t + b0
z(t) = c3t3 + c2t2 + c1t + c0 (These equations can also be represented via
matrix form)
Interpolating curves:
Parametric continuity:
• When we join two or more curves, we need to observe its smoothness to
ensure the continuity (regularity). There are three basic types of
parametric continuity:
• Zero-order continuity: if joining points of two curve are same. Let say we
have joined two curves A and B then at joining point: A(t=1) = B(t=0)
• It is represented as C0
Cont.
• First-order continuity: if joining points of two curve are same. Let say
we have joined two curves A and B then at joining point:
• A’(t=1) = B’(t=0) (1st order derivate of joining point is same)
• It is represented as C1
Cont.
• Second-order continuity: if joining points of two curve are same. Let
say we have joined two curves A and B then at joining point:
• A’’(t=1) = B’’(t=0) (2nd order derivate of joining point is same)
• It is represented as C2
Geometric continuity:
• We have check for parameters of piecewise polynomial in parametric
continuity while in geometric, we consider the tangent of curve to
observe how well shape is formed.
Cont.
• Zero-order geometric continuity: Same as zero-order parametric
continuity
• First-order geometric continuity: Point of junction of curves have first
order derivative directly proportional to each other (not magnitude always)
A’(t=1) = k(B’(t=0))
• First-order geometric continuity: Point of junction of curves have second
order derivative directly proportional to each other (not magnitude always
A’’(t=1) = k(B’’(t=0))
These are represented by Gn. Where ‘n’ is the order.
In simple words, tangent line of both curves’ junction point must be same
which will indicate the slope of change.
Spline curves:
• A spline curve is a mathematical representation for which it is easy to
change the curve design put changing the control points (points taken
as reference for future modification). It is flexible enough an can be
used to adjust in any shape. If a spline curves’ control points form a
polygon, then it is convex hull.
Cont.
• Interpolation spline: A spline curve which passes through all the
control points.
• Approximation spline: A spline curve which passes through not all
the control points.
Bezier curve:
• A type of spline curve which is used to generate polygon. It forms
approximate spline curve (curve must pass from starting and ending
point but not necessary to pass through all other points). Convex hull
is formed if complete curve lie inside the control points.
• Degree of polynomial is always one less than total no. of control
points. For example, if 2 control point -> linear, 3 control points ->
quadratic.
• A Bezier curve must pass from starting and ending control point.
• The slope at the beginning of the curve is along the line joining the
first two control points and the slope at the end of the curve is along
the line joining the last two points of convex hull.
Properties of Bezier curve:
• Bezier curve is always contained within polygon called as convex hull
of its control points.
• The first and last points of the curve are coincident with the first and
last points of the defining polygon.
• The degree of the polynomial defining the curve segment is one
less than the total number of control points.
Cubic Bezier curve:
• Cubic bezier curve is a bezier curve with degree 3.
• The total number of control points in a cubic bezier curve is 4.
Bezier equation:
•t is any parameter where 0 <= t <= 1
•P(t) = Any point lying on the bezier curve
•Bi = ith control point of the bezier curve
•n = degree of the curve
•Jn,i(t) = Blending function = C(n,i)ti(1-t)n-i where C(n,i) = n! / i!(n-i)!
Example:
• Given cubic Bezier curve:
• This curve is defined by 4 control points b0, b1, b2 and b3.
• The degree of this curve is 3.
• So, it is a cubic bezier curve.
Cont.
Q(t) = Σn
i=0 Bi,n (u) * Pi
B0,3(u) = 3C0 * (u)0 * (1-u)3-0 = (1 - u)3
B1,3(u) = 3C1 * (u)1 * (1-u)3-1 = 3u(1 - u)2
B2,3(u) = 3C2 * (u)2 * (1-u)3-2 = 3u2(1 - u)2
B3,3(u) = 3C3 * (u)3 * (1-u)3-3 = u3
Q(t) = P0*(1 - u)3 + P1*3u(1 - u)2 + P3*3u2(1 - u)2 + P4*u3
This is required parametric equation for Bezier curve.
Problem-1:
• Given a Bezier curve having 4-control points: (1,0), (3,3), (6,3), (8,1)
Determine any 5 points lying on the curve. Also, draw a rough sketch of
the curve.
Solution:
• 5 points are allowed to take: 0 <= u <= 1
1/ u-1 = 1/5-1 = ¼ = 0.25
taking 5 points with increment of 0.25
u = [0.0, 0.25, 0.50, 0.75, 1.0]
As total control points are 4, so order of polynomial is n-1 = 3
Q(t) = Σn
i=0 Bi,n (u) * Pi = Q(t) = Σ3
i=0 Bi,3 (u) * Pi
Now we need to compute B0,3 B1,3 B2,3 B3,3
Cont.
B0,3(u) = 3C0 * (u)0 * (1-u)3-0 = (1 - u)3
B1,3(u) = 3C1 * (u)1 * (1-u)3-1 = 3u(1 - u)2
B2,3(u) = 3C2 * (u)2 * (1-u)3-2 = 3u2(1 - u)2
B3,3(u) = 3C3 * (u)3 * (1-u)3-3 = u3
Q(u) = P0*(1 - u)3 + P1*3u(1 - u)2 + P3*3u2(1 - u)2 + P4*u3
As we now Bezier curve takes starting and ending point from the same
shape, so we need to compute intermediate 3 points.
X(u) = x0*(1 - u)3 + x1*3u(1 - u)2 + x3*3u2(1 - u)2 + x4*u3
y(u) = y0*(1 - u)3 + y1*3u(1 - u)2 + y3*3u2(1 - u)2 + y4*u3
Cont.
• For u = 0.0
P(0) = [1 0](1-0)3 + [3 3]3(0)(1-t)2 + [6 3]3(0)2(1-0) + [8 1](0)3
P(0) = [1 0] + 0 + 0 + 0
P(0) = [1 0]
• For u = 0.25
P(0.2) = [1 0](1-0.2)3 + [3 3]3(0.2)(1-0.2)2 + [6 3]3(0.2)2(1-0.2) + [8 1](0.2)3
P(0.2) = [1 0](0.8)3 + [3 3]3(0.2)(0.8)2 + [6 3]3(0.2)2(0.8) + [8 1](0.2)3
P(0.2) = [1 0] x 0.512 + [3 3] x 3 x 0.2 x 0.64 + [6 3] x 3 x 0.04 x 0.8 + [8 1]
x 0.008
P(0.2) = [1 0] x 0.512 + [3 3] x 0.384 + [6 3] x 0.096 + [8 1] x 0.008
P(0.2) = [0.512 0] + [1.152 1.152] + [0.576 0.288] + [0.064 0.008]
P(0.2) = [2.304 1.448]
Cont.
• For u = 0.50
P(0.5) = [1 0](1-0.5)3 + [3 3]3(0.5)(1-0.5)2 + [6 3]3(0.5)2(1-0.5) + [8 1](0.5)3
P(0.5) = [1 0](0.5)3 + [3 3]3(0.5)(0.5)2 + [6 3]3(0.5)2(0.5) + [8 1](0.5)3
P(0.5) = [1 0] x 0.125 + [3 3] x 3 x 0.5 x 0.25 + [6 3] x 3 x 0.25 x 0.5 + [8 1] x 0.125
P(0.5) = [1 0] x 0.125 + [3 3] x 0.375 + [6 3] x 0.375 + [8 1] x 0.125
P(0.5) = [0.125 0] + [1.125 1.125] + [2.25 1.125] + [1 0.125]
P(0.5) = [4.5 2.375]
• For u = 0.75
P(t) = [1 0](1-t)3 + [3 3]3t(1-t)2 + [6 3]3t2(1-t) + [8 1]t3
P(0.7) = [1 0](1-0.7)3 + [3 3]3(0.7)(1-0.7)2 + [6 3]3(0.7)2(1-0.7) + [8 1](0.7)3
P(0.7) = [1 0](0.3)3 + [3 3]3(0.7)(0.3)2 + [6 3]3(0.7)2(0.3) + [8 1](0.7)3
P(0.7) = [1 0] x 0.027 + [3 3] x 3 x 0.7 x 0.09 + [6 3] x 3 x 0.49 x 0.3 + [8 1] x 0.343
P(0.7) = [1 0] x 0.027 + [3 3] x 0.189 + [6 3] x 0.441 + [8 1] x 0.343
P(0.7) = [0.027 0] + [0.567 0.567] + [2.646 1.323] + [2.744 0.343]
P(0.7) = [5.984 2.233]
Cont.
• For u = 1.0
P(1) = [1 0](1-1)3 + [3 3]3(1)(1-1)2 + [6 3]3(1)2(1-1) + [8 1](1)3
P(1) = [1 0] x 0 + [3 3] x 3 x 1 x 0 + [6 3] x 3 x 1 x 0 + [8 1] x 1
P(1) = 0 + 0 + 0 + [8 1]
P(1) = [8 1]
So, Bezier curve points are: (0,1), (2.3,1.4), (4.5, 2.3), (5.9,2.2),
(8,1)
Problem-2:
• Given control points of Bezier curve: (0,0), (1,2), (3,3), (4,0)
Find the Bezier curve taking arbitrary number of points. The more
points you take, curve will be smoother.
Solution:
• Using formulas, Bezier curve points are: (0,0), (0.9, 1.26), (2,1.87),
(3.09,1.54), (4,0)
B-spline curve:
• Concept of B-spline curve came to resolve the disadvantages having
by Bezier curve, as we all know that both curves are parametric in
nature. In Bezier curve we face a problem, when we change any of
the control point respective location the whole curve shape gets
change. But here in B-spline curve, the only a specific segment of the
curve-shape gets changes or affected by the changing of the
corresponding location of the control points.
• In the B-spline curve, the control points impart local control over the
curve-shape rather than the global control like Bezier-curve.
• Points of junction is often called as knot points.
Cont.
As we can see, local change does not affect the global curve.
NURBS
• Non-uniform b-spline curve is a type of b-spline curve in which gap
between curves is not uniform. Periodic spline curves has repeating
pattern with equal gap.
Catmull-Rom curves:
Catmull-Rom curves are a type of cubic interpolation curve used in computer graphics and
animation. Given a set of control points P₀, P₁, P₂, ..., Pₙ₋₁, the Catmull-Rom curve C(t) is
defined as a piecewise cubic polynomial that smoothly passes through each consecutive
pair of control points.
• The formula for the Catmull-Rom curve between control points Pᵢ and Pᵢ₊₁ is:
• C(t) = ((-t³ + 2t² - t)Pᵢ + (3t³ - 5t² + 2)Pᵢ₊₁ + (-3t³ + 4t² + t)Pᵢ₊₂ + (t³ - t²)Pᵢ₊₃) / 2
• where t is the parameter ranging from 0 to 1, determining the position along the curve.
• The Catmull-Rom curve calculation is based on a local control scheme, meaning that the
shape of the curve is determined by the positions of the adjacent control points. This
local influence allows for easy manipulation and adjustment of the curve's shape.
• Catmull-Rom curves exhibit several desirable properties, including passing through the
control points, maintaining continuity, and providing smoothness in the resulting curve.
Hermite curve:
• A Hermite curve, named after Charles Hermite, is a type of
interpolation curve used in computer graphics and mathematics. It is
often used to create smooth and continuous curves defined by
specified control points and their associated tangents.
• It is an interpolation spline curve.
• The Hermite curve calculation incorporates both the position and
tangent information, allowing for precise control over the curve's
shape and direction. The tangents determine the slope or direction of
the curve at each control point, influencing the curve's behavior
between the points.
Example:
• Let say we have a hermite curve with pk as initial and pk+1 as final point.
Value is between ‘0’ & ‘1’.
• Pk = P(0) = initial point
• Pk+1 = P(1) = end point
• Pk’ = DPk = derivative of ‘pk’
• Pk+1’ = DPk+1 = derivative of ‘pk+1’
Cont.
• P(u) = au3 + bu2 + cu + d , where 0 <= u <= 1
Px(u) = axu3 + bxu2 + cxu + dx
Py(u) = ayu3 + byu2 + cyu + dy
Pz(u) = azu3 + bzu2 + czu + dz
P’(u) = 3au2 + 2bu + c
P(0) = a*0 + b*0 + c*0 + d
P(1) = a*1 + b*1 + c*1 + d
P’(0) = 3a*0 + 2b*0 + c
P’(1) = 3a*1 + 2b*1 + c
Cont.
Animation
Lecture 10
Introduction:
• Animation refers to the movement on the screen of the display device
created by displaying a sequence of still images. Animation is the
technique of designing, drawing, making layouts and preparation of
photographic series which are integrated into the multimedia and
gaming products. Animation connects the exploitation and
management of still images to generate the illusion of movement.
Applications:
• Education & training
• Entertainment
• Computer Aided Design (CAD)
• Advertising
• Presentation
Animation functions:
• Morphing: Morphing is an animation function which is used to
transform object shape from one form to another is called Morphing.
It is one of the most complicated transformations. This function is
commonly used in movies, cartoons, advertisement, and computer
games.
Cont.
• Wrapping: Wrapping function is similar to morphing function. It
distorts only the initial images so that it matches with final
images and no fade occurs in this function.
• Tweening: Tweening is the short form of 'inbetweening.'
Tweening is the process of generating intermediate frames
between the initial & last final images. This function is popular in
the film industry.
Tweening:
Tilting:
• In animation, tilting refers to the movement of an object or camera
along a vertical axis. It involves changing the vertical angle or
orientation of the object or camera to create a sense of tilt or slant.
• When an object or camera tilts in an animation, it appears to lean or
pivot around the vertical axis. This movement can be used to add
dynamics, depth, and visual interest to a scene.
Cont.
• Panning: Usually Panning refers to rotation of the camera in
horizontal Plane. In computer graphics, Panning relates to the
movement of fixed size window across the window object in a
scene. In which direction the fixed sized window moves, the
object appears to move in the opposite direction.
Cont.
• Zooming: the window is fixed an object and change its size, the
object also appear to change in size. When the window is made
smaller about a fixed center, the object comes inside the
window appear more enlarged. This feature is known
as Zooming In.
• When we increase the size of the window about the fixed
center, the object comes inside the window appear small. This
feature is known as Zooming Out.
Cont.
• Rigging: The process of defining internal structure of a character like
bones/skeleton. It is the initial phase in animation where internal
design is first prepared. After then skinning is done to provide outer
structure of the animation character like skin, clothes.
Rigging Skinning
Cont.
• Key frame animation: The process of generating only key/important
frames of the animation and remaining/intermediate frames are
automatically added by software (tweening).
• Motion capture: Creating animation based on real life objects like
creating a character on a specific human.
• Texture mapping: The process of applying a specific pattern in
animation to make it more realistic in 3D. For example, I have a cube
involved in my animation of black color, I want to make cube made of
wood, then I will wrap the cube inside the wood color (texture) to
make the illusion of looking like a wooden cube.
Key frame specification:
Types of animation:
• Procedural: In this process, objects are animated with a procedure (set of
rules). Animator specifies the rules to be followed.
• Behavioral: Animator determines actions required to take on certain
frame. The process put more action in animation.
• Dynamics: Unlike key framing and motion picture, simulation uses the laws
of physics to generate motion of pictures and other objects. Simulations
can be easily used to produce slightly different sequences while
maintaining physical realism. Secondly, real-time simulations allow a higher
degree of interactivity where the real person can maneuver the actions of
the simulated character. These animations are created in physics engines
where physical behaviors can be scripted, even those with minute details
such as fluids or smoke.
Raster animation:
• Raster images are collection of a large number of pixels stored in a
buffer in shape of matrix in bitmap format.
• When these raster images are displayed in a particular sequence, it is
raster animation. Each raster image is a frame in animation. Frame
buffer is refreshed iteratively.
Traditional raster animation:
• Used low detailed animation using sprite sheets
• Sprite sheet is a single image having different motions in different
cells. In simple words, it encloses animation in a single image but
limited number of frames are stored.
Vector animation:
• It stores images as a sequence of points. Vector animation does not
provide much clarity as compared to raster animation.
• Raster animations are high resolution as compared to vector
animation.
Color table animation:
• Color table animation, also known as palette animation or indexed
color animation, is a technique used to create animations in which
the colors of the image or scene change over time. It is commonly
used in older systems or graphics formats that have limited color
capabilities.
• In color table animation, instead of directly changing the colors of
individual pixels in the image or scene, a fixed color table or palette is
used. The color table contains a limited set of colors, often referred to
as color indices. Each pixel in the image is assigned a color index that
corresponds to a specific color in the color table.
Double buffering:
• Double buffering is a technique used in animation and computer graphics
to prevent flickering and create smoother, more visually appealing
animations.
• In computer graphics, the image displayed on the screen is updated and
refreshed multiple times per second. Without buffering, when an image is
being drawn on the screen, there is a possibility of seeing incomplete or
partially drawn frames, resulting in flickering or visual artifacts.
• Double buffering solves this issue by introducing two buffers: a front buffer
and a back buffer. The front buffer represents the currently displayed
image on the screen, while the back buffer is a hidden or off-screen buffer
where the next frame of the animation is prepared.
Motion specification:
Direct motion specification:
• We explicitly give the rotation angles and translation vectors.
• Then the geometric transformation matrices are applied to transform
co-ordinate positions.
• These methods can be used for simple user programmed sequences.
Goal directed system:
• We an specify the motions that are to take place in general terms that
abstractly describes the actions.
• These systems are referred to as goal directed because they
determine specific motion parameters given the goals of the
animation. For example, we could specify that we want an object to
“walk” or to “run” to a particular destination.
Kinematics and dynamics:
• Kinematics: motion of study (position, velocity, acceleration)
• The movement of object from one place to another
• Measured over a time interval such as s, min,h
• Relative to the position of the observer or reference point
• Dynamics: Full consideration of time varying phenomenon in the
interaction between motion, forces and material properties
• Typically, there is a time-integration process where result from one
time frame effect the result on the next time frame.
Virtual/augmented reality:
• Advance sub-field of animation
• Process of creating real world animation with more and more realism
• AVATAR like movies based on this technology
Illumination model
Lecture 11
Introduction:
• Given an illumination incident at a point on a surface, quantification is
required to compute the intensity.
• Used to compute interaction of light with surfaces
• Factors determining lighting effect:
- Light source, surface, eye (camera)
Light sources:
• Point source: All lights originate at a point and radially diverge. A
reasonable approximation for sources whose dimensions are small
compared to the object size. For example, bulb in a room.
• Parallel source: Light is distributed parallelly in all directions. For
example, tube-light in a room.
• Distributed source: Light is scattered with unequal length. For
example, disco lights in party and functions.
Point Parallel Distributed
Ambient light:
• Non-directional
• Amount of light incident is constant on all surfaces
• Background light
• Not very realistic
• Indirect light source
• Can be natural/artificial, sun-light is reflected equally on all sources
Beer Lamberts’s law:
• It states that intensity of color observed from any reflecting surface is
directly proportional to cosine of the angle between direction of
incident light and the normal surface.
Diffuse light:
• Scattered along all points equally. (parallel source)
• Surface that are rough or grainy tend to scatter the reflected light in all
directions
• Measured by angle made by taking normal to the point where light is
incident to the light source making a cosine angle. Or it can be specified
as product of N.L (N = normal to the vector, L = light direction)
• A surface only illuminates light if the angle of incidence is in between 0
and 90 degree because cosine must be between 0 and 1.
• When cosine is negative, light source is behind the surface.
Specular reflection:
• Model for shiny and glossy surfaces like metals
• An ideal specular surface reflects light in one direction
Specular reflection:
• Adds brightness factor on most outward edge.
Specular + diffusion:
Ks = specular
Ambient + diffuse + specular:
Example:
Example:
• Identify the light source in the required section of image.
?
?
Example:
• Identify the light source in the required section of image.
Diffuse reflection
Shading
Lecture 12
Shading:
• The process of manipulating color of the shape to make it more
realistic is shading. It has four main types:
• Flat/Constant shading
• Gouraund shading
• Phong shading
Flat shading:
• A fast and straight forward method for rendering an object with
polygon surface is constant or flat shading. In this method, a single
intensity is computed by taking a normal to the specific/desired side
of shape and energy of light is computed by multiplying reflectivity
and refractivity. All points with-in the surface are assigned the same
color. It is the fastest one but less realistic and can make image more
worse with respect to intensity. It can be used to display the general
appearance of the shape.
Cont.
• If shape has more than one side, normal at each face is computed at
that intensity is applied to corresponding face only.
• It provides intensity discontinuity which causes match band effect.
Gouraud shading:
• This method uses interpolation by rasterizing the shape line by line.
• Step1: Find adjacent vertex's normal
• Step2: Apply illumination model at each polygon vertex to determine
polygon vertex intensity.
• Step3: Linearly interpolate the vertex intensity over the surface of
polygon.
Example:
• Step1: Along vertex ‘V’ adjacent edges are N1, N2, N3
• Taking a 2D shape to interpolate easily step 2
• Lets’ find the interpolation for ‘a’, ‘p’ & ‘b’.
Cont.
• Intensity of a = Ia = ya – y2 / y1 – y2 (I1) + y1 – ya/ y1 - y2(I2)
• Intensity of b = Ib = yb – y2 / y2 – y3 (I3) + y3 – yb/ y2 – y3(I2)
• Intensity of p = Ip = xb – xp / xb – xa (Ia) + xp – xa/ xb – xa(Ib)
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx
Computer Graphics Full Tutorial.pptx

More Related Content

Similar to Computer Graphics Full Tutorial.pptx

Similar to Computer Graphics Full Tutorial.pptx (20)

Displaydevices graphics
Displaydevices graphicsDisplaydevices graphics
Displaydevices graphics
 
Overview of Graphics System
Overview of Graphics SystemOverview of Graphics System
Overview of Graphics System
 
Computer Graphics - Introduction and CRT Devices
Computer Graphics - Introduction and CRT DevicesComputer Graphics - Introduction and CRT Devices
Computer Graphics - Introduction and CRT Devices
 
Introduction with graphics
Introduction with graphicsIntroduction with graphics
Introduction with graphics
 
Computer Graphics
Computer GraphicsComputer Graphics
Computer Graphics
 
A concept of graphics
A concept of graphicsA concept of graphics
A concept of graphics
 
Computer Graphics MCQ's
Computer Graphics MCQ'sComputer Graphics MCQ's
Computer Graphics MCQ's
 
Display devices
Display devices Display devices
Display devices
 
Computer Graphics 01.pptx
Computer Graphics 01.pptxComputer Graphics 01.pptx
Computer Graphics 01.pptx
 
Graphics display devices
Graphics display devicesGraphics display devices
Graphics display devices
 
Unit 1 notes
Unit 1 notesUnit 1 notes
Unit 1 notes
 
Introduction to computer graphics part 2
Introduction to computer graphics part 2Introduction to computer graphics part 2
Introduction to computer graphics part 2
 
Overview of CG by R.Chinthamani.pptx
Overview of CG by R.Chinthamani.pptxOverview of CG by R.Chinthamani.pptx
Overview of CG by R.Chinthamani.pptx
 
8259731.ppt
8259731.ppt8259731.ppt
8259731.ppt
 
display devices.pptx
display devices.pptxdisplay devices.pptx
display devices.pptx
 
CG_ch1.pptx
CG_ch1.pptxCG_ch1.pptx
CG_ch1.pptx
 
Chapter two 1
Chapter two 1Chapter two 1
Chapter two 1
 
Graphics display-devicesmod-1
Graphics display-devicesmod-1Graphics display-devicesmod-1
Graphics display-devicesmod-1
 
Overview-of-GraphicsSystem@2334444_5.ppt
Overview-of-GraphicsSystem@2334444_5.pptOverview-of-GraphicsSystem@2334444_5.ppt
Overview-of-GraphicsSystem@2334444_5.ppt
 
new ai techniques.pptx
new ai techniques.pptxnew ai techniques.pptx
new ai techniques.pptx
 

More from AOUNHAIDER7

10a String Matching(KMP).pptx
10a String Matching(KMP).pptx10a String Matching(KMP).pptx
10a String Matching(KMP).pptxAOUNHAIDER7
 
Travelling salesman problem(DAA).pdf
Travelling salesman problem(DAA).pdfTravelling salesman problem(DAA).pdf
Travelling salesman problem(DAA).pdfAOUNHAIDER7
 
10c -Articulation_point.pptx
10c -Articulation_point.pptx10c -Articulation_point.pptx
10c -Articulation_point.pptxAOUNHAIDER7
 
10b- Rabin Karp String Matching Problem.pptx
10b- Rabin Karp String Matching Problem.pptx10b- Rabin Karp String Matching Problem.pptx
10b- Rabin Karp String Matching Problem.pptxAOUNHAIDER7
 
Computer Graphics Interview Questions.pdf
Computer Graphics Interview Questions.pdfComputer Graphics Interview Questions.pdf
Computer Graphics Interview Questions.pdfAOUNHAIDER7
 
Computer Graphics Notes 2.pdf
Computer Graphics Notes 2.pdfComputer Graphics Notes 2.pdf
Computer Graphics Notes 2.pdfAOUNHAIDER7
 
Computer Graphics Notes.pdf
Computer Graphics Notes.pdfComputer Graphics Notes.pdf
Computer Graphics Notes.pdfAOUNHAIDER7
 

More from AOUNHAIDER7 (8)

10a String Matching(KMP).pptx
10a String Matching(KMP).pptx10a String Matching(KMP).pptx
10a String Matching(KMP).pptx
 
Travelling salesman problem(DAA).pdf
Travelling salesman problem(DAA).pdfTravelling salesman problem(DAA).pdf
Travelling salesman problem(DAA).pdf
 
10c -Articulation_point.pptx
10c -Articulation_point.pptx10c -Articulation_point.pptx
10c -Articulation_point.pptx
 
10b- Rabin Karp String Matching Problem.pptx
10b- Rabin Karp String Matching Problem.pptx10b- Rabin Karp String Matching Problem.pptx
10b- Rabin Karp String Matching Problem.pptx
 
Recurrences.pdf
Recurrences.pdfRecurrences.pdf
Recurrences.pdf
 
Computer Graphics Interview Questions.pdf
Computer Graphics Interview Questions.pdfComputer Graphics Interview Questions.pdf
Computer Graphics Interview Questions.pdf
 
Computer Graphics Notes 2.pdf
Computer Graphics Notes 2.pdfComputer Graphics Notes 2.pdf
Computer Graphics Notes 2.pdf
 
Computer Graphics Notes.pdf
Computer Graphics Notes.pdfComputer Graphics Notes.pdf
Computer Graphics Notes.pdf
 

Recently uploaded

AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........LeaCamillePacle
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxLigayaBacuel1
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 

Recently uploaded (20)

AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........Atmosphere science 7 quarter 4 .........
Atmosphere science 7 quarter 4 .........
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Planning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptxPlanning a health career 4th Quarter.pptx
Planning a health career 4th Quarter.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 

Computer Graphics Full Tutorial.pptx

  • 2. Introduction: • Computer Graphics involves technology to access. The Process transforms and presents information in a visual form. The role of computer graphics insensible. In today life, computer graphics has now become a common element in user interfaces, T.V. commercial motion pictures. • Computer Graphics is the creation of pictures with the help of a computer. The end product of the computer graphics is a picture it may be a business graph, drawing, and engineering. • In computer graphics, two or three-dimensional pictures can be created that are used for research. Many hardware devices algorithm has been developing for improving the speed of picture generation with the passes of time. It includes the creation storage of models and image of objects. These models for various fields like engineering, mathematical and so on. • Today computer graphics is entirely different from the earlier one. It is not possible. It is an interactive user can control the structure of an object of various input devices.
  • 3. Application: • Education & Training • Flight simulator • Computational biology • Computer generated maps • Architect • Presentation • Computer art • Entertainment • Visualization • printing technology
  • 4. Types of CG: • Non-interactive/passive graphics: user has no control over generated graphics. In simple words, read only graphics are non-interactive because user is unable to interact with like titles in TV. It is one way communication. User cannot make changes in the available resources. • Interactive graphics: user have some controls over the picture, i.e., the user can make any change in the produced image. One example of it is the ping-pong game. Interactive Computer Graphics require two-way communication between the computer and the user. A User can see the image and make any change by sending his command with an input device.
  • 6. Display technologies: • Shadow mark technology: also known as shadow X-ray or silhouette X-ray, relies on the principle of image contrast. When an object is placed between an X-ray source and a detector, the X-rays are attenuated or blocked by the object, resulting in a shadow or silhouette image(image void of internal details) on the detector. This technique is commonly used for two-dimensional (2D) X-ray inspection. Shadow Mask Method is commonly used in Raster- Scan System because they produce a much wider range of colors than the beam-penetration method. • It is used in the majority of color TV sets and monitors.
  • 7. Cont. • Beam penetration technology: Beam penetration technology, also known as penetrating X-ray or transmission X-ray, is based on the principle of X-ray penetration through materials. This technique is typically used for three-dimensional (3D) X-ray inspection. The Beam- Penetration method has been used with random-scan monitors. In this method, the CRT screen is coated with two layers of phosphor, red and green and the displayed color depends on how far the electron beam penetrates the phosphor layers. This method produces four colors only, red, green, orange and yellow. A beam of slow electrons excites the outer red layer only; hence screen shows red color only. A beam of high-speed electrons excites the inner green layer. Thus screen shows a green color. Only 4 colors are possible.
  • 8. Direct view storage tubes: • A Display Storage Tube (DST), also known as a Storage Tube or a Storage Oscilloscope, is a specialized type of cathode ray tube (CRT) used in electronic display systems. It was primarily used in older computer terminals and oscilloscopes. • The Display Storage Tube functions as a combination of a regular CRT and a temporary storage medium. It allows the persistent display of an image even after the original signal has been removed. This is accomplished by introducing a phosphor coating on the screen that can retain the image for an extended period, typically several minutes or longer. • It is not possible to erase specific part of image. • Not suitable for dynamic display devices. • Slow processing rate but cheap.
  • 9. Working: • Electron Beam Scanning: Similar to a regular CRT, a Display Storage Tube consists of an electron gun that emits an electron beam. The beam is focused and accelerated towards the screen, which is coated with a phosphor material. • Phosphor Coating: The phosphor coating on the Display Storage Tube screen is designed to have a longer persistence than the phosphor used in regular CRTs. This allows the image to remain visible for an extended period after the electron beam has passed. • Writing and Erasing: When an electrical signal is applied to the electron beam, it scans across the screen, exciting the phosphor and causing it to emit light. This creates the visible image. The phosphor coating retains the charge and continues to emit light even after the beam has moved to another location. • Image Persistence: The stored image on the Display Storage Tube screen remains visible until it is erased. Erasing is usually done by either applying a blanking signal to the electron beam or by flooding the screen with an intense light source that dissipates the stored charge.
  • 10. Flat Panel display: • The Flat-Panel display refers to a class of video devices that have reduced volume, weight and power requirement compared to CRT. • Example: Small T.V. monitor, calculator, pocket video games, laptop computers, an advertisement board in elevator.
  • 11. Cont. • Emissive Display: The emissive displays are devices that convert electrical energy into light. Examples are Plasma Panel, thin film electroluminescent display and LED (Light Emitting Diodes). • Non-Emissive Display: The Non-Emissive displays use optical effects to convert sunlight or light from some other source into graphics patterns. Examples are LCD (Liquid Crystal Device).
  • 12. Basic terminology: • Pixel: smallest point in display • Resolution: total number of pixel in picture or screen Resolution = Width X Height Width = number of horizontal pixels Height = number of vertical pixels • Pixel per inch (PPI): number of pixel per inch computed from diagonal distance • Aspect ratio: ratio of height and width commonly 4:3 • Frame buffer: storage area used to display graphics content (picture, image) • Persistence: Amount of time a frame takes to be displayed before refreshing.
  • 13. Illustration: Width = 1920 Height = 1080 Resolution = 1920 x 1080 PPI =√ a2 + b2 = √ 19202 + 10802 √ 3686400 + 1166400 = 2202/5 inch = 440 PPI
  • 15. Cathode ray tube: • A cathode ray tube (CRT) is a specialized vacuum tube in which images are produced when an electron beam strikes a phosphorescent surface. It modulates, accelerates, and deflects electron beam(s) onto the screen to create the images. Most desktop computer displays make use of CRT for image-displaying purposes.
  • 16. Working: Electron Beam Generation: Inside the CRT, an electron gun emits a focused beam of electrons. The electron gun consists of a cathode that emits electrons and an anode that accelerates and focuses the electrons into a narrow beam. Deflection: The electron beam is then deflected by electromagnetic coils or plates located around the neck of the CRT. These electromagnetic fields steer the beam horizontally and vertically, allowing it to scan across the entire screen. Phosphor-Coated Screen: The front of the CRT screen is coated with a layer of phosphors. Phosphors are chemical compounds that emit light when struck by electrons. Different phosphors can emit different colors of light. Pixel Intensity Control: The pixel intensity is controlled by modulating the strength of the electron beam. A higher intensity results in a brighter pixel, while a lower intensity results in a dimmer pixel.
  • 17. Cont. Scanning the Screen: The electron beam scans the screen line by line, starting from the top left corner and moving horizontally across each line. As the beam moves, it emits electrons that strike the phosphor-coated screen. Light Emission: When the electron beam hits the phosphor-coated screen, the phosphors emit light in response to the energy transferred by the electrons. The emitted light corresponds to the color of the phosphor and the intensity of the electron beam. Persistence: Phosphors have a property called persistence, which means they continue to emit light for a short period even after the electron beam has moved away. This persistence helps maintain the image on the screen until the next scan.
  • 19. Scanning techniques There are different strategies followed by different system. 1) Vector/Random scan display 2) Raster scan display
  • 20. Vector/random scan display: • In Random-Scan Display electron beam is directed only to the areas of screen where a picture has to be drawn. It is also called vector display, as it draws picture one line at time. It can draw and refresh component lines of a picture in any specified sequence. Pen plotter is an example of random- scan displays. • The number of lines regulates refresh rate on random-scan displays. An area of memory called refresh display files stores picture definition as a set of line drawing commands. The system returns back to first-line command in the list, after all the drawing commands have been processed. High- quality vector systems can handle around 100, 00 short lines at this refresh rate. Faster refreshing can burn phosphor. To avoid this every refresh cycle is delayed to prevent refresh rate greater than 60 frames per second.
  • 21. Cont. ADVANTAGES: • Higher resolution as compared to raster scan display. • Produces smooth line drawing. • Less Memory required. DISADVANTAGES: • Realistic images with different shades cannot be drawn. • Color limitations.
  • 22.
  • 23. Raster scan display: • Raster Scan Displays are most common type of graphics monitor which employs CRT. It is based on television technology. In raster scan system electron beam sweeps across the screen, from top to bottom covering one row at a time. A pattern of illuminated pattern of spots is created by turning beam intensity on and off as it moves across each row. A memory area called refresh buffer or frame buffer stores picture definition. This memory area holds intensity values for all screen points. Stored intensity values are restored from frame buffer and painted on screen taking one row at a time. Each screen point is referred to as pixels. • In raster scan systems refreshing is done at a rate of 60-80 frames per second. Refresh rates are also sometimes described in units of cycles per second / Hertz (Hz). At the end of each scan line, electron beam begins to display next scan line after returning to left side of screen. The return to the left of screen after refresh of each scan line is known as horizontal retrace of electron beam. At the end of each frame electron beam returns to top left corner and begins the next frame.
  • 24.
  • 25. Cont. ADVANTAGES: • Real life images with different shades can be displayed. • Color range available is bigger than random scan display. DISADVANTAGES: • Resolution is lower than random scan display. • More memory is required. • Data about the intensities of all pixel has to be stored.
  • 26. Interlaced scan display: Interlaced scan is a display technique where the image is split into two fields, displaying odd-numbered lines in one pass (called the odd field) and even-numbered lines in the next pass (called the even field). The screen is scanned in an alternating pattern, filling in the missing lines with each pass. Interlaced scan was more prevalent in older display technologies like CRT televisions and some computer monitors. While it requires fewer video resources, interlaced scan can sometimes result in flickering and reduced image quality, especially with fast- moving content.
  • 27. Progressive scan display: • Progressive scan display is a way of showing images on a screen in a smooth and continuous manner. It works by displaying all the lines of an image one after another, from top to bottom, in a sequence. This happens very quickly, with each line appearing so fast that our eyes perceive it as a complete image. • Imagine you're drawing a picture by filling it in line by line. With progressive scan, you start at the top of the picture and draw each line until you reach the bottom. This method ensures that the entire image is displayed at once, creating a clear and seamless picture.
  • 28. Line drawing algorithms Digital differential analyzer (DDA) Bresenhams’ Line generation algorithm
  • 29. Digital differential analyzer: • DDA (Digital Differential Analyzer) 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.
  • 30.
  • 31. Slope values • Case#01: Draw horizontal line: m = 0
  • 32. Slope values • Case#02: Draw vertical line: m = undefined
  • 33. Slope values • Case#03: Draw diagonal line: m = 1
  • 34. Important concept: m = 1, Angle = 45 degree m < 1 m > 1 ∆x = x2 – x1 ∆y = y2 – y1
  • 35. Algorithm: • Input the two endpoints of the line segment, (x1,y1) and (x2,y2). • Calculate the difference between the x-coordinates and y-coordinates of the endpoints as dx and dy respectively. • Calculate the slope of the line as m = dy/dx. • Set the initial point of the line as (x1,y1). • 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(x – x1). • Plot the pixel at the calculated (x,y) coordinate. • Repeat steps 5 and 6 until the endpoint (x2,y2) is reached.
  • 36. The line of equation for step i yi=mxi+b......................equation 1 Next value will be m = y2-y1 / x2 – x1 => ∆y / ∆x We can also extract ∆x and ∆y from above equation ∆y=m∆x ∆x=∆y/m
  • 37. Rules: Case1: When |∆x| >= |∆y| Then: Assign ∆x = 1 Xi+1 = xi + ∆x = xi + 1 yi+1 = yi + ∆y = yi + m ∆x = yi + m Case2: When |∆x| < |∆y| Then: Assign ∆y = 1 yi+1 = yi + ∆y = yi + 1 xi+1 = xi + ∆x = xi + ∆y / m = xi + 1/m
  • 38. Example: • Draw a line from (1,1) to (3,3) ??
  • 39. Solution: Draw a line from (1,1) to (3,3) X1 = 1, y1 = 1 & x2 =3, y2 = 3 m = y2-y1 / x2 – x1 => ∆y / ∆x = 3 – 1/ 3 – 1 = 2/2 = 1 Find ∆x & ∆y: ∆y=m∆x = 1 X 2 = 2 ∆x=∆y/m = 2/1 = 2
  • 40. Cont. xi yi xi+1 Yi+1 1 1 Xi, yi = current value , xi+1, yi+1 = next computed value m = 1 ∆x =2 , ∆y = 2 |∆x| >= |∆y| (Case#01) 2 = 2 Xi+1 = xi + ∆x = xi + 1 = 1 + 1 = 2 yi+1 = yi + ∆y = yi + m ∆x = yi + m = 1 + 1 = 2 1 2 3 4 3 2 1 0
  • 41. Cont. xi yi xi+1 Yi+1 1 1 2 2 2 2 m = 1 ∆x =2 , ∆y = 2 |∆x| >= |∆y| (Case#01) 2 = 2 Xi+1 = xi + ∆x = xi + 1 = 1 + 1 = 2 yi+1 = yi + ∆y = yi + m ∆x = yi + m = 1 + 1 = 2 1 2 3 4 3 2 1 0 *
  • 42. Cont. xi yi xi+1 Yi+1 1 1 2 2 2 2 m = 1 ∆x =2 , ∆y = 2 |∆x| >= |∆y| (Case#01) 2 = 2 Xi+1 = xi + ∆x = xi + 1 = 2 + 1 = 3 yi+1 = yi + ∆y = yi + m ∆x = yi + m = 2 + 1 = 3 1 2 3 4 3 2 1 0 * *
  • 43. Cont. xi yi xi+1 Yi+1 1 1 2 2 2 2 3 3 m = 1 ∆x =2 , ∆y = 2 |∆x| >= |∆y| (Case#01) 2 = 2 Xi+1 = xi + ∆x = xi + 1 = 2 + 1 = 3 yi+1 = yi + ∆y = yi + m ∆x = yi + m = 2 + 1 = 3 1 2 3 4 3 2 1 0 * * *
  • 44. Cont. xi yi xi+1 Yi+1 1 1 2 2 2 2 3 3 m = 1 ∆x =2 , ∆y = 2 |∆x| >= |∆y| (Case#01) 2 = 2 Xi+1 = xi + ∆x = xi + 1 = 2 + 1 = 3 yi+1 = yi + ∆y = yi + m ∆x = yi + m = 2 + 1 = 3 Done!! 1 2 3 4 3 2 1 0 * * *
  • 45. Practice: • Draw a line from (3,1) to (5,7) ??
  • 46. Solution: Draw a line from (3,1) to (5,7) X1 = 3, y1 = 1 & x2 =5, y2 = 7 m = y2-y1 / x2 – x1 => ∆y / ∆x = 7 – 1/ 5 – 3 = 6/2 = 3 Find ∆x & ∆y: ∆y=m∆x = 3 X 2 = 6 ∆x=∆y/m = 6/3 = 2
  • 47. Cont. xi yi xi+1 Yi+1 3 1 Xi, yi = current value , xi+1, yi+1 = next computed value m = 3 ∆x =2 , ∆y = 6 |∆x| < |∆y| (Case#02) 2 = 2 ∆y = 1 yi+1 = yi + ∆y = yi + 1 = 1 + 1 = 2 xi+1 = xi + ∆x = xi + ∆y / m = xi + 1/m = 3 + 1/3 = 3.3 1 2 3 4 5 6 7 3 2 1 0 4 5 6 7 *
  • 48. Cont. xi yi xi+1 Yi+1 3 1 3.3 2 3.3 2 Xi, yi = current value , xi+1, yi+1 = next computed value m = 3 ∆x =2 , ∆y = 6 |∆x| < |∆y| (Case#02) 2 = 2 ∆y = 1 yi+1 = yi + ∆y = yi + 1 = 1 + 1 = 2 xi+1 = xi + ∆x = xi + ∆y / m = xi + 1/m = 3 + 1/3 = 3.3 1 2 3 4 5 6 7 3 2 1 0 4 5 6 7 * *
  • 49. Cont. xi yi xi+1 Yi+1 3 1 3.3 2 3.3 2 3.8 3 3.8 3 Xi, yi = current value , xi+1, yi+1 = next computed value m = 3 ∆x =2 , ∆y = 6 |∆x| < |∆y| (Case#02) 2 = 2 ∆y = 1 yi+1 = yi + ∆y = yi + 1 = 2 + 1 = 3 xi+1 = xi + ∆x = xi + ∆y / m = xi + 1/m = 3.5 + 0.3 = 3.8 1 2 3 4 5 6 7 3 2 1 0 4 5 6 7 * * *
  • 50. Cont. xi yi xi+1 Yi+1 3 1 3.3 2 3.3 2 3.8 3 3.8 3 4.1 4 Xi, yi = current value , xi+1, yi+1 = next computed value m = 3 ∆x =2 , ∆y = 6 |∆x| < |∆y| (Case#02) 2 = 2 ∆y = 1 yi+1 = yi + ∆y = yi + 1 = 3 + 1 = 4 xi+1 = xi + ∆x = xi + ∆y / m = xi + 1/m = 3.8 + 0.3 = 4.1 1 2 3 4 5 6 7 3 2 1 0 4 5 6 7 * * * *
  • 51. Cont. xi yi xi+1 Yi+1 3 1 3.3 2 3.3 2 3.8 3 3.8 3 4.1 4 4 4.1 4.4 5 4.4 5 Xi, yi = current value , xi+1, yi+1 = next computed value m = 3 ∆x =2 , ∆y = 6 |∆x| < |∆y| (Case#02) 2 = 2 ∆y = 1 yi+1 = yi + ∆y = yi + 1 = 4 + 1 = 5 xi+1 = xi + ∆x = xi + ∆y / m = xi + 1/m = 4.1 + 0.3 = 4.4 1 2 3 4 5 6 7 3 2 1 0 4 5 6 7 * * * * *
  • 52. Cont. xi yi xi+1 Yi+1 3 1 3.3 2 3.3 2 3.8 3 3.8 3 4.1 4 4 4.1 4.4 5 4.4 5 4.7 6 4.7 6 5 7 Xi, yi = current value , xi+1, yi+1 = next computed value m = 3 ∆x =2 , ∆y = 6 |∆x| < |∆y| (Case#02) 2 = 2 ∆y = 1 yi+1 = yi + ∆y = yi + 1 = 6 + 1 = 7 xi+1 = xi + ∆x = xi + ∆y / m = xi + 1/m = 4.7 + 0.3 = 5 1 2 3 4 5 6 7 3 2 1 0 4 5 6 7 * * * * * *
  • 53. Cont. xi yi xi+1 Yi+1 3 1 3.3 2 3.3 2 3.8 3 3.8 3 4.1 4 4 4.1 4.4 5 4.4 5 4.7 6 4.7 6 5 7 Xi, yi = current value , xi+1, yi+1 = next computed value m = 3 ∆x =2 , ∆y = 6 |∆x| < |∆y| (Case#02) 2 = 2 ∆y = 1 yi+1 = yi + ∆y = yi + 1 = 6 + 1 = 7 xi+1 = xi + ∆x = xi + ∆y / m = xi + 1/m = 4.7 + 0.3 = 5 1 2 3 4 5 6 7 3 2 1 0 4 5 6 7 * * * * * * *
  • 54. Cont. xi yi xi+1 Yi+1 3 1 3.3 2 3.3 2 3.8 3 3.8 3 4.1 4 4 4.1 4.4 5 4.4 5 4.7 6 4.7 6 5 7 Xi, yi = current value , xi+1, yi+1 = next computed value m = 3 ∆x =2 , ∆y = 6 |∆x| < |∆y| (Case#02) 2 = 2 ∆y = 1 yi+1 = yi + ∆y = yi + 1 = 6 + 1 = 7 xi+1 = xi + ∆x = xi + ∆y / m = xi + 1/m = 4.7 + 0.3 = 5 Done!! 1 2 3 4 5 6 7 3 2 1 0 4 5 6 7 * * * * * * *
  • 55. Bresenhams’ algorithm: • The problem with DDA algorithm is that it considers float values which require extra computation and straight line is not achieved properly. But bresenham algorithm takes maximum distance b/w two pixels and generates a smooth and straight line.
  • 56.
  • 57.
  • 58.
  • 59. Algorithm: 1. Compute slop of line ‘m’, ∆x = dy, ∆y = dy, pk = 2dy - dx 2. If m<1: if p<0: xi+1 = xi + 1 yi+1 = yi pk+1 = pk + 2dy if p>=0: xi+1 = xi+1 yi+1 = yi+1 pk+1 = pk + 2dy – 2dx
  • 60. Cont. If m>=1: if p<0: xi+1 = xi yi+1 = yi+1 pk+1 = pk + 2dx if p>=0: xi+1 = xi+1 yi+1 = yi+1 pk+1 = pk + 2dx – 2dy
  • 61. Example: Draw line from (1,1) to (5,3) m = ∆y/∆x = 3 – 1/ 5 – 1 = 2/4 = 0.5 dx = x2 – x1 = 5 – 1 = 4 dy = y2 – y1 = 3 – 1 = 2 Pk = 2dy – dx = 2(2) – 4 = 0 m<1 (Condition#01)
  • 62. Implementation: pk xi yi xi+1 yi+1 0 1 1 2 2 -4 2 2 m<1 && pk>=0 (Case#02 of condition#01) xi+1 = xi + 1 = 1 + 1 = 2 yi+1 = yi +1 = 1 + 1 = 2 Pk+1 = pk + 2dy -2dx = 0 + 2(2) - 2(4) = -4 1 2 3 4 5 1 2 4 3 0 *
  • 63. Implementation: pk xi yi xi+1 yi+1 0 1 1 2 2 -4 2 2 m<1 && pk>=0 (Case#02 of condition#01) xi+1 = xi + 1 = 1 + 1 = 2 yi+1 = yi +1 = 1 + 1 = 2 Pk+1 = pk + 2dy -2dx = 0 + 2(2) - 2(4) = -4 1 2 3 4 5 1 2 4 3 0 * *
  • 64. Implementation: pk xi yi xi+1 yi+1 0 1 1 2 2 -4 2 2 3 2 0 3 2 m<1 && pk<0 (Case#01 of condition#01) xi+1 = xi + 1 = 2 + 1 = 3 yi+1 = yi = 2 Pk+1 = pk + 2dx = -4 + 2(2) = 0 1 2 3 4 5 1 2 4 3 0 * * *
  • 65. Implementation: pk xi yi xi+1 yi+1 0 1 1 2 2 -4 2 2 3 2 0 3 2 4 3 -4 4 3 m<1 && pk>=0 (Case#02 of condition#01) xi+1 = xi + 1 = 3 + 1 = 4 yi+1 = yi + 1 = 2 + 1 = 3 Pk+1 = pk + 2dy – 2dx = 0 + 2(2) – 2(4) = -4 1 2 3 4 5 1 2 4 3 0 * * * *
  • 66. Implementation: pk xi yi xi+1 yi+1 0 1 1 2 2 -4 2 2 3 2 0 3 2 4 3 -4 4 3 5 3 m<1 && pk<0 (Case#01 of condition#01) xi+1 = xi + 1 = 4 + 1 = 5 yi+1 = yi = 3 Pk+1 = pk + 2dy = -4 + 2(2) = 0 1 2 3 4 5 1 2 4 3 0 * * * * *
  • 67. Implementation: pk xi yi xi+1 yi+1 0 1 1 2 2 -4 2 2 3 2 0 3 2 4 3 -4 4 3 5 3 m<1 && pk<0 (Case#01 of condition#01) xi+1 = xi + 1 = 4 + 1 = 5 yi+1 = yi = 3 Pk+1 = pk + 2dy = -4 + 2(2) = 0 Done!! 1 2 3 4 5 1 2 4 3 0 * * * * *
  • 69. Bresenham circle drawing algorithm: • We only need to compute one slice b/w 90 and 45 degree. All other values will be computed by just mirroring and swapping x and y co- ordinate.
  • 70. Algorithm: 1. Compute x0 = starting point, y0 = radius = r 2. Compute decision parameter(P): p = 3 – 2*R 3. If p<0: xi+1 = xi + 1 yi+1 = yi pi+1 = pi + 4xi+1 + 6 If p>=0: xi+1 = xi + 1 yi+1 = yi - 1 pi+1 = pi + 4(xi+1 – yi+1) + 10
  • 71. Example: • Generate a circle from origin (0,0) with r = 8. X0 = 0 Y0 = r = 8 • Calculate the value of initial decision parameter P0 as- P0 = 3 – 2 x R P0 = 3 – 2 x 8 P0 = -13
  • 72. Cont. • As Pinitial < 0, so case-01 is satisfied. Xk+1 = Xk + 1 = 0 + 1 = 1 Yk+1 = Yk = 8 Pk+1 = Pk + 4 x Xk+1 + 6 = -13 + (4 x 1) + 6 = -3 Step-03 is executed similarly until Xk+1 >= Yk+1 Algorithm calculates all the points of octant-1 and terminates!!
  • 73. Cont. • Just take mirror of upper slice of one quadrant. Change the signs in another quadrant accordingly.
  • 74. Swapped values Mirror of upper slice Quadrant 2, 3 & 4 are copy of quadrant-1 with sign changed accordingly!!
  • 75. Practice: • Given the center point coordinates (10, 10) and radius as 10, generate all the points to form a circle. • Hint: Don’t apply hint here because origin is not (0,0)
  • 76. Solution: 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 = 3 – 2 x R P0 = 3 – 2 x 10 P0 = -17
  • 77. Cont. Step-03: As Pinitial < 0, so case-01 is satisfied. Thus, Xk+1 = Xk + 1 = 0 + 1 = 1 Yk+1 = Yk = 10 Pk+1 = Pk + 4 x Xk+1 + 6 = -17 + (4 x 1) + 6 = -7 Step-04: This step is applicable here as the given centre point coordinates is (10, 10). Xplot = Xc + X0 = 1 + 10 = 11 Yplot = Yc + Y0 = 10 + 10 = 20
  • 78. Cont. • Step-03 and Step-04 are executed similarly until Xplot => Yplot as follows-
  • 79. Other columns have subtracted actual value from 20 because origin is 10 and radius is double or 20
  • 80. Bresenham midpoint circle drawing algorithm: dk = distance between above and below axis xk = x-coordinate yk = y-coordinate r = radius Step#01: Compute dk = r-1 While xk < yk: If dk < 0: xk+1 = xk + 1 yk+1 = yk dk+1 = dk + 2xk + 3 If dk > 0: xk+1 = xk + 1 yk+1 = yk – 1 dk+1 = dk + 2xk – 2yk + 5
  • 81. Cont.
  • 82. Problem-1: • Given the center point coordinates (0, 0) and radius as 10, generate all the points to form a circle.
  • 83. Solution: Assign the starting point coordinates (X0, Y0) as- X0 = 0 Y0 = R = 10 P0 = 1 – R P0 = 1 – 10 P0 = -9 Pinitial < 0, so case-01 is satisfied. Xk+1 = Xk + 1 = 0 + 1 = 1 Yk+1 = Yk = 10 Pk+1 = Pk + 2 x Xk+1 + 1 = -9 + (2 x 1) + 1 = -6 Note: dk is pk here
  • 84. Cont. • We can compute all the points in the same way:
  • 85. Cont. • Hence, all other points using first quadrant are:
  • 86. Problem-2: • Given the center point coordinates (4, -4) and radius as 10, generate all the points to form a circle.
  • 87. Solution: • As the origin is other than (0,0), we find co-ordinates by assuming center as (0,0). After computing, we will add the points. • Just add 4 in every point • If quadrant is negative like 2nd one, then subtract original value from 4. For example, in 1st row, 4 – 0 = 0 then (4, 14) are the points of 1st row.
  • 88. Cont.
  • 90. Polygon: • Shape having more than two points connected with each other. Line segment which forms the boundary of polygon is known as edge which end sides are vertices. It can be of any shape.
  • 91. Types: • Simple • Complex • Concave • Convex
  • 92. Simple polygon: • Polygon having shape such that no line intersect other. Not simple due to intersecting lines Simple
  • 93. Complex polygon: • Opposite of simple polygon. • Shape having lines intersecting other (at least one) Complex
  • 94. Convex polygon: • Such shape in which if we take any points which are surely inside the polygon and if we draw a line joining these points and if all the points lie inside the polygon, then such a polygon is convex. All the angles of edges must be less then 180 degree.
  • 95. Concave polygon: • Such polygon in which if we take two points which are surely inside the polygon and if we draw a line joining these points and if all the points are not lying inside the polygon, then such a polygon is concave polygon. Angle of edges > 180 (at least one)
  • 96. Inside test of polygon: • It is very important to know if a point is inside or outside the polygon before starting to fill the polygon. Draw a horizontal line from point left or right which is required to determined inside, if number of points intersected by line are even, it is outside the polygon. If odd, it is inside. There are two rare cases also need to consider discussed next. Odd – inside Even - outside
  • 97. Example: • Let below point is need to determine whether it is inside or outside the polygon. • 1- put the point where required to determine.
  • 98. Cont. • Draw a horizontal line from point to left or right. Count number of points intersected by line. In this case, total points are 3. So, point is inside the polygon.
  • 99. Cont. • Let check another point in the same shape. Number of intersected points are 2(even). So, its outside the polygon.
  • 100. Issue with inside test method: • Consider the point g which is outside the polygon, by checking via algorithm, number of points intersected are 1 or 2??
  • 101. Solution: • Add extra step in the algorithm that if line is passed from such point connected two or more line, check whether all the joined lines are not same side of the or one above and one below or one left and one right. • If lines connected with intersected point are on the same side, consider point as odd otherwise even. Same side – even Different side – odd • Now apply this scheme on previous diagram.
  • 102. Practice: • Apply the updated algorithm of inside test on point-3.
  • 103. Solution: • As 1st intersected point joins two lines which are on the same side of point-3, so considering it as even let say 2 and one more point is intersecting. Total is 3, hence it is inside the polygon.
  • 104. Winding number method: • Draw a horizontal line on left or right side of point • Traverse whole shape anti-clockwise and assign +1 if direction is bottom to top otherwise -1. • Find the sum of vertices from which point line is passing. • If sum is non-zero, it is inside the shape otherwise it is outside.
  • 105. Example: • Consider the point ‘p’ in the diagram • Sum = (-1) + (1) + (-1) + (1) = 0 (outside the shape)
  • 107. 4-connected algorithm: • Initially we need to check boundary color not be same to the color which is filled in the shape and that color is not already filled inside the boundary.
  • 109. 8-connected vs 4- connected: • 4-connected algorithm fails to fill the below shape which is filled by 8- connected algorithm properly.
  • 110. Limitations of boundary fill algorithm: • We are restricted to the different color from boundary. • Boundary color must be one.
  • 111. Flood fill/seed fill algorithm: This algorithm works if boundary pixels have different color. It checks if old color (color inside the boundary) is the color or targeted pixel, change color. Limitation: If more than one color exist inside boundary, this algorithm will fail. Solution: Use a data structure containing list of old colors exist inside the boundary and check. This method can be slow.
  • 112. Implementation: G G B B G G B G B B R R B R B B R R R R R R Old Color = White New color = Yellow
  • 113. Implementation: G G B B G G B G B B R R B R B B R R R R R R Visit 8-neighbours White != Green
  • 114. Implementation: G G B B G G Y B G B B R R B R B B R R R R R R
  • 115. Implementation: G G B B G G Y B G B B R R B R B B R R R R R R
  • 116. Implementation: G G B B G G Y Y B G B B R R B R B B R R R R R R
  • 117. Implementation: G G B B G G Y Y Y B G B B R R B R B B R R R R R R
  • 118. Implementation: G G B B G G Y Y Y B G B B R R B R B B R R R R R R
  • 119. Implementation: G G B B G G Y Y Y B G Y B B R R B R B B R R R R R R
  • 120. Implementation: G G B B G G Y Y Y B G Y B B R R B R B B R R R R R R
  • 121. Implementation: G G B B G G Y Y Y B G Y Y B B R R B R B B R R R R R R
  • 122. Implementation: G G B B G G Y Y Y B G Y Y B B R R B R B B R R R R R R
  • 123. Implementation: G G B B G G Y Y Y B G Y Y Y Y B B R Y Y Y Y R B Y Y Y Y R B B R Y Y R R R Y R R
  • 124. Implementation: G G B B G G Y Y Y B G Y Y Y Y B B R Y Y Y Y R B Y Y Y Y R B B R Y Y R R R Y R R
  • 125. Implementation: G G B B G G Y Y Y B G Y Y Y Y B B R Y Y Y Y R B Y Y Y Y R B B R Y Y R R R Y R R
  • 126. Scan line polygon fill algorithm:
  • 127.
  • 129. Implementation: 0 1 2 3 4 5 6 7 8 9 10 11 11 10 9 8 7 6 5 4 3 2 1 0 Y11 = [] Y10 = [] Y9 = [] Y8 = [] Y7 = [] Y6 = [] Y5 = [] Y4 = [] Y3 = [] Y2 = [] Y1 = [] Y0 = []
  • 130. Cont. 0 1 2 3 4 5 6 7 8 9 10 11 11 10 9 8 7 6 5 4 3 2 1 0 Y11 = [] Y10 = [(8,8)] Y9 = [] Y8 = [] Y7 = [] Y6 = [] Y5 = [] Y4 = [] Y3 = [] Y2 = [] Y1 = [] Y0 = []
  • 131. Cont. 0 1 2 3 4 5 6 7 8 9 10 11 11 10 9 8 7 6 5 4 3 2 1 0 Y11 = [] Y10 = [(8,8)] Y9 = [(7,8)] Y8 = [] Y7 = [] Y6 = [] Y5 = [] Y4 = [] Y3 = [] Y2 = [] Y1 = [] Y0 = []
  • 132. Cont. 0 1 2 3 4 5 6 7 8 9 10 11 11 10 9 8 7 6 5 4 3 2 1 0 Y11 = [] Y10 = [(8,8)] Y9 = [(7,8)] Y8 = [(6,8)] Y7 = [] Y6 = [] Y5 = [] Y4 = [] Y3 = [] Y2 = [] Y1 = [] Y0 = []
  • 133. Cont. 0 1 2 3 4 5 6 7 8 9 10 11 11 10 9 8 7 6 5 4 3 2 1 0 Y11 = [] Y10 = [(8,8)] Y9 = [(7,8)] Y8 = [(6,8)] Y7 = [(5,8)] Y6 = [] Y5 = [] Y4 = [] Y3 = [] Y2 = [] Y1 = [] Y0 = []
  • 134. Cont. 0 1 2 3 4 5 6 7 8 9 10 11 11 10 9 8 7 6 5 4 3 2 1 0 Y11 = [] Y10 = [(8,8)] Y9 = [(7,8)] Y8 = [(6,8)] Y7 = [(5,8)] Y6 = [(4,8)] Y5 = [] Y4 = [] Y3 = [] Y2 = [] Y1 = [] Y0 = []
  • 135. Cont. 0 1 2 3 4 5 6 7 8 9 10 11 11 10 9 8 7 6 5 4 3 2 1 0 Y11 = [] Y10 = [(8,8)] Y9 = [(7,8)] Y8 = [(6,8)] Y7 = [(5,8)] Y6 = [(4,8)] Y5 = [(3,9)] Y4 = [] Y3 = [] Y2 = [] Y1 = [] Y0 = []
  • 136. Cont. 0 1 2 3 4 5 6 7 8 9 10 11 11 10 9 8 7 6 5 4 3 2 1 0 Y11 = [] Y10 = [(8,8)] Y9 = [(7,8)] Y8 = [(6,8)] Y7 = [(5,8)] Y6 = [(4,8)] Y5 = [(3,9)] Y4 = [(2,9)] Y3 = [] Y2 = [] Y1 = [] Y0 = []
  • 137. Cont. 0 1 2 3 4 5 6 7 8 9 10 11 11 10 9 8 7 6 5 4 3 2 1 0 Y11 = [] Y10 = [(8,8)] Y9 = [(7,8)] Y8 = [(6,8)] Y7 = [(5,8)] Y6 = [(4,8)] Y5 = [(3,9)] Y4 = [(2,9)] Y3 = [(1,2),(2,9)] Y2 = [] Y1 = [] Y0 = []
  • 138. Cont. 0 1 2 3 4 5 6 7 8 9 10 11 11 10 9 8 7 6 5 4 3 2 1 0 Y11 = [] Y10 = [(8,8)] Y9 = [(7,8)] Y8 = [(6,8)] Y7 = [(5,8)] Y6 = [(4,8)] Y5 = [(3,9)] Y4 = [(2,9)] Y3 = [(1,2),(2,9)] Y2 = [(3,6),(6,9)] Y1 = [] Y0 = []
  • 139. Cont. 0 1 2 3 4 5 6 7 8 9 10 11 11 10 9 8 7 6 5 4 3 2 1 0 Y11 = [] Y10 = [(8,8)] Y9 = [(7,8)] Y8 = [(6,8)] Y7 = [(5,8)] Y6 = [(4,8)] Y5 = [(3,9)] Y4 = [(2,9)] Y3 = [(1,2),(2,9)] Y2 = [(3,6),(6,9)] Y1 = [(7,9)] Y0 = []
  • 140. Cont. 0 1 2 3 4 5 6 7 8 9 10 11 11 10 9 8 7 6 5 4 3 2 1 0 Y11 = [] Y10 = [(8,8)] Y9 = [(7,8)] Y8 = [(6,8)] Y7 = [(5,8)] Y6 = [(4,8)] Y5 = [(3,9)] Y4 = [(2,9)] Y3 = [(1,2),(2,9)] Y2 = [(3,6),(6,9)] Y1 = [(7,9)] Y0 = []
  • 141. Cont. 0 1 2 3 4 5 6 7 8 9 10 11 11 10 9 8 7 6 5 4 3 2 1 0 Y11 = [] Y10 = [(8,8)] Y9 = [(7,8)] Y8 = [(6,8)] Y7 = [(5,8)] Y6 = [(4,8)] Y5 = [(3,9)] Y4 = [(2,9)] Y3 = [(1,2),(2,9)] Y2 = [(3,6),(6,9)] Y1 = [(7,9)] Y0 = []
  • 142. Cont. 0 1 2 3 4 5 6 7 8 9 10 11 11 10 9 8 7 6 5 4 3 2 1 0 Y11 = [] Y10 = [(8,8)] Y9 = [(7,8)] Y8 = [(6,8)] Y7 = [(5,8)] Y6 = [(4,8)] Y5 = [(3,9)] Y4 = [(2,9)] Y3 = [(1,2),(2,9)] Y2 = [(3,6),(6,9)] Y1 = [(7,9)] Y0 = []
  • 143. Cont. 0 1 2 3 4 5 6 7 8 9 10 11 11 10 9 8 7 6 5 4 3 2 1 0 Y11 = [] Y10 = [(8,8)] Y9 = [(7,8)] Y8 = [(6,8)] Y7 = [(5,8)] Y6 = [(4,8)] Y5 = [(3,9)] Y4 = [(2,9)] Y3 = [(1,2),(2,9)] Y2 = [(3,6),(6,9)] Y1 = [(7,9)] Y0 = []
  • 144. Cont. 0 1 2 3 4 5 6 7 8 9 10 11 11 10 9 8 7 6 5 4 3 2 1 0 Y11 = [] Y10 = [(8,8)] Y9 = [(7,8)] Y8 = [(6,8)] Y7 = [(5,8)] Y6 = [(4,8)] Y5 = [(3,9)] Y4 = [(2,9)] Y3 = [(1,2),(2,9)] Y2 = [(3,6),(6,9)] Y1 = [(7,9)] Y0 = []
  • 145. Cont. 0 1 2 3 4 5 6 7 8 9 10 11 11 10 9 8 7 6 5 4 3 2 1 0 Y11 = [] Y10 = [(8,8)] Y9 = [(7,8)] Y8 = [(6,8)] Y7 = [(5,8)] Y6 = [(4,8)] Y5 = [(3,9)] Y4 = [(2,9)] Y3 = [(1,2),(2,9)] Y2 = [(3,6),(6,9)] Y1 = [(7,9)] Y0 = []
  • 146. Cont. 0 1 2 3 4 5 6 7 8 9 10 11 11 10 9 8 7 6 5 4 3 2 1 0 Y11 = [] Y10 = [(8,8)] Y9 = [(7,8)] Y8 = [(6,8)] Y7 = [(5,8)] Y6 = [(4,8)] Y5 = [(3,9)] Y4 = [(2,9)] Y3 = [(1,2),(2,9)] Y2 = [(3,6),(6,9)] Y1 = [(7,9)] Y0 = []
  • 147. Cont. 0 1 2 3 4 5 6 7 8 9 10 11 11 10 9 8 7 6 5 4 3 2 1 0 Y11 = [] Y10 = [(8,8)] Y9 = [(7,8)] Y8 = [(6,8)] Y7 = [(5,8)] Y6 = [(4,8)] Y5 = [(3,9)] Y4 = [(2,9)] Y3 = [(1,2),(2,9)] Y2 = [(3,6),(6,9)] Y1 = [(7,9)] Y0 = []
  • 148. Cont. 0 1 2 3 4 5 6 7 8 9 10 11 11 10 9 8 7 6 5 4 3 2 1 0 Y11 = [] Y10 = [(8,8)] Y9 = [(7,8)] Y8 = [(6,8)] Y7 = [(5,8)] Y6 = [(4,8)] Y5 = [(3,9)] Y4 = [(2,9)] Y3 = [(1,2),(2,9)] Y2 = [(3,6),(6,9)] Y1 = [(7,9)] Y0 = []
  • 149. Cont. 0 1 2 3 4 5 6 7 8 9 10 11 11 10 9 8 7 6 5 4 3 2 1 0 Y11 = [] Y10 = [(8,8)] Y9 = [(7,8)] Y8 = [(6,8)] Y7 = [(5,8)] Y6 = [(4,8)] Y5 = [(3,9)] Y4 = [(2,9)] Y3 = [(1,2),(2,9)] Y2 = [(3,6),(6,9)] Y1 = [(7,9)] Y0 = [] Done!!
  • 150. Coherence property: • There can be such a shape where we have to pass through same edge again and again, we can save time by saving the sorted pairs. • m = y2 – y1 / x2 – x1 • y2 is always 1 in this algorithm. For example, we have visited from top to bottom in a scan line with a different in y-axis as 1. y12 to y11 to y10 … y So, Δy is always one. Let x1 = xk and x2 = xk+1 • m = 1/ Δx = 1/xk+1 – xk • Xk+1 = 1/m + xk
  • 152. 2D operations: • It is the straight-line movement of an object from one position to another is called Translation. • Possible operations: • Translation • Rotation • Scaling • Shear • Reflection
  • 153. Translation: • To translate a point from coordinate position (x, y) to another (x’, y’), we add algebraically the translation distances Tx and Ty to original coordinate. x’=x+Tx y’=y+Ty (x’, y’) (x, y) Translated position
  • 154. Problem-1: • Given a circle C with radius 10 and center coordinates (1, 4). Apply the translation with distance 5 towards X axis and 1 towards Y axis. Obtain the new coordinates of C without changing its radius.
  • 155. Solution: Applying the translation equations, we have- Xnew = Xold + Tx = 1 + 5 = 6 Ynew = Yold + Ty = 4 + 1 = 5 Thus, New center coordinates of C = (6, 5).
  • 156. Problem-2: • Given a square with coordinate points A(0, 3), B(3, 3), C(3, 0), D(0, 0). Apply the translation with distance 1 towards X axis and 1 towards Y axis. Obtain the new coordinates of the square.
  • 157. Solution: For A(0,3): Xnew = Xold + Tx = 0 + 1 = 1 Ynew = Yold + Ty = 3 + 1 = 4 For B(3,3): Xnew = Xold + Tx = 3 + 1 = 4 Ynew = Yold + Ty = 3 + 1 = 4 For C(3,0): Xnew = Xold + Tx = 3 + 1 = 4 Ynew = Yold + Ty = 0 + 1 = 1 For D(0,0): Xnew = Xold + Tx = 0 + 1 = 1 Ynew = Yold + Ty = 0 + 1 = 1
  • 158. 2D Scaling: • Scaling is a process of modifying or altering the size of objects. • Scaling may be used to increase or reduce the size of object. • Scaling subjects the coordinate points of the original object to change. • Scaling factor determines whether the object size is to be increased or reduced. • If scaling factor > 1, then the object size is increased. • If scaling factor < 1, then the object size is reduced.
  • 159. Cont. • Let- • Initial coordinates of the object O = (Xold, Yold) Scaling factor for X-axis = Sx Scaling factor for Y-axis = Sy • New coordinates of the object O after scaling = (Xnew, Ynew) • This scaling is achieved by using the following scaling equations- Xnew = Xold x Sx Ynew = Yold x Sy
  • 160. Cont. • Why we take 2x2 matrix in case of scaling while 2x1 in case of translation?? • If we take 2x1 matrix, both values of scaling will be added in both new coordinates. Putting zero will avoid this and adds Sx to new x-axis and Sy to new y-axis.
  • 161. Problem-1: • Given a square object with coordinate points A(0, 3), B(3, 3), C(3, 0), D(0, 0). Apply the scaling parameter 2 towards X axis and 3 towards Y axis and obtain the new coordinates of the object.
  • 162. Solution: • For A(0,3): Xnew = Xold x Sx = 0 x 2 = 0 Ynew = Yold x Sy = 3 x 3 = 9 • For B(3,3): Xnew = Xold x Sx = 3 x 2 = 6 Ynew = Yold x Sy = 3 x 3 = 9 • For C(3,0): Xnew = Xold x Sx = 3 x 2 = 6 Ynew = Yold x Sy = 0 x 3 = 0 • For D(0,0): Xnew = Xold x Sx = 0 x 2 = 0 Ynew = Yold x Sy = 0 x 3 = 0
  • 163. Rotation: • 2D Rotation is a process of rotating an object with respect to an angle in a two-dimensional plane. Consider a point object O has to be rotated from one angle to another in a 2D plane. Let- Initial coordinates of the object O = (Xold, Yold) Initial angle of the object O with respect to origin = Φ Rotation angle = θ New coordinates of the object O after rotation = (Xnew, Ynew)
  • 164. Derivation of formula: Cosθ = x/r x = rCosθ Sinθ = y/r y = rSinθ For anti-clockwise(+ive): x’ = rCos(θ+Φ) = rCosθCosΦ - rSinθSinΦ = xCosΦ - ySinΦ y’ = rSin(θ+Φ) = rSinθCosΦ + rCosθSinΦ = yCosΦ + xSinΦ For clockwise(-ive): x’ = rCos(θ-Φ) = rCosθCos(-Φ) - rSinθSin(-Φ) = rCos(θ-Φ) = rCosθCosΦ – rSinθSinΦ = xCosΦ + ySinΦ y’ = rSin(θ-Φ) = rSinθCos(-Φ) + rCosθSin(-Φ) = rSin(θ-Φ) = rSinθCosΦ - rCosθSinΦ = yCosΦ – xSinΦ
  • 165. Formula: Xnew = Xold x cosθ – Yold x sinθ Ynew = Xold x sinθ + Yold x cosθ + - For anti-clockwise rotation: For clockwise rotation:
  • 166. Problem-1: • Given a line segment with starting point as (0, 0) and ending point as (4, 4). Apply 30degree rotation anticlockwise direction on the line segment and find out the new coordinates of the line.
  • 168. Problem-2: • Given a triangle with corner coordinates (0, 0), (1, 0) and (1, 1). Rotate the triangle by 90degree anticlockwise direction and find out the new coordinates.
  • 169. Solution: • For A =(0,0): Xnew= Xold x cosθ – Yold x sinθ = 0 x cos90º – 0 x sin90º = 0 Ynew= Xold x sinθ + Yold x cosθ = 0 x sin90º + 0 x cos90º = 0 • For B(1,0): Xnew= Xold x cosθ – Yold x sinθ= 1 x cos90º – 0 x sin90º= 0 Ynew= Xold x sinθ + Yold x cosθ= 1 x sin90º + 0 x cos90º= 1 + 0= 1 • For C(1,1): Xnew= Xold x cosθ – Yold x sinθ= 1 x cos90º – 1 x sin90º= 0 – 1= -1
  • 170. Shear: • Shearing is an ideal technique to change the shape of an existing object. There are two versions of shearing: • Shearing in x-axis: Xnew = Xold + Shx x Yold Ynew = Yold • Shearing in y-axis: Xnew = Xold Ynew = Yold + Shy x Xold
  • 171. Matrix representation: • We can also adjust the formula of previous ppt in matrix form:
  • 172. Problem-1: • 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.
  • 173. Solution: Shearing along x-axis: • For A(1,1): Xnew = Xold + Shx x Yold = 1 + 2 x 1 = 3 Ynew = Yold = 1 • For B(0,0): Xnew = Xold + Shx x Yold = 0 + 2 x 0 = 0 Ynew = Yold = 0 • For C(1,0): Xnew = Xold + Shx x Yold = 1 + 2 x 0 = 1 Ynew = Yold = 0
  • 174. Cont. Shearing along y-axis: • For A(1,1): Xnew = Xold = 1 Ynew = Yold + Shy x Xold = 1 + 2 x 1 = 3 • For B(0,0): Xnew = Xold = 0 Ynew = Yold + Shy x Xold = 0 + 2 x 0 = 0 • For C(1,0): Xnew = Xold = 1 Ynew = Yold + Shy x Xold = 0 + 2 x 1 = 2
  • 176. Reflection: • Reflection is a kind of rotation where the angle of rotation is 180. • The reflected object is always formed on the other side of the mirror. • The size of reflected object is same as the size of original object. • Reflection along x-axis: Xnew = Xold Ynew = -Yold • Reflection along y-axis: Xnew = -Xold Ynew = Yold
  • 178. Problem-1: • Given a triangle with coordinate points A(3, 4), B(6, 4), C(5, 6). Apply the reflection on the X axis Y axis and obtain the new coordinates of the object.
  • 179. Solution: Reflection along x-axis: • For A(3,4): Xnew = Xold = 3 Ynew = -Yold = -4 • For B(6,4): Xnew = Xold = 6 Ynew = -Yold = -4 • For C(5,6): Xnew = Xold = 5 Ynew = -Yold = -6
  • 180. Cont. Reflection along y-axis: • For A(3,4): Xnew = -Xold = -3 Ynew = Yold = 4 • For B(6,4): Xnew = -Xold = -6 Ynew = Yold = 4 • For C(5,6): Xnew = -Xold = -5 Ynew = Yold = 6
  • 182. Homogeneous co-ordinate system for composite transformation: • If we must apply set of operations one after another, it is difficult to compute separately one by one using previously discussed methods. Those methods are suitable where only single operation is required. • For example, rotation of straight line or any other shape is achieved by first moving object towards rotation (translation), perform rotation and then move object to the old origin (translation). So, three operations are required to compute which are translation, rotation and then again translation. • In order to save time, we can just multiply three matrices of required task and multiplied by original object coordinate matrix.
  • 185. Transformation: • All the operations are similar but just a new axis named z-axis is added.
  • 186. Translation: Xnew = Xold + Tx (This denotes translation towards X axis) Ynew = Yold + Ty (This denotes translation towards Y axis) Znew = Zold + Tz (This denotes translation towards Z axis) • Matrix representation:
  • 187. Problem-1: • Given a 3D object with coordinate points A(0, 3, 1), B(3, 3, 2), C(3, 0, 0), D(0, 0, 0). Apply the translation with the distance 1 towards X axis, 1 towards Y axis and 2 towards Z axis and obtain the new coordinates of the object.
  • 188. Solution: • For A(0,3,1): Xnew = Xold + Tx = 0 + 1 = 1 Ynew = Yold + Ty = 3 + 1 = 4 Znew = Zold + Tz = 1 + 2 = 3 • For B(3,3,2): Xnew = Xold + Tx = 3 + 1 = 4 Ynew = Yold + Ty = 3 + 1 = 4 Znew = Zold + Tz = 2 + 2 = 4 • For C(3,0,0): Xnew = Xold + Tx = 3 + 1 = 4 Ynew = Yold + Ty = 0 + 1 = 1 Znew = Zold + Tz = 0 + 2 = 2 • For D(0,0,0): Xnew = Xold + Tx = 0 + 1 = 1 Ynew = Yold + Ty = 0 + 1 = 1 Znew = Zold + Tz = 0 + 2 = 2
  • 190. Cont.
  • 191. Cont.
  • 192. Cont.
  • 193. Mathematical representation: • This scaling is achieved by using the following scaling equations- Xnew = Xold x Sx Ynew = Yold x Sy Znew = Zold x Sz • Matrix representation:
  • 194. Problem-1: • 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.
  • 195. Solution: • For A(0,3,3): Xnew = Xold x Sx = 0 x 2 = 0 Ynew = Yold x Sy = 3 x 3 = 9 Znew = Zold x Sz = 3 x 3 = 9 • For B(3,3,6): Xnew = Xold x Sx = 3 x 2 = 6 Ynew = Yold x Sy = 3 x 3 = 9 Znew = Zold x Sz = 6 x 3 = 18 • For C(3,0,1): Xnew = Xold x Sx = 3 x 2 = 6 Ynew = Yold x Sy = 0 x 3 = 0 Znew = Zold x Sz = 1 x 3 = 3 • For D(0,0,0): Xnew = Xold x Sx = 0 x 2 = 0 Ynew = Yold x Sy = 0 x 3 = 0 Znew = Zold x Sz = 0 x 3 = 0
  • 196. Shearing: • Shearing in X axis is achieved by using the following shearing equations- Xnew = Xold Ynew = Yold + Shy x Xold Znew = Zold + Shz x Xold • Shearing in Y axis is achieved by using the following shearing equations- Xnew = Xold + Shx x Yold Ynew = Yold Znew = Zold + Shz x Yold • Shearing in Z axis is achieved by using the following shearing equations- Xnew = Xold + Shx x Zold Ynew = Yold + Shy x Zold Znew = Zold
  • 197. Problem-1: • 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.
  • 198. Solution: Shearing along x-axis: • For A(0,0,0): Xnew = Xold = 0 Ynew = Yold + Shy x Xold = 0 + 2 x 0 = 0 Znew = Zold + Shz x Xold = 0 + 3 x 0 = 0 • For B(1,1,2): Xnew = Xold = 1 Ynew = Yold + Shy x Xold = 1 + 2 x 1 = 3 Znew = Zold + Shz x Xold = 2 + 3 x 1 = 5 • For C(1,1,3): Xnew = Xold = 1 Ynew = Yold + Shy x Xold = 1 + 2 x 1 = 3 Znew = Zold + Shz x Xold = 3 + 3 x 1 = 6
  • 199. Cont. Shearing along y-axis: • For A(0,0,0): Xnew = Xold + Shx x Yold = 0 + 2 x 0 = 0 Ynew = Yold = 0 Znew = Zold + Shz x Yold = 0 + 3 x 0 = 0 • For B(1,1,2): Xnew = Xold + Shx x Yold = 1 + 2 x 1 = 3 Ynew = Yold = 1 Znew = Zold + Shz x Yold = 2 + 3 x 1 = 5 • For C(1,1,3): Xnew = Xold + Shx x Yold = 1 + 2 x 1 = 3 Ynew = Yold = 1 Znew = Zold + Shz x Yold = 3 + 3 x 1 = 6
  • 200. Cont. Shearing along z-axis: • For A(0,0,0): Xnew = Xold + Shx x Zold = 0 + 2 x 0 = 0 Ynew = Yold + Shy x Zold = 0 + 2 x 0 = 0 Znew = Zold = 0 • For B(1,1,2): Xnew = Xold + Shx x Zold = 1 + 2 x 2 = 5 Ynew = Yold + Shy x Zold = 1 + 2 x 2 = 5 Znew = Zold = 2 • For C(1,1,3): Xnew = Xold + Shx x Zold = 1 + 2 x 3 = 7 Ynew = Yold + Shy x Zold = 1 + 2 x 3 = 7 Znew = Zold = 3
  • 202. Cont.
  • 203. Mathematical representation: • This rotation is achieved by using the following rotation equations- Xnew = Xold Ynew = Yold x cosθ – Zold x sinθ Znew = Yold x sinθ + Zold x cosθ • This rotation is achieved by using the following rotation equations- Xnew = Zold x sinθ + Xold x cosθ Ynew = Yold Znew = Yold x cosθ – Xold x sinθ • This rotation is achieved by using the following rotation equations- Xnew = Xold x cosθ – Yold x sinθ Ynew = Xold x sinθ + Yold x cosθ Znew = Zold This is for clockwise rotation. For anti-clockwise, just revert the sign of Sinθ
  • 204. Problem-1: • Given a homogeneous point (1, 2, 3). Apply rotation 90 degree towards X, Y and Z axis and find out the new coordinate points.
  • 205. Solution: • Along x-axis: Xnew = Xold = 1 Ynew = Yold x cosθ – Zold x sinθ = 2 x cos90° – 3 x sin90° = 2 x 0 – 3 x 1 = -3 Znew = Yold x sinθ + Zold x cosθ = 2 x sin90° + 3 x cos90° = 2 x 1 + 3 x 0 = 2 • Along y-axis: Xnew = Zold x sinθ + Xold x cosθ = 3 x sin90° + 1 x cos90° = 3 x 1 + 1 x 0 = 3 Ynew = Yold = 2 Znew = Yold x cosθ – Xold x sinθ = 2 x cos90° – 1 x sin90° = 2 x 0 – 1 x 1 = -1 • Along z-axis: Xnew = Xold x cosθ – Yold x sinθ Ynew = Xold x sinθ + Yold x cosθ Znew = Zold
  • 206. Reflection: • Along xy-plane: Xnew = Xold Ynew = Yold Znew = -Zold • Along yz-plane: Xnew = -Xold Ynew = Yold Znew = Zold • Along xz-plane: Xnew = Xold Ynew = -Yold Znew = Zold
  • 207. Problem-1: • 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.
  • 208. Solution: • For A(3,4,1): Xnew = Xold = 3 Ynew = Yold = 4 Znew = -Zold = -1 • For B(6,4,2): Xnew = Xold = 6 Ynew = Yold = 4 Znew = -Zold = -2 • For C(5,6,3): Xnew = Xold = 5 Ynew = Yold = 6 Znew = -Zold = -3
  • 209. Problem-2: • 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.
  • 210. Solution: • For A(3,4,1): Xnew = Xold = 3 Ynew = -Yold = -4 Znew = Zold = 1 • For B(6,4,2): Xnew = Xold = 6 Ynew = -Yold = -4 Znew = Zold = 2 • For C(5,6,3): Xnew = Xold = 5 Ynew = -Yold = -6 Znew = Zold = 3
  • 211. Inverse transformation: • Like linear algebra matrix transformation, we can use this feature to save a lot of computations but just computing inverse transformation. For example, I have rotated a shape anti-clockwise and want to return it to its original place in game to fulfill reset requirement. I can just rotate the matrix in opposite direction without measuring the coordinates again. • Just put change the sign of the respective parameter in matrix like Shy in shear, Sx in scaling, Tx in translation and many more patterns.
  • 214. Character generation: • In computer graphics, character can be generated using software or hardware. • Software provides a lot of options as compared to hardware. • Three basic methods are: 1) Stroke method 2) Vector method or bitmap method 3) Starbust method
  • 215. Stroke method: • In this method, different shapes especially lines are combined to generate character. Shapes can be circle, curve, lines or any other. • We can change the size of character in this method. • Font faces are few one. Word generated by combining lines and circle.
  • 216. Bitmap/vector method: • This method uses a data-structure commonly a matrix to store zero’s and one’s. while scanning of each pixel intensity is done while reading the data and displayed on screen. Matrix can be of rbg format. • For example, a matrix of zero’s and one generate a pattern where there are ones in the matrix and ignore that place (black by default) where zeros are encountered.
  • 217. Problem-1: • Generate a bitmap matrix based on the given picture.
  • 219. Cont. 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  • 220. Bitmap: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 1 0 0 1 0 0 1 1 0 0 1 0 0 1 0 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 1 0 0 1 0 1 1 0 1 0 1 0 1 0 0 0 1 0 0 0 1 1 1 1 0 1 1 1 1 0 1 0 0 1 0 1 1 0 0 0 0 1 0 0 0 1 0 0 1 0 1 0 0 1 0 1 0 1 1 0 1 0 1 0 0 0 1 0 0 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 1 1 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 0 0 1 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 1 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 1 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
  • 221. Starbust method: • In this method, a fixed pattern of lines is used to generate the character. • In this method, we use combination of 24 bit line segment. • In 24-bit line segment, each bit represent a single line. • To highlight a line, we put bit 1 in 24 bit line segment code and 0 otherwise.
  • 222. Cont. • To generate ‘U’ character we need to active given line segments:
  • 223. Problem-1: • Given a segment array, produce the corresponding pattern from given star-bust pattern.
  • 226. Clipping: “The process of ensuring whether a certain shape or component is inside or outside the viewport.” • Clipping is a fundamental concept in computer graphics that refers to the process of determining which portions of an object or primitive should be displayed or rendered on the screen. It is essential for efficiently displaying graphics on a two-dimensional display device, such as a monitor, while working with three-dimensional objects or primitives. • When rendering 3D objects, it is common for portions of those objects to extend beyond the boundaries of the display window or viewport. Clipping ensures that only the visible parts of these objects are drawn, while the portions outside the viewing window are discarded.
  • 227. Point clipping: • Point Clipping is used to determining, whether the point is inside the window or not. For this following conditions are checked. if (x >= xmin) && (x <= xmax) && (y >= ymin) && (y <= ymax) Point is inside else Point is outside the viewport!!
  • 228. Text Clipping: • Several methods are available for clipping of text. Clipping method is dependent on the method of generation used for characters. A simple method is completely considered, or nothing considers method. This method is also called as all or none. If all characters of the string are inside window, then we will keep the string, if a string character is outside then whole string will be discarded. • Two methods are used: 1) Based on whole string 2) Based on individual character • Based on whole string, if whole half string is outside, whole will be rejected. • Based on individual character, if few characters are outside the window, then only those characters will be rejected.
  • 229. Text Clipping: Identify type of text clipping, individual character based, or entire string based??
  • 230. Example: if (x >= xmin) && (x <= xmax) && (y >= ymin) && (y <= ymax) Determine whether point (x1, y2) is inside or outside the window?? (Xmin , ymin) Xmax Ymax 2 3 4 2 3 4 (x1,y2)
  • 231. Example: if (x >= xmin) && (x <= xmax) && (y >= ymin) && (y <= ymax) (xmin, ymin) -> (xmax, ymax) = (2,2) -> (4,4) Point (x1,y1) = (3,1) ?? If (3 >= 2) && (3 <= 4) && (1 >= 2) && (1 <= 4) (Xmin , ymin) Xmax Ymax 2 3 4 2 3 4 (x1,y2)
  • 232. Example: if (x >= xmin) && (x <= xmax) && (y >= ymin) && (y <= ymax) (xmin, ymin) -> (xmax, ymax) = (2,2) -> (4,4) Point (x1,y1) = (3,1) ?? If (3 >= 2) && (3 <= 4) && (1 >= 2) && (1 <= 4) So, point is outside the window!! (Xmin , ymin) Xmax Ymax 2 3 4 2 3 4 (x1,y2)
  • 233. Cohn Sutherland line clipping algorithm: • It is used to determine a line outside, inside or partially inside the window.
  • 234. Bit code assignment: • Window is divided into 9 different parts to detect at which portion line is available. A TBRL (Top, Bottom, Right, Left)rule is used to check the availability.
  • 235. Algorithm: 1) Assign the region codes to both endpoints. 2) Perform OR operation on both of these endpoints. 3) if OR = 0000, then it is completely visible (inside the window). else Perform AND operation on both these endpoints. i) if AND ≠ 0000, then the line is invisible and not inside the window. Also, it can’t be considered for clipping. ii) else AND = 0000, the line is partially inside the window and considered for clipping.
  • 236. Cont. • 4) After confirming that the line is partially inside the window, then we find the intersection with the boundary of the window. By using the following formula:- Slope:- m= (y2-y1)/(x2-x1) a) If the line passes through top or the line intersects with the top boundary of the window. x = x + (y_wmax – y)/m y = y_wmax b) If the line passes through the bottom or the line intersects with the bottom boundary of the window. x = x + (y_wmin – y)/m y = y_wmin c) If the line passes through the left region or the line intersects with the left boundary of the window. y = y+ (x_wmin – x)*m x = x_wmin
  • 237. Cont. d) If the line passes through the right region or the line intersects with the right boundary of the window. y = y + (x_wmax -x)*m x = x_wmax 5) Now, overwrite the endpoints with a new one and update it. 6) Repeat the 4th step till your line doesn’t get completely clipped
  • 238. Derivation: • Left: x = xmin m = y2- y1 / x2 – x1 = y – y1/ x – x1 = y- y1 / xmin – x1 y = y1 + m( xmin - x1) • Right: x = xmax m = y2- y1 / x2 – x1 = y – y1/ x – x1 = y- y1 / xmax – x1 y = y1 + m( xmax - x1)
  • 239. Cont. • Top: y = ymax m = y2- y1 / x2 – x1 = y – y1/ x – x1 = ymax- y1 / x2 – x1 x = x1 + (ymax – y1)/m • Bottom: y = ymin m = y2- y1 / x2 – x1 = y – y1/ x – x1 = ymin- y1 / x2 – x1 x = x1 + (ymin – y1)/m
  • 240. Example: 1 2 3 4 5 6 7 8 9 9 8 7 6 5 4 3 2 1 (9,6) (5,2) Let A = (x1, y1) = (5,2), B = (x2, y2) = (9,6) 1) Applying TBLR rule A = 0000, B = 0001 A AND B = 0 (Partially outside) 2) Applying right formula: x = xmax= 1 y = y1 + m( xmax - x1) m = 6 – 2 / 9 – 5 = 4/4 = 1 y = 2 + 1(7 – 5) = 4 So, intersection point is (1,4) Ignore the remaining part from (1,4) to (9,6).
  • 241. Possible cases: Visible Partially outside Not visible Partially inside, No operation required Find intersection Ignore find intersection and ignore line for two points outside the box
  • 242. Cont. 1 2 3 4 5 6 7 8 9 8 7 6 5 4 3 2 1 What if line passes through diagonal?? In the given case, (xmax, ymax) are the points intersecting. So, we already have values in case of diagonal intersection.
  • 243. Sutherland hodgeman polygon clipping algorithm: • This algorithm is used for the clipping of polygons. We start from left side of window and then clip all the sides.
  • 244. Example: • Apply Sutherland polygon clipping algorithm.
  • 245. Cont. • Starting from left side, Take an edge an check whether it is inside or not. • Outside from outside -> Ignore
  • 246. Cont. • Taking next edge • inside from inside -> Save
  • 247. Cont. • Taking next edge • inside from inside -> Save
  • 248. Cont. • Taking next edge • inside from inside -> Save
  • 249. Cont. • Taking next edge • Outside from outside -> Ignore
  • 250. Cont. • Taking next edge Done!!
  • 252. Limitations: • This algorithm gives invalid result for concave polygon. • Weiler Atherton algorithm was devised to solve this issue.
  • 253. Problem-1: • Apply Sutherland hodgeman algorithm to clip the polygon.
  • 254. Problem-2: • Apply Sutherland hodgeman algorithm to clip the polygon and apply cohn Sutherland line clipping algorithm on the edge C to D. (Assume coordinates on your own).
  • 255. Weiler Athorton polygon clipping algorithm: • This algorithm maintains two list one for path and other for intersection points. It also handles the issue of Sutherland hodgeman algorithm.
  • 257. Example: • Let's say we want to clip the below shape:
  • 258. Cont. • Assigning label to intersection points:
  • 259. Cont. • Maintain two lists for traversed path:
  • 260. Cont. • Tracing the intersection path to join lines:
  • 261. Cont.
  • 262. Cont.
  • 263. Problem-1: • Clip the given polygon using weiler athorton algorithm.
  • 265. Cont.
  • 266. Cont.
  • 267. Cont.
  • 268. Cont.
  • 269. Cont.
  • 270. Cont.
  • 272. Cyrus beck line clipping algorithm: • Cohn Sutherland algorithm works only for rectangular window. But If we have window of any other pattern, this algorithm fails. • Cyrus beck line clipping algorithm works for all kind of windows. • Normal for every edge is computed • Vector for the clipping line is computed • This algorithm uses one parametric equation and find the intersection points through this.
  • 273. Algorithm: 1) Draw and compute normal vector for each edge. 2) Find the edge points of the shape if not given already. 3) Compute all the values of ‘t’ for each edge using formula: P(t) = P0 + t(P1 – P0) x = Ni (P(t)- Pei) X > 0 -> Outside the clipping window, x<0 -> Inside the clipping window, X = 0 -> Intersection point 4) We have to find the intersection point, so we will take equation x = 0 Ni(P(t) - Pei) = 0 Ni ( P0 + t(P1 – P0) - Pei ) = 0 NiP0 + NitP1 – NitP0 – NiPei = 0 NitP1 – NitP0 = NiPei - NiP0 t( NiP1 – NiP0) = Ni(Pei – P0) t = Ni(Pei – P0) / Ni (P1 – P0) 5) Compute value of t for each edge. 6) If denominator < 0 (Entering edge), If denominator > 0 (Leaving edge 7) Find maximum from entering edge and minimum from leaving edge 8) Two ‘t’ coordinates came out, then put them into formula P(t) = P0 + t(P1 – P0) one by one P0 = starting point of intersecting line P1 = ending point of intersecting line Ni = Normal to the selected edge Pei = edge coordinates
  • 274. Example: • Find the intersection points from given pentagon window.
  • 275. Cont. 1) Normal points are N1, …N6 2) N1 = (-1, -1), N2 = (-1, 0), N3 = (-1, 1), N4 = (1, 1), N5 = (1, 0), N6 = (1, -1) Pe1 = (3,0), Pe2 = (1,2), Pe3 = (1,4), Pe4 = (3,6), Pe5 = (5,4), Pe6 = (5,2) 3) t1 = N1 (Pe1 – P0)/ N1 (P1 – P0) = (-1,-1)[(3,0) – (-2,1)] / (-1,-1)[(6,3) – (-2,1)] = -4/-10 t2 = N2 (Pe2 – P0)/ N2 (P1 – P0) = (-1,0)[(1,2) – (-2,1)] / (-1,0)[(6,3) – (-2,1)] = -3/-8 t3 = N3 (Pe3 – P0)/ N3 (P1 – P0) = (-1,1)[(1,4) – (-2,1)] / (-1,1)[(6,3) – (-2,1)] = 0/-6 t4 = N4 (Pe4 – P0)/ N4 (P1 – P0) = (1,1)[(3,6) – (-2,1)] / (1,1)[(6,3) – (-2,1)] = 10/10
  • 276. Cont. t5 = N5 (Pe5 – P0)/ N5 (P1 – P0) = (1,0)[(5,4) – (-2,1)] / (1,0)[(6,3) – (-2,1)] = 7/8 t6 = N6 (Pe6 – P0)/ N6 (P1 – P0) = (1,-1)[(5,2) – (-2,1)] / (1,-1)[(6,3) – (-2,1)] = 6/6 So, values of t1,…t6 are computed Finding entering and leaving edges Entering = -ive denominator, Leaving = +ive denominator Entering = [t1, t2 , t3], Leaving = [t4, t5, t6]
  • 277. Cont. Find maximum from entering list and minimum from leaving list Max(Entering) = t1 = -4/-10 = 2/5 Min(Leaving) = t5 = 7/8 Put values into equation: P(t) = P0 + t(P1 – P0) Let t0 = t1, t1 = t5 P(t0) = (-2, 1) + 2/5 [(6,3) – (-2,1)] = (-2,1) + 2/5 (8,2) = (6/5, 9/5) P(t1) = (-2, 1) + 7/8 [(6,3) – (-2,1)] = (-2,1) + 7/8 (8,2) = (5, 11/4) So, intersection points are (6/5, 9/5) & (5, 11/4).
  • 278. Problem-1: • Let a clipping polygon be defined by the vertices (5, 5), (20, 2), (16, 10), (10, 10). Find intersection point using cyrus beck algorithm.
  • 279. Solution: • After computing all the stuff, values are:
  • 280. Liang barsky line clipping algorithm: • Like cohn Sutherland algorithm, this algorithm also works only for rectangular window but faster and more efficient. While cyrus beck is more general and work for all kinds of windows. • This algorithm uses parametric equations and solves 4 inequalities.
  • 281. Cont.
  • 283. Cont.
  • 284. Cont.
  • 285. Cont.
  • 286. Example: • Find intersection points of window (5,5) & (9,9) with line having p1(4,12) & p2(8,8).
  • 287. Solution: • Find intersection points of window (5,5) & (9,9) with line having p1(4,12) & p2(8,8). 1) Xmin = 5, Ymin = 5, Xmax = 9, Ymax = 9 2) Δx = x2 – x1 = 8 – 4 = 4, Δy = y2 – y1 = 8 – 12 = -4 3) P1 = -Δx = -4, P2 = Δx = 4, P3 = -Δy = 4, P4 = Δy = -4 4) q1 = X1 – Xmin = 4 – 5 = -1, q2 = Xmax – X1 = 9 – 4 = 5 5) q3 = Y1 – Ymin = 12 – 5 = 7, q4 = Ymax – Y1 = 9 – 12 = -3 6) Pk = 0 (false) 7) Pk = 0 && qk < 0 (false)
  • 288. Cont. 7) Pk < 0: P1, P4 t1 = max(0, qk/pk) = max(0, -1/-4, -3/-4) = ¾ 8) Pk >0: P2, P3 t2 = min(1, qk/pk) = min(1, 5/4, 7/4) = 1 9) t1> t2 (false) 10) t2 > t2: x = x1 + t Δx = 4 + 4(3/4) = 7, y = y1 + t Δy = 12 + (-4)(3/4) = 9 So, intersection point is (7,9)
  • 289. Example: • Find intersection points of window (5,5) & (9,9) with line having p1(2,6) & p2(12, 8).
  • 290. Solution: • Find intersection points of window (5,5) & (9,9) with line having p1(2,6) & p2(12, 8). 1) Xmin = 5, Ymin = 5, Xmax = 9, Ymax = 9 2) Δx = x2 – x1 = 12 – 2 = 10, Δy = y2 – y1 = 8 – 6 = 2 3) P1 = -Δx = -10, P2 = Δx = 10, P3 = -Δy = -2, P4 = Δy = 2 4) q1 = X1 – Xmin = 2 - 5 = -3, q2 = Xmax – X1 = 9 – 2 = 7 5) q3 = Y1 – Ymin = 6 – 5 = 1, q4 = Ymax – Y1 = 9 – 6 = 3 6) Pk = 0 (false) 7) Pk = 0 && qk < 0 (false)
  • 291. Cont. 7) Pk < 0: P1, P3 t1 = max(0, qk/pk) = max(0, -30/-10, 1/-2) = 3/10 8) Pk >0: P2, P4 t2 = min(1, qk/pk) = min(1, 7/10, 3/2) = 7/10 9) t1> t2 (false) 10) t2 > t2: A: x = x1 + t Δx = 2 + 10(3/10) = 5, y = y1 + t Δy = 6 + (2)(3/10) = 6.6 B: x = x1 + t Δx = 2 + 10(7/10) = 9, y = y1 + t Δy = 6 + (2)(7/10) = 7.4 So, intersection point are (5,6.6) & (9,7.4)
  • 292. Problem-1: • Find intersection points of window (5,5) & (9,9) with line having p1(4,9) & p2(4,2).
  • 293. Solution: • Find intersection points of window (5,5) & (9,9) with line having p1(4,9) & p2(4,2). 1) Xmin = 5, Ymin = 5, Xmax = 9, Ymax = 9 2) Δx = x2 – x1 = 4 – 4 = 10, Δy = y2 – y1 = 9 – 2 = 7 3) P1 = -Δx = 0, P2 = Δx = 0, P3 = -Δy = -7, P4 = Δy = 7 4) q1 = X1 – Xmin = 4 - 5 = -1, q2 = Xmax – X1 = 9 – 4 = 5 5) q3 = Y1 – Ymin = 2 – 5 = -3, q4 = Ymax – Y1 = 9 – 2 = 7 6) Pk = 0 (true) 7) Pk = 0 && qk < 0 (true) So, there is no intersection point. Line is outside the window!
  • 295. Solution: • Intersection points are p1(-1.4, -3) & p2(3, -1).
  • 297. Introduction: • Fractals are intricate and infinitely complex mathematical patterns that exhibit self-similarity at various scales. They are often characterized by repeating patterns that can be observed regardless of the level of magnification. Fractals can be found in nature, art, and various scientific fields, and they have gained popularity in computer graphics and digital art due to their visually appealing and fascinating properties.
  • 298. Properties: • Self similarity: When broken into smaller and smaller pieces, the new piece look exactly the same as the original • Dimension: How much an object fills the space • ‘S’ represents scaling factor and is always a natural number • ‘N’ represents the number of smaller self similar figures
  • 299. Dimension of a line:
  • 300. Dimension of a square:
  • 301. Dimension of a cube:
  • 305. Kock snowflake - Dimension
  • 306. Iterated function system: • IFS (iterated function system) is another way of generating fractals. It is based on the taking a point or figure and substituting it with several other identical ones.
  • 307. Naturally occurring fractals: • Trees and plants • In the human body - Blood vessels - Alveoli in lungs
  • 309. Problem-1: • Given sierpinski carpet pattern, what could be dimension of the 2nd shape generate by this pattern. (Hint: Reverse back to small size to compute)
  • 310. Problem-2: • Apply iterative function system to create dragon curve.
  • 312. Curve: • Shape formed by sketching without lifting the pen. • In computer graphics, shape formed without any gap is curve. • Fact: Straight line is also curve.
  • 313. Types: • Implicit curves • Explicit curves • Parametric curves • Spline curves (Bezier, B-spline(periodic, non-periodic)) • NURBS (Non-uniform rational b-spline curves) • Catmul-Rom splines • Hermite curves
  • 314. Implicit curves: • Implicit curves are defined by an implicit equation that relates the coordinates (x, y, z) of a point on the curve. The equation typically involves a polynomial or algebraic expression. When evaluating the equation for a given point, it results in a value that determines whether the point is on the curve (value equals zero) or outside the curve (value greater or less than zero). Implicit curves can represent a wide range of shapes, including complex and irregular curves. f(x,y) = 0
  • 315. Explicit curves: • Explicit curves, also known as parametric curves, are defined by explicit equations that directly describe the coordinates (x, y, z) of points on the curve as functions of one or more parameters, such as time or a parameter t. The equations provide explicit formulas for the x, y, and z coordinates at any given point along the curve. Parametric curves are often used to represent smoothly varying curves and allow for more intuitive control over the curve's shape and behavior. y = f(x) ‘y’ is dependent of on the value of ‘x’, while ‘x’ is independent.
  • 316. Parametric curves: • Parametric curves are defined by a set of equations that describe the position of points along the curve as a function of one or more parameters. These curves allow for precise control over shape and are used in various applications, such as animation and curve fitting. • Peace-wise – linear, polynomial • Linear equation curve – less smooth and abrupt change • Polynomial curves – more smooth and flexible with less abrupt changes x(t) = a3t3 + a2t2 + a1t + a0 y(t) = b3t3 + b2t2 + b1t + b0 z(t) = c3t3 + c2t2 + c1t + c0 (These equations can also be represented via matrix form)
  • 318. Parametric continuity: • When we join two or more curves, we need to observe its smoothness to ensure the continuity (regularity). There are three basic types of parametric continuity: • Zero-order continuity: if joining points of two curve are same. Let say we have joined two curves A and B then at joining point: A(t=1) = B(t=0) • It is represented as C0
  • 319. Cont. • First-order continuity: if joining points of two curve are same. Let say we have joined two curves A and B then at joining point: • A’(t=1) = B’(t=0) (1st order derivate of joining point is same) • It is represented as C1
  • 320. Cont. • Second-order continuity: if joining points of two curve are same. Let say we have joined two curves A and B then at joining point: • A’’(t=1) = B’’(t=0) (2nd order derivate of joining point is same) • It is represented as C2
  • 321. Geometric continuity: • We have check for parameters of piecewise polynomial in parametric continuity while in geometric, we consider the tangent of curve to observe how well shape is formed.
  • 322. Cont. • Zero-order geometric continuity: Same as zero-order parametric continuity • First-order geometric continuity: Point of junction of curves have first order derivative directly proportional to each other (not magnitude always) A’(t=1) = k(B’(t=0)) • First-order geometric continuity: Point of junction of curves have second order derivative directly proportional to each other (not magnitude always A’’(t=1) = k(B’’(t=0)) These are represented by Gn. Where ‘n’ is the order. In simple words, tangent line of both curves’ junction point must be same which will indicate the slope of change.
  • 323. Spline curves: • A spline curve is a mathematical representation for which it is easy to change the curve design put changing the control points (points taken as reference for future modification). It is flexible enough an can be used to adjust in any shape. If a spline curves’ control points form a polygon, then it is convex hull.
  • 324. Cont. • Interpolation spline: A spline curve which passes through all the control points. • Approximation spline: A spline curve which passes through not all the control points.
  • 325. Bezier curve: • A type of spline curve which is used to generate polygon. It forms approximate spline curve (curve must pass from starting and ending point but not necessary to pass through all other points). Convex hull is formed if complete curve lie inside the control points. • Degree of polynomial is always one less than total no. of control points. For example, if 2 control point -> linear, 3 control points -> quadratic. • A Bezier curve must pass from starting and ending control point. • The slope at the beginning of the curve is along the line joining the first two control points and the slope at the end of the curve is along the line joining the last two points of convex hull.
  • 326. Properties of Bezier curve: • Bezier curve is always contained within polygon called as convex hull of its control points. • The first and last points of the curve are coincident with the first and last points of the defining polygon. • The degree of the polynomial defining the curve segment is one less than the total number of control points.
  • 327. Cubic Bezier curve: • Cubic bezier curve is a bezier curve with degree 3. • The total number of control points in a cubic bezier curve is 4.
  • 328. Bezier equation: •t is any parameter where 0 <= t <= 1 •P(t) = Any point lying on the bezier curve •Bi = ith control point of the bezier curve •n = degree of the curve •Jn,i(t) = Blending function = C(n,i)ti(1-t)n-i where C(n,i) = n! / i!(n-i)!
  • 329. Example: • Given cubic Bezier curve: • This curve is defined by 4 control points b0, b1, b2 and b3. • The degree of this curve is 3. • So, it is a cubic bezier curve.
  • 330. Cont. Q(t) = Σn i=0 Bi,n (u) * Pi B0,3(u) = 3C0 * (u)0 * (1-u)3-0 = (1 - u)3 B1,3(u) = 3C1 * (u)1 * (1-u)3-1 = 3u(1 - u)2 B2,3(u) = 3C2 * (u)2 * (1-u)3-2 = 3u2(1 - u)2 B3,3(u) = 3C3 * (u)3 * (1-u)3-3 = u3 Q(t) = P0*(1 - u)3 + P1*3u(1 - u)2 + P3*3u2(1 - u)2 + P4*u3 This is required parametric equation for Bezier curve.
  • 331. Problem-1: • Given a Bezier curve having 4-control points: (1,0), (3,3), (6,3), (8,1) Determine any 5 points lying on the curve. Also, draw a rough sketch of the curve.
  • 332. Solution: • 5 points are allowed to take: 0 <= u <= 1 1/ u-1 = 1/5-1 = ¼ = 0.25 taking 5 points with increment of 0.25 u = [0.0, 0.25, 0.50, 0.75, 1.0] As total control points are 4, so order of polynomial is n-1 = 3 Q(t) = Σn i=0 Bi,n (u) * Pi = Q(t) = Σ3 i=0 Bi,3 (u) * Pi Now we need to compute B0,3 B1,3 B2,3 B3,3
  • 333. Cont. B0,3(u) = 3C0 * (u)0 * (1-u)3-0 = (1 - u)3 B1,3(u) = 3C1 * (u)1 * (1-u)3-1 = 3u(1 - u)2 B2,3(u) = 3C2 * (u)2 * (1-u)3-2 = 3u2(1 - u)2 B3,3(u) = 3C3 * (u)3 * (1-u)3-3 = u3 Q(u) = P0*(1 - u)3 + P1*3u(1 - u)2 + P3*3u2(1 - u)2 + P4*u3 As we now Bezier curve takes starting and ending point from the same shape, so we need to compute intermediate 3 points. X(u) = x0*(1 - u)3 + x1*3u(1 - u)2 + x3*3u2(1 - u)2 + x4*u3 y(u) = y0*(1 - u)3 + y1*3u(1 - u)2 + y3*3u2(1 - u)2 + y4*u3
  • 334. Cont. • For u = 0.0 P(0) = [1 0](1-0)3 + [3 3]3(0)(1-t)2 + [6 3]3(0)2(1-0) + [8 1](0)3 P(0) = [1 0] + 0 + 0 + 0 P(0) = [1 0] • For u = 0.25 P(0.2) = [1 0](1-0.2)3 + [3 3]3(0.2)(1-0.2)2 + [6 3]3(0.2)2(1-0.2) + [8 1](0.2)3 P(0.2) = [1 0](0.8)3 + [3 3]3(0.2)(0.8)2 + [6 3]3(0.2)2(0.8) + [8 1](0.2)3 P(0.2) = [1 0] x 0.512 + [3 3] x 3 x 0.2 x 0.64 + [6 3] x 3 x 0.04 x 0.8 + [8 1] x 0.008 P(0.2) = [1 0] x 0.512 + [3 3] x 0.384 + [6 3] x 0.096 + [8 1] x 0.008 P(0.2) = [0.512 0] + [1.152 1.152] + [0.576 0.288] + [0.064 0.008] P(0.2) = [2.304 1.448]
  • 335. Cont. • For u = 0.50 P(0.5) = [1 0](1-0.5)3 + [3 3]3(0.5)(1-0.5)2 + [6 3]3(0.5)2(1-0.5) + [8 1](0.5)3 P(0.5) = [1 0](0.5)3 + [3 3]3(0.5)(0.5)2 + [6 3]3(0.5)2(0.5) + [8 1](0.5)3 P(0.5) = [1 0] x 0.125 + [3 3] x 3 x 0.5 x 0.25 + [6 3] x 3 x 0.25 x 0.5 + [8 1] x 0.125 P(0.5) = [1 0] x 0.125 + [3 3] x 0.375 + [6 3] x 0.375 + [8 1] x 0.125 P(0.5) = [0.125 0] + [1.125 1.125] + [2.25 1.125] + [1 0.125] P(0.5) = [4.5 2.375] • For u = 0.75 P(t) = [1 0](1-t)3 + [3 3]3t(1-t)2 + [6 3]3t2(1-t) + [8 1]t3 P(0.7) = [1 0](1-0.7)3 + [3 3]3(0.7)(1-0.7)2 + [6 3]3(0.7)2(1-0.7) + [8 1](0.7)3 P(0.7) = [1 0](0.3)3 + [3 3]3(0.7)(0.3)2 + [6 3]3(0.7)2(0.3) + [8 1](0.7)3 P(0.7) = [1 0] x 0.027 + [3 3] x 3 x 0.7 x 0.09 + [6 3] x 3 x 0.49 x 0.3 + [8 1] x 0.343 P(0.7) = [1 0] x 0.027 + [3 3] x 0.189 + [6 3] x 0.441 + [8 1] x 0.343 P(0.7) = [0.027 0] + [0.567 0.567] + [2.646 1.323] + [2.744 0.343] P(0.7) = [5.984 2.233]
  • 336. Cont. • For u = 1.0 P(1) = [1 0](1-1)3 + [3 3]3(1)(1-1)2 + [6 3]3(1)2(1-1) + [8 1](1)3 P(1) = [1 0] x 0 + [3 3] x 3 x 1 x 0 + [6 3] x 3 x 1 x 0 + [8 1] x 1 P(1) = 0 + 0 + 0 + [8 1] P(1) = [8 1] So, Bezier curve points are: (0,1), (2.3,1.4), (4.5, 2.3), (5.9,2.2), (8,1)
  • 337. Problem-2: • Given control points of Bezier curve: (0,0), (1,2), (3,3), (4,0) Find the Bezier curve taking arbitrary number of points. The more points you take, curve will be smoother.
  • 338. Solution: • Using formulas, Bezier curve points are: (0,0), (0.9, 1.26), (2,1.87), (3.09,1.54), (4,0)
  • 339. B-spline curve: • Concept of B-spline curve came to resolve the disadvantages having by Bezier curve, as we all know that both curves are parametric in nature. In Bezier curve we face a problem, when we change any of the control point respective location the whole curve shape gets change. But here in B-spline curve, the only a specific segment of the curve-shape gets changes or affected by the changing of the corresponding location of the control points. • In the B-spline curve, the control points impart local control over the curve-shape rather than the global control like Bezier-curve. • Points of junction is often called as knot points.
  • 340. Cont. As we can see, local change does not affect the global curve.
  • 341. NURBS • Non-uniform b-spline curve is a type of b-spline curve in which gap between curves is not uniform. Periodic spline curves has repeating pattern with equal gap.
  • 342. Catmull-Rom curves: Catmull-Rom curves are a type of cubic interpolation curve used in computer graphics and animation. Given a set of control points P₀, P₁, P₂, ..., Pₙ₋₁, the Catmull-Rom curve C(t) is defined as a piecewise cubic polynomial that smoothly passes through each consecutive pair of control points. • The formula for the Catmull-Rom curve between control points Pᵢ and Pᵢ₊₁ is: • C(t) = ((-t³ + 2t² - t)Pᵢ + (3t³ - 5t² + 2)Pᵢ₊₁ + (-3t³ + 4t² + t)Pᵢ₊₂ + (t³ - t²)Pᵢ₊₃) / 2 • where t is the parameter ranging from 0 to 1, determining the position along the curve. • The Catmull-Rom curve calculation is based on a local control scheme, meaning that the shape of the curve is determined by the positions of the adjacent control points. This local influence allows for easy manipulation and adjustment of the curve's shape. • Catmull-Rom curves exhibit several desirable properties, including passing through the control points, maintaining continuity, and providing smoothness in the resulting curve.
  • 343. Hermite curve: • A Hermite curve, named after Charles Hermite, is a type of interpolation curve used in computer graphics and mathematics. It is often used to create smooth and continuous curves defined by specified control points and their associated tangents. • It is an interpolation spline curve. • The Hermite curve calculation incorporates both the position and tangent information, allowing for precise control over the curve's shape and direction. The tangents determine the slope or direction of the curve at each control point, influencing the curve's behavior between the points.
  • 344. Example: • Let say we have a hermite curve with pk as initial and pk+1 as final point. Value is between ‘0’ & ‘1’. • Pk = P(0) = initial point • Pk+1 = P(1) = end point • Pk’ = DPk = derivative of ‘pk’ • Pk+1’ = DPk+1 = derivative of ‘pk+1’
  • 345. Cont. • P(u) = au3 + bu2 + cu + d , where 0 <= u <= 1 Px(u) = axu3 + bxu2 + cxu + dx Py(u) = ayu3 + byu2 + cyu + dy Pz(u) = azu3 + bzu2 + czu + dz P’(u) = 3au2 + 2bu + c P(0) = a*0 + b*0 + c*0 + d P(1) = a*1 + b*1 + c*1 + d P’(0) = 3a*0 + 2b*0 + c P’(1) = 3a*1 + 2b*1 + c
  • 346. Cont.
  • 348. Introduction: • Animation refers to the movement on the screen of the display device created by displaying a sequence of still images. Animation is the technique of designing, drawing, making layouts and preparation of photographic series which are integrated into the multimedia and gaming products. Animation connects the exploitation and management of still images to generate the illusion of movement.
  • 349. Applications: • Education & training • Entertainment • Computer Aided Design (CAD) • Advertising • Presentation
  • 350. Animation functions: • Morphing: Morphing is an animation function which is used to transform object shape from one form to another is called Morphing. It is one of the most complicated transformations. This function is commonly used in movies, cartoons, advertisement, and computer games.
  • 351. Cont. • Wrapping: Wrapping function is similar to morphing function. It distorts only the initial images so that it matches with final images and no fade occurs in this function. • Tweening: Tweening is the short form of 'inbetweening.' Tweening is the process of generating intermediate frames between the initial & last final images. This function is popular in the film industry.
  • 353. Tilting: • In animation, tilting refers to the movement of an object or camera along a vertical axis. It involves changing the vertical angle or orientation of the object or camera to create a sense of tilt or slant. • When an object or camera tilts in an animation, it appears to lean or pivot around the vertical axis. This movement can be used to add dynamics, depth, and visual interest to a scene.
  • 354. Cont. • Panning: Usually Panning refers to rotation of the camera in horizontal Plane. In computer graphics, Panning relates to the movement of fixed size window across the window object in a scene. In which direction the fixed sized window moves, the object appears to move in the opposite direction.
  • 355. Cont. • Zooming: the window is fixed an object and change its size, the object also appear to change in size. When the window is made smaller about a fixed center, the object comes inside the window appear more enlarged. This feature is known as Zooming In. • When we increase the size of the window about the fixed center, the object comes inside the window appear small. This feature is known as Zooming Out.
  • 356. Cont. • Rigging: The process of defining internal structure of a character like bones/skeleton. It is the initial phase in animation where internal design is first prepared. After then skinning is done to provide outer structure of the animation character like skin, clothes. Rigging Skinning
  • 357. Cont. • Key frame animation: The process of generating only key/important frames of the animation and remaining/intermediate frames are automatically added by software (tweening). • Motion capture: Creating animation based on real life objects like creating a character on a specific human. • Texture mapping: The process of applying a specific pattern in animation to make it more realistic in 3D. For example, I have a cube involved in my animation of black color, I want to make cube made of wood, then I will wrap the cube inside the wood color (texture) to make the illusion of looking like a wooden cube.
  • 359. Types of animation: • Procedural: In this process, objects are animated with a procedure (set of rules). Animator specifies the rules to be followed. • Behavioral: Animator determines actions required to take on certain frame. The process put more action in animation. • Dynamics: Unlike key framing and motion picture, simulation uses the laws of physics to generate motion of pictures and other objects. Simulations can be easily used to produce slightly different sequences while maintaining physical realism. Secondly, real-time simulations allow a higher degree of interactivity where the real person can maneuver the actions of the simulated character. These animations are created in physics engines where physical behaviors can be scripted, even those with minute details such as fluids or smoke.
  • 360. Raster animation: • Raster images are collection of a large number of pixels stored in a buffer in shape of matrix in bitmap format. • When these raster images are displayed in a particular sequence, it is raster animation. Each raster image is a frame in animation. Frame buffer is refreshed iteratively.
  • 361. Traditional raster animation: • Used low detailed animation using sprite sheets • Sprite sheet is a single image having different motions in different cells. In simple words, it encloses animation in a single image but limited number of frames are stored.
  • 362. Vector animation: • It stores images as a sequence of points. Vector animation does not provide much clarity as compared to raster animation. • Raster animations are high resolution as compared to vector animation.
  • 363. Color table animation: • Color table animation, also known as palette animation or indexed color animation, is a technique used to create animations in which the colors of the image or scene change over time. It is commonly used in older systems or graphics formats that have limited color capabilities. • In color table animation, instead of directly changing the colors of individual pixels in the image or scene, a fixed color table or palette is used. The color table contains a limited set of colors, often referred to as color indices. Each pixel in the image is assigned a color index that corresponds to a specific color in the color table.
  • 364. Double buffering: • Double buffering is a technique used in animation and computer graphics to prevent flickering and create smoother, more visually appealing animations. • In computer graphics, the image displayed on the screen is updated and refreshed multiple times per second. Without buffering, when an image is being drawn on the screen, there is a possibility of seeing incomplete or partially drawn frames, resulting in flickering or visual artifacts. • Double buffering solves this issue by introducing two buffers: a front buffer and a back buffer. The front buffer represents the currently displayed image on the screen, while the back buffer is a hidden or off-screen buffer where the next frame of the animation is prepared.
  • 366. Direct motion specification: • We explicitly give the rotation angles and translation vectors. • Then the geometric transformation matrices are applied to transform co-ordinate positions. • These methods can be used for simple user programmed sequences.
  • 367. Goal directed system: • We an specify the motions that are to take place in general terms that abstractly describes the actions. • These systems are referred to as goal directed because they determine specific motion parameters given the goals of the animation. For example, we could specify that we want an object to “walk” or to “run” to a particular destination.
  • 368. Kinematics and dynamics: • Kinematics: motion of study (position, velocity, acceleration) • The movement of object from one place to another • Measured over a time interval such as s, min,h • Relative to the position of the observer or reference point • Dynamics: Full consideration of time varying phenomenon in the interaction between motion, forces and material properties • Typically, there is a time-integration process where result from one time frame effect the result on the next time frame.
  • 369. Virtual/augmented reality: • Advance sub-field of animation • Process of creating real world animation with more and more realism • AVATAR like movies based on this technology
  • 371. Introduction: • Given an illumination incident at a point on a surface, quantification is required to compute the intensity. • Used to compute interaction of light with surfaces • Factors determining lighting effect: - Light source, surface, eye (camera)
  • 372. Light sources: • Point source: All lights originate at a point and radially diverge. A reasonable approximation for sources whose dimensions are small compared to the object size. For example, bulb in a room. • Parallel source: Light is distributed parallelly in all directions. For example, tube-light in a room. • Distributed source: Light is scattered with unequal length. For example, disco lights in party and functions. Point Parallel Distributed
  • 373. Ambient light: • Non-directional • Amount of light incident is constant on all surfaces • Background light • Not very realistic • Indirect light source • Can be natural/artificial, sun-light is reflected equally on all sources
  • 374. Beer Lamberts’s law: • It states that intensity of color observed from any reflecting surface is directly proportional to cosine of the angle between direction of incident light and the normal surface.
  • 375. Diffuse light: • Scattered along all points equally. (parallel source) • Surface that are rough or grainy tend to scatter the reflected light in all directions • Measured by angle made by taking normal to the point where light is incident to the light source making a cosine angle. Or it can be specified as product of N.L (N = normal to the vector, L = light direction) • A surface only illuminates light if the angle of incidence is in between 0 and 90 degree because cosine must be between 0 and 1. • When cosine is negative, light source is behind the surface.
  • 376. Specular reflection: • Model for shiny and glossy surfaces like metals • An ideal specular surface reflects light in one direction
  • 377. Specular reflection: • Adds brightness factor on most outward edge.
  • 379. Ambient + diffuse + specular:
  • 381. Example: • Identify the light source in the required section of image. ? ?
  • 382. Example: • Identify the light source in the required section of image. Diffuse reflection
  • 384. Shading: • The process of manipulating color of the shape to make it more realistic is shading. It has four main types: • Flat/Constant shading • Gouraund shading • Phong shading
  • 385. Flat shading: • A fast and straight forward method for rendering an object with polygon surface is constant or flat shading. In this method, a single intensity is computed by taking a normal to the specific/desired side of shape and energy of light is computed by multiplying reflectivity and refractivity. All points with-in the surface are assigned the same color. It is the fastest one but less realistic and can make image more worse with respect to intensity. It can be used to display the general appearance of the shape.
  • 386. Cont. • If shape has more than one side, normal at each face is computed at that intensity is applied to corresponding face only. • It provides intensity discontinuity which causes match band effect.
  • 387. Gouraud shading: • This method uses interpolation by rasterizing the shape line by line. • Step1: Find adjacent vertex's normal • Step2: Apply illumination model at each polygon vertex to determine polygon vertex intensity. • Step3: Linearly interpolate the vertex intensity over the surface of polygon.
  • 388. Example: • Step1: Along vertex ‘V’ adjacent edges are N1, N2, N3 • Taking a 2D shape to interpolate easily step 2 • Lets’ find the interpolation for ‘a’, ‘p’ & ‘b’.
  • 389. Cont. • Intensity of a = Ia = ya – y2 / y1 – y2 (I1) + y1 – ya/ y1 - y2(I2) • Intensity of b = Ib = yb – y2 / y2 – y3 (I3) + y3 – yb/ y2 – y3(I2) • Intensity of p = Ip = xb – xp / xb – xa (Ia) + xp – xa/ xb – xa(Ib)