You are on page 1of 18

# Parabola Drawing

## CS335 Computer Graphics

Parabola Drawing Algorithms

figs/NITr

## Dr. Sambit Bakshi CS335 Computer Graphics

Parabola Drawing

1 Parabola Drawing
Parabola Drawing
Midpoint Parabola Drawing Algorithm

figs/NITr

## Dr. Sambit Bakshi CS335 Computer Graphics

Parabola Drawing
Parabola Drawing
Midpoint Parabola Drawing Algorithm

Equation of a parabola

## General parabola drawing problem: parameters are focus and

vertex
(y k)2 = 4a(x h)
p
y = k 4a(x k)
x = h + (y k)2 /4
Creates uneven spacing if plotted!!!

figs/NITr

## Dr. Sambit Bakshi CS335 Computer Graphics

Parabola Drawing
Parabola Drawing
Midpoint Parabola Drawing Algorithm

Drawing a parabola

figs/CircleDrawWithYasFx.png figs/CircleDrawWithXasFy.png

## Figure: Plot withp Figure: Plot with

y = f (x) = k 4a(x h) x = f (y ) = h + (y k)2 /4a figs/NITr

## Dr. Sambit Bakshi CS335 Computer Graphics

Parabola Drawing
Parabola Drawing
Midpoint Parabola Drawing Algorithm

Drawing a parabola

## How to eliminate uneven spacing?

parametric form:
y = k 2at
x = h + at 2
Computation can be reduced by exploiting symmetry

figs/NITr

## Dr. Sambit Bakshi CS335 Computer Graphics

Parabola Drawing
Parabola Drawing
Midpoint Parabola Drawing Algorithm

Drawing a parabola

figs/MidpointCircleSymmetry.png

figs/NITr

## Dr. Sambit Bakshi CS335 Computer Graphics

Parabola Drawing
Parabola Drawing
Midpoint Parabola Drawing Algorithm

Drawing a parabola

p
y =k 4a(x k)
x = h + (y k)2 /4
Each pixel computation would need 2 addition (or
subtraction), 2 multiplication (or division) and 3
exponentiation (or root) operation

figs/NITr

## Dr. Sambit Bakshi CS335 Computer Graphics

Parabola Drawing
Parabola Drawing
Midpoint Parabola Drawing Algorithm

## Midpoint Parabola Drawing

fparabola = y 2 4ax
Without loss of generalization, we consider vertex at (0, 0)

< 0; if (x, y ) is inside the boundary
fparabola (x, y ) = = 0; if (x, y ) is on the boundary
> 0; if (x, y ) is outiside the boundary

dy 2a
Slope of parabola at (x, y ) = dx = y

figs/NITr

## Dr. Sambit Bakshi CS335 Computer Graphics

Parabola Drawing
Parabola Drawing
Midpoint Parabola Drawing Algorithm

## The algorithm takes an input say

(x, y ) and starts from (0, 0) and
move towards (x, y )
We move from Region 1 to 2 when
dy
= 2a 1, i.e. y 2a figs/ellipse_region.png
dx y
Midpoint parameters are formed in
different way in two regions
Region 1: Change in x < Change in
y
Region 2: Change in y < Change in
x

## Figure: Rationally choosing the

independent axes figs/NITr

## Dr. Sambit Bakshi CS335 Computer Graphics

Parabola Drawing
Parabola Drawing
Midpoint Parabola Drawing Algorithm

## Assuming (xk , yk ) is plotted, we

want to plot (xk+1 , yk+1 )
We consider yk+1 = yk + 1 MidpointDecision_parabolaRegi
and we check if xk+1 = xk or
xk+1 = xk + 1
p1k
= fparabola (xk + 21 , yk + 1)
= (yk + 1)2 4a(xk + 21 )

## Figure: Decision parameter in

Region 1 figs/NITr

## Dr. Sambit Bakshi CS335 Computer Graphics

Parabola Drawing
Parabola Drawing
Midpoint Parabola Drawing Algorithm

## Finding Decision Parameter in Region 1

p1k
= fparabola (xk + 21 , yk + 1)
= (yk + 1)2 4a(xk + 21 )
p1k+1
= fparabola (xk+1 + 12 , yk+1 + 1)
= (yk+1 + 1)2 4a(xk+1 + 12 ) figs/MidpointDecision_ellipse
p1k+1
= p1k + 1 + 2yk+1 + 4a(xk xk+1 )
IF p1k < 0
xk+1 = xk
p1k+1 = p1k + 1 + 2yk+1
OTHERWISE
xk+1 = xk + 1
p1k+1 = p1k + 1 + 2yk+1 4a Figure: Decision parameter in
Region 1 figs/NITr

## Dr. Sambit Bakshi CS335 Computer Graphics

Parabola Drawing
Parabola Drawing
Midpoint Parabola Drawing Algorithm

Finding p10

p10 figs/MidpointDecision_parabol
= fparabola ( 21 , 1)
= 12 4a 12
= 1 2a

## Figure: Decision parameter in

Region 1 figs/NITr

## Dr. Sambit Bakshi CS335 Computer Graphics

Parabola Drawing
Parabola Drawing
Midpoint Parabola Drawing Algorithm

## Assuming (xk , yk ) is plotted, we

want to plot (xk+1 , yk+1 )
We consider xk+1 = xk + 1 figs/MidpointDecision_ellipse
and we check if yk+1 = yk or
yk+1 = yk + 1
p2k
= fparabola (xk + 1, yk + 21 )
= (yk + 12 )2 4a(xk + 1)

## Figure: Decision parameter in

Region 2 figs/NITr

## Dr. Sambit Bakshi CS335 Computer Graphics

Parabola Drawing
Parabola Drawing
Midpoint Parabola Drawing Algorithm

## Finding Decision Parameter in Region 2

p2k
= fparabola (xk + 1, yk + 21 )
= (yk + 12 )2 4a(xk + 1)
p2k+1
= fparabola (xk+1 + 1, yk+1 + 12 )
= (yk+1 + 12 )2 4a(xk+1 + 1)
figs/MidpointDecision_ellipse
p2k+1
=
p2k +(yk+1 )2 (yk )2 +(yk+1 yk )4a
IF p2k < 0
yk+1 = yk + 1
p2k+1 = p2k 4a + 2yk+1
OTHERWISE
yk+1 = yk
p2k+1 = p2k 4a Figure: Decision parameter in
Region 2 figs/NITr

## Dr. Sambit Bakshi CS335 Computer Graphics

Parabola Drawing
Parabola Drawing
Midpoint Parabola Drawing Algorithm

Finding p20

p20 figs/MidpointDecision_ellipse
= fparabola (x0 + 1, y0 + 21 )
= (y0 + 21 )2 4a(x0 + 1)
(x0 , y0 ) is the last point of Region 1.

## Figure: Decision parameter in

Region 2 figs/NITr

## Dr. Sambit Bakshi CS335 Computer Graphics

Parabola Drawing
Parabola Drawing
Midpoint Parabola Drawing Algorithm

## Midpoint parabola drawing algorithm

1 Input: a, x, y
2 (x0 , y0 ) (0, 0) 10 (x0 , y0 ) (xk , yk )
3 Load (x0 , y0 ) 11 Load (x0 , y0 )
4 p10 1 2a 12 p20 = (y0 + 12 )2 4a(x0 + 1)
5 k0 13 k0
6 if (p1k < 0) 14 if (p2k > 0)
xk+1 xk , yk+1 yk + 1, xk+1 xk + 1, yk+1 yk + 1,
Load (xk , yk+1 ) Load (xk + 1, yk + 1)
p1k+1 = p1k + 1 + 2yk+1 p2k+1 = p2k 4a + 2yk+1
7 Otherwise 15 Otherwise
xk+1 xk + 1, yk+1 yk + 1, xk+1 xk + 1, yk+1 yk ,
Load (xk + 1, yk + 1) Load (xk + 1, yk )
p1k+1 = p1k + 1 + 2yk+1 4a p2k+1 = p2k 4a
8 k (k + 1) 16 k (k + 1)
9 Repeat steps 6,7,8 while yk < 2a 17 Repeat steps 14,15,16 while yk < y
and yk < y
figs/NITr

## Dr. Sambit Bakshi CS335 Computer Graphics

Parabola Drawing
Parabola Drawing
Midpoint Parabola Drawing Algorithm

## Find the coordinate of raster points on the parabola

with focus a = 1 and vertex (0, 0) till (10, 6).

figs/NITr

## Dr. Sambit Bakshi CS335 Computer Graphics

Parabola Drawing
Parabola Drawing
Midpoint Parabola Drawing Algorithm

## k p1k xk+1 yk+1

0 -1 0 0
p0 = 1 2 2 = 3 1 0 0 1

## (x0 , y0 ) (0, 0) for Region 1.

k p2k xk+1 yk+1
We move out of Region 1 at 0 -2 1 2
k=1 as yk > 2a. The last 1 2 3 3
2 -2 3 3
point of Region 1 is (0, 1). 3 4 4 4
4 0 5 4
5 -4 6 4
(x0 , y0 ) (0, 1) for Region 2.
6 4 7 5
p20 = f (0 + 1, 1 + 0.5) = 2 7 0 8 5
We stop when x = 10 8 -4 9 5
9 6 10 6

figs/NITr