SlideShare une entreprise Scribd logo
1  sur  6
Télécharger pour lire hors ligne
Drawing
• Most computer generated images made up of
geometric primitives (polygons, lines, points)

Scan Conversion 1: Lines, Circles
and Fractals
Greg Humphreys

• Application draws them by setting bits in the
framebuffer
• Most graphics applications involve scene database
management

CS445: Intro Graphics
University of Virginia, Fall 2003

A DDA Line Drawing Function
Line(int x1, int y1, int x2, int y2)
{
int dx = x1 - x2, dy = y2 - y1;

Scene
Database

Graphics
Application

Device
Driver

Framebuffer

Display

We Can Do Better Than That...
• Get rid of all those nasty floating point operations
• The idea: find the next pixel from the current one

int n = max(abs(dx),abs(dy));
float dt = n, dxdt = dx/dt, dydt = dy/dt;
float x = x1, y = y1;
while (n--)
{
DrawPoint( round(x), round(y) );
x += dxdt;
y += dydt;

• So which of the green pixels is next?

}
}

What’s bad about this?

The Key

The Midpoint Test

• We’re only ever going to go right one pixel, or up and
right one pixel (if the slope of the line is between 0
and 1). Call these two choices “E” and “NE”

• Look at the vertical grid line that our line intersects

• Let’s think of pixels as “lattice points” on a grid

• On which side of the midpoint (y+1/2) does the
intersection lie?
• If it’s above the midpoint, go NE, otherwise go E

• Given an X coordinate, we only need to choose
between y and y+1 (y is the Y coordinate of the last
pixel)

1
Our Example

Implicit Functions
• Normally, a line is defined as

y+3

• Instead, define
be everywhere where

y+2

• Now, if

, and let the line

, we’re “above” the line, and if
, we’re “below” the line

y+1
y

x

x+1

x+2

x+3

x+4

x+5

x+6

x+7

Who Cares?

Midpoint Algorithm

• We can evaluate the implicit line function at the
midpoint to figure out where to draw next!

Line(int x1, int y1, int x2, int y2)
{
int dx = x2 - x1, dy = y2 - y1;

• In fact, we can use the last function evaluation to find
the next one cheaply!
• For ANY

int e = 2*dy - dx;
int incrE = 2*dy, incrNE = 2*(dy-dx);
int x = x1, y = y1;

:
DrawPoint( x, y );
while (x < x2)
{
x++;
if ( e <= 0 ) { e += incrE; }
else { y++; e += incrNE; }
DrawPoint( x, y );
}

• “e” holds the
implicit function
evaluation at
each x value
(actually, it’s
multiplied by 2,
but all we care
about is the sign).
• Easy extension
for lines with
arbitrary slopes.

}

Midpoint Algorithm for Circles

More Midpoint Circle Drawing

• Only consider the second octant (the others are
symmetric anyhow)

• The circle’s implicit function (r is the radius):

• Midpoint test still works: do we go right, or right and
down?

• Once we know the value of the implicit function at
one midpoint, we can get the value at the next
midpoint by the same differencing technique:

E

 If we’re going E:
SE

 If we’re going SE:

2
Drawing the 2nd Octant

Final Circle Drawer

void Circle( int cx, int cy, int radius )
{
int x = 0, y = radius, e = 1-radius;
DrawPoint( x + cx, y + cy );

• Look at all those
expensive multiplies!
Can we get rid of them
too?

while (y > x)
{
if (e < 0) // Go “east”
{
e += 2*x + 3;
}
else // Go “south-east”
{
e += 2*(x-y) + 5;
y--;
}
x++;
DrawPoint( x + cx, y + cy );
}

void Circle( int
{
int x = 0, y =
int incrE = 3,
DrawPoint( x +

radius, e = 1-radius;
incrSE = -2*radius + 5
cx, y + cy );

while (y > x)
{
if (e < 0) // Go “east”
{
e += incrE;
incrE += 2; incrSE += 2;
}
else // Go “south-east”
{
e += incrSE;
incrE += 2; incrSE += 4;
y--;
}
x++;
DrawPoint( x + cx, y + cy );
}

• How about doing finite
differencing on the “e”
variable itself?
 If we go E:
 If we go SE:

}

cx, int cy, int radius )

This looks pretty fast!

}

Flood Fill

Simple 4-connected Fill

• The idea: fill a “connected region” with a solid
color

• The simplest algorithm to fill a 4-connected region is
a recursive one:

• Term definitions:
8

4

8

4

1

4

8

4

8

• The center “1” pixel is 4-connected to the pixels
marked “4”, and 8-connected to the pixels
marked “8”

FloodFill( int x, int y, int inside_color, int new_color )
{
if (GetColor( x, y ) == inside_color)
{
SetColor( x, y, new_color );
FloodFill( x+1, y , inside_color, new_color );
FloodFill( x-1, y , inside_color, new_color );
FloodFill( x,
y+1, inside_color, new_color );
FloodFill( x,
y-1, inside_color, new_color );
}
}

A Span-based Algorithm

Fractals

• Definition: a run is a horizontal span of identically
colored pixels

• Fractal: any curve or shape exhibiting self-similarity
at any scale

h

b

c

s

a
d
e

f
g
i
Start at pixel “s”, the seed. Find the run containing “s” (“b”
to “a”). Fill that run with the new color. Then search every
pixel above that run, looking for other pixels of the interior
color. For each one found, find the right side of that run
(“c”), and push that on a stack. Do the same for the pixels
below (“d”). Then pop the stack and repeat the procedure
with the new seed. The algorithm finds runs ending at “e”,
“f”, “g”, “h”, and “i”

• Fractals appear in nature all the time
• Part of the general science of chaos

3
The Koch Curve

Properties of the Koch Curve

• Start with a line

• It occupies a finite area in the plane

• Replace the line with four lines, and repeat:

• It has infinite length
• It is self-similar
• It has a dimension of

• It’s easier to draw in polar coordinates (hint, hint…)

Non-Integral Dimension???

Self Similar Curves in Nature

• Let’s look at other “self-similar” shapes:

• How long is a coastline?

Shape

 Measure on a map
 Walk around big boulders
 Measure each grain of sand

#Parts

Scale

Dimension

2

2

1

• Cellular structure of leaves

4

2

2

• Blood vessel structure

8

2

3

4

3

?

• Ethernet packet traffic (okay, that’s not really Nature)

Drawing Fractal Trees

Fractal Trees

#define ANGLE 45
void tree (float X1, float Y1, float R,
float Theta, int Level)
{
float SX, SY, EX, EY;
if (Level >
{
EX =
EY =
line

SX =
SY =
tree
tree

0)
X1 + (R * cos(Theta));
Y1 + (R * sin(Theta));
(X1, Y1, EX, EY);

X1 +
Y1 +
(SX,
(SX,

((R
((R
SY,
SY,

* 0.5)
* 0.5)
R*0.8,
R*0.8,

* cos(Theta));
* sin(Theta));
Theta-ANGLE, Level-1);
Theta+ANGLE, Level-1);

}
}

4
Better Fractal Trees
#define RT_ANGLE
#define LFT_ANGLE

Non Symmetric Tree

45
65

void non_sym_tree (float X1, float Y1, float R,
float Theta, int Level)
{
float SX, SY, EX, EY;
if (Level > 0)
{
EX = X1 + (R * cos(Theta));
EY = Y1 + (R * sin(Theta));
line (X1, Y1, EX, EY);
SX = X1 + ((R * 0.4) * cos(Theta));
SY = Y1 + ((R * 0.4) * sin(Theta));
non_sym_tree (SX, SY, R*0.8, Theta-RT_ANGLE, Level-1);
SX = X1 + ((R * 0.6) * cos(Theta));
SY = Y1 + ((R * 0.6) * sin(Theta));
non_sym_tree (SX, SY, R*0.8, Theta+LFT_ANGLE, Level-1);
}
}

Even Better Trees

Other Fractal Curves

• The tree still doesn’t really look like a tree

• C-curve (dimension = 2!)

• To get a better looking picture, we should apply
randomness to the recursion
• Allow the length of branches to vary (between .4 and
.6 of the parent branch, say)
• Allow the angle of the branch to very (between 35
and 65 angles, say)
• Allow the join point of the branch to the parent to vary

Julia Sets

Julia Set for C = .3+.6i

• Each 2D point can be thought of as a complex
number (
)
• Repeatedly replace each point with
until the
point goes to infinity or comes to a “fixed point”
• Color the point based on how long it took the
magnitude of the point to become > 2

5
Julia Set for C = .2+.6i

Julia Set for C = .1+.6i

Mandelbrot Set

Assignment 4 Demo

• Almost like the Julia set, but use the original (x,y)
point instead of a constant c

6

Contenu connexe

Tendances

Line drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniquesLine drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniquesAnkit Garg
 
Bresenhamcircle derivation
Bresenhamcircle derivationBresenhamcircle derivation
Bresenhamcircle derivationMazharul Islam
 
[4] num integration
[4] num integration[4] num integration
[4] num integrationikhulsys
 
Computer Graphics Unit 1
Computer Graphics Unit 1Computer Graphics Unit 1
Computer Graphics Unit 1aravindangc
 
Lab lecture 1 line_algo
Lab lecture 1 line_algoLab lecture 1 line_algo
Lab lecture 1 line_algosimpleok
 
Lines and curves algorithms
Lines and curves algorithmsLines and curves algorithms
Lines and curves algorithmsMohammad Sadiq
 
Bresenham derivation
Bresenham derivationBresenham derivation
Bresenham derivationKumar
 
Comuter graphics bresenhams circle drawing algorithm
Comuter graphics bresenhams circle drawing algorithmComuter graphics bresenhams circle drawing algorithm
Comuter graphics bresenhams circle drawing algorithmRachana Marathe
 
Open GL T0074 56 sm1
Open GL T0074 56 sm1Open GL T0074 56 sm1
Open GL T0074 56 sm1Roziq Bahtiar
 
7.1 area between curves
7.1 area between curves7.1 area between curves
7.1 area between curvesdicosmo178
 
Open GL 04 linealgos
Open GL 04 linealgosOpen GL 04 linealgos
Open GL 04 linealgosRoziq Bahtiar
 
Matlab dc circuit analysis
Matlab dc circuit analysisMatlab dc circuit analysis
Matlab dc circuit analysisAmeen San
 
Intro to scan conversion
Intro to scan conversionIntro to scan conversion
Intro to scan conversionMohd Arif
 
Bresenham circles and polygons derication
Bresenham circles and polygons dericationBresenham circles and polygons derication
Bresenham circles and polygons dericationKumar
 
Computer Graphic - Lines, Circles and Ellipse
Computer Graphic - Lines, Circles and EllipseComputer Graphic - Lines, Circles and Ellipse
Computer Graphic - Lines, Circles and Ellipse2013901097
 

Tendances (20)

Line drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniquesLine drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniques
 
bresenham circles and polygons in computer graphics(Computer graphics tutorials)
bresenham circles and polygons in computer graphics(Computer graphics tutorials)bresenham circles and polygons in computer graphics(Computer graphics tutorials)
bresenham circles and polygons in computer graphics(Computer graphics tutorials)
 
Bresenhamcircle derivation
Bresenhamcircle derivationBresenhamcircle derivation
Bresenhamcircle derivation
 
[4] num integration
[4] num integration[4] num integration
[4] num integration
 
Computer Graphics Unit 1
Computer Graphics Unit 1Computer Graphics Unit 1
Computer Graphics Unit 1
 
Lab lecture 1 line_algo
Lab lecture 1 line_algoLab lecture 1 line_algo
Lab lecture 1 line_algo
 
Unit 3
Unit 3Unit 3
Unit 3
 
Lines and curves algorithms
Lines and curves algorithmsLines and curves algorithms
Lines and curves algorithms
 
Bresenham derivation
Bresenham derivationBresenham derivation
Bresenham derivation
 
Comuter graphics bresenhams circle drawing algorithm
Comuter graphics bresenhams circle drawing algorithmComuter graphics bresenhams circle drawing algorithm
Comuter graphics bresenhams circle drawing algorithm
 
Open GL T0074 56 sm1
Open GL T0074 56 sm1Open GL T0074 56 sm1
Open GL T0074 56 sm1
 
Computer graphics
Computer graphics   Computer graphics
Computer graphics
 
Cgm Lab Manual
Cgm Lab ManualCgm Lab Manual
Cgm Lab Manual
 
7.1 area between curves
7.1 area between curves7.1 area between curves
7.1 area between curves
 
Open GL 04 linealgos
Open GL 04 linealgosOpen GL 04 linealgos
Open GL 04 linealgos
 
Matlab dc circuit analysis
Matlab dc circuit analysisMatlab dc circuit analysis
Matlab dc circuit analysis
 
Intro to scan conversion
Intro to scan conversionIntro to scan conversion
Intro to scan conversion
 
Bresenham circles and polygons derication
Bresenham circles and polygons dericationBresenham circles and polygons derication
Bresenham circles and polygons derication
 
Cgm Lab Manual
Cgm Lab ManualCgm Lab Manual
Cgm Lab Manual
 
Computer Graphic - Lines, Circles and Ellipse
Computer Graphic - Lines, Circles and EllipseComputer Graphic - Lines, Circles and Ellipse
Computer Graphic - Lines, Circles and Ellipse
 

En vedette

Franceli infor-1225899477473159-9
Franceli infor-1225899477473159-9Franceli infor-1225899477473159-9
Franceli infor-1225899477473159-9luzenid
 
Invitados de honor
Invitados de honorInvitados de honor
Invitados de honormisalonsu
 
MATERIAL ESCOLAR CURSO 2014-2015
MATERIAL ESCOLAR CURSO 2014-2015MATERIAL ESCOLAR CURSO 2014-2015
MATERIAL ESCOLAR CURSO 2014-2015Ceipsancristobal
 
¿COMO DESARROLLAR EL ESPIRITU EMPRENDEDOR?
¿COMO DESARROLLAR EL ESPIRITU EMPRENDEDOR?¿COMO DESARROLLAR EL ESPIRITU EMPRENDEDOR?
¿COMO DESARROLLAR EL ESPIRITU EMPRENDEDOR?Valen Agudelo
 
09 april-2014 to-15-april-2014-hindu_sabhavarta_year38_issue2
09 april-2014 to-15-april-2014-hindu_sabhavarta_year38_issue209 april-2014 to-15-april-2014-hindu_sabhavarta_year38_issue2
09 april-2014 to-15-april-2014-hindu_sabhavarta_year38_issue2Akhil Bharat Mahasabha
 
02 july-2014 to-08-july-2014-hindu_sabhavarta_year38_issue14
02 july-2014 to-08-july-2014-hindu_sabhavarta_year38_issue1402 july-2014 to-08-july-2014-hindu_sabhavarta_year38_issue14
02 july-2014 to-08-july-2014-hindu_sabhavarta_year38_issue14Akhil Bharat Mahasabha
 
Introducing CVBS Victoria (2010)
Introducing CVBS Victoria (2010)Introducing CVBS Victoria (2010)
Introducing CVBS Victoria (2010)lisacvbs
 
Guia profesoradoeso
Guia profesoradoesoGuia profesoradoeso
Guia profesoradoesoAlicia Fdz
 
Presentación1
Presentación1Presentación1
Presentación1andrear27
 
Oferta educativa bachillerato
Oferta educativa bachilleratoOferta educativa bachillerato
Oferta educativa bachilleratoIES JULIO VERNE
 
1 a a la verdad
1 a a la verdad1 a a la verdad
1 a a la verdadmgmdec
 

En vedette (20)

Franceli infor-1225899477473159-9
Franceli infor-1225899477473159-9Franceli infor-1225899477473159-9
Franceli infor-1225899477473159-9
 
Invitados de honor
Invitados de honorInvitados de honor
Invitados de honor
 
MATERIAL ESCOLAR CURSO 2014-2015
MATERIAL ESCOLAR CURSO 2014-2015MATERIAL ESCOLAR CURSO 2014-2015
MATERIAL ESCOLAR CURSO 2014-2015
 
Acuerdo 717 cte sep
Acuerdo 717 cte sepAcuerdo 717 cte sep
Acuerdo 717 cte sep
 
¿COMO DESARROLLAR EL ESPIRITU EMPRENDEDOR?
¿COMO DESARROLLAR EL ESPIRITU EMPRENDEDOR?¿COMO DESARROLLAR EL ESPIRITU EMPRENDEDOR?
¿COMO DESARROLLAR EL ESPIRITU EMPRENDEDOR?
 
09 april-2014 to-15-april-2014-hindu_sabhavarta_year38_issue2
09 april-2014 to-15-april-2014-hindu_sabhavarta_year38_issue209 april-2014 to-15-april-2014-hindu_sabhavarta_year38_issue2
09 april-2014 to-15-april-2014-hindu_sabhavarta_year38_issue2
 
02 july-2014 to-08-july-2014-hindu_sabhavarta_year38_issue14
02 july-2014 to-08-july-2014-hindu_sabhavarta_year38_issue1402 july-2014 to-08-july-2014-hindu_sabhavarta_year38_issue14
02 july-2014 to-08-july-2014-hindu_sabhavarta_year38_issue14
 
Introducing CVBS Victoria (2010)
Introducing CVBS Victoria (2010)Introducing CVBS Victoria (2010)
Introducing CVBS Victoria (2010)
 
4 03 2002_edited
4 03 2002_edited4 03 2002_edited
4 03 2002_edited
 
Protocolos prehospitalarios
Protocolos prehospitalariosProtocolos prehospitalarios
Protocolos prehospitalarios
 
Guia profesoradoeso
Guia profesoradoesoGuia profesoradoeso
Guia profesoradoeso
 
Presentation1
Presentation1Presentation1
Presentation1
 
Moday 2
Moday 2Moday 2
Moday 2
 
Presentación1
Presentación1Presentación1
Presentación1
 
Laverdad
LaverdadLaverdad
Laverdad
 
Oferta educativa bachillerato
Oferta educativa bachilleratoOferta educativa bachillerato
Oferta educativa bachillerato
 
1 a a la verdad
1 a a la verdad1 a a la verdad
1 a a la verdad
 
Orar con jesus
Orar con jesusOrar con jesus
Orar con jesus
 
Getting started
Getting startedGetting started
Getting started
 
Rhetorical communication
Rhetorical communicationRhetorical communication
Rhetorical communication
 

Similaire à 10 linescan

Line drawing Algorithm DDA in computer Graphics.pdf
Line drawing Algorithm DDA in computer Graphics.pdfLine drawing Algorithm DDA in computer Graphics.pdf
Line drawing Algorithm DDA in computer Graphics.pdfRAJARATNAS
 
7.curves Further Mathematics Zimbabwe Zimsec Cambridge
7.curves   Further Mathematics Zimbabwe Zimsec Cambridge7.curves   Further Mathematics Zimbabwe Zimsec Cambridge
7.curves Further Mathematics Zimbabwe Zimsec Cambridgealproelearning
 
chapter 3 , foley.pptxhuujjjjjjjkjmmmm. Ibibhvucufucuvivihohi
chapter 3 , foley.pptxhuujjjjjjjkjmmmm.  Ibibhvucufucuvivihohichapter 3 , foley.pptxhuujjjjjjjkjmmmm.  Ibibhvucufucuvivihohi
chapter 3 , foley.pptxhuujjjjjjjkjmmmm. Ibibhvucufucuvivihohi54MahakBansal
 
An Algorithm to Find the Largest Circle inside a Polygon
An Algorithm to Find the Largest Circle inside a PolygonAn Algorithm to Find the Largest Circle inside a Polygon
An Algorithm to Find the Largest Circle inside a PolygonKasun Ranga Wijeweera
 
The Day You Finally Use Algebra: A 3D Math Primer
The Day You Finally Use Algebra: A 3D Math PrimerThe Day You Finally Use Algebra: A 3D Math Primer
The Day You Finally Use Algebra: A 3D Math PrimerJanie Clayton
 
Rasterisation of a circle by the bresenham algorithm
Rasterisation of a circle by the bresenham algorithmRasterisation of a circle by the bresenham algorithm
Rasterisation of a circle by the bresenham algorithmKALAIRANJANI21
 
Rasterisation of a circle by the bresenham algorithm
Rasterisation of a circle by the bresenham algorithmRasterisation of a circle by the bresenham algorithm
Rasterisation of a circle by the bresenham algorithmKALAIRANJANI21
 
Graphs of the Sine and Cosine Functions Lecture
Graphs of the Sine and Cosine Functions LectureGraphs of the Sine and Cosine Functions Lecture
Graphs of the Sine and Cosine Functions LectureFroyd Wess
 
Elliptical curve cryptography
Elliptical curve cryptographyElliptical curve cryptography
Elliptical curve cryptographyBarani Tharan
 
Chapter 3 - Part 1 [Autosaved].pptx
Chapter 3 - Part 1 [Autosaved].pptxChapter 3 - Part 1 [Autosaved].pptx
Chapter 3 - Part 1 [Autosaved].pptxKokebe2
 
Ch01 basic concepts_nosoluiton
Ch01 basic concepts_nosoluitonCh01 basic concepts_nosoluiton
Ch01 basic concepts_nosoluitonshin
 
Computer Aided Manufacturing Design
Computer Aided Manufacturing DesignComputer Aided Manufacturing Design
Computer Aided Manufacturing DesignV Tripathi
 
Rational Functions
Rational FunctionsRational Functions
Rational FunctionsJazz0614
 
07 cie552 image_mosaicing
07 cie552 image_mosaicing07 cie552 image_mosaicing
07 cie552 image_mosaicingElsayed Hemayed
 
3D Math Without Presenter Notes
3D Math Without Presenter Notes3D Math Without Presenter Notes
3D Math Without Presenter NotesJanie Clayton
 

Similaire à 10 linescan (20)

raster algorithm.pdf
raster algorithm.pdfraster algorithm.pdf
raster algorithm.pdf
 
Line drawing Algorithm DDA in computer Graphics.pdf
Line drawing Algorithm DDA in computer Graphics.pdfLine drawing Algorithm DDA in computer Graphics.pdf
Line drawing Algorithm DDA in computer Graphics.pdf
 
7.curves Further Mathematics Zimbabwe Zimsec Cambridge
7.curves   Further Mathematics Zimbabwe Zimsec Cambridge7.curves   Further Mathematics Zimbabwe Zimsec Cambridge
7.curves Further Mathematics Zimbabwe Zimsec Cambridge
 
chapter 3 , foley.pptxhuujjjjjjjkjmmmm. Ibibhvucufucuvivihohi
chapter 3 , foley.pptxhuujjjjjjjkjmmmm.  Ibibhvucufucuvivihohichapter 3 , foley.pptxhuujjjjjjjkjmmmm.  Ibibhvucufucuvivihohi
chapter 3 , foley.pptxhuujjjjjjjkjmmmm. Ibibhvucufucuvivihohi
 
An Algorithm to Find the Largest Circle inside a Polygon
An Algorithm to Find the Largest Circle inside a PolygonAn Algorithm to Find the Largest Circle inside a Polygon
An Algorithm to Find the Largest Circle inside a Polygon
 
The Day You Finally Use Algebra: A 3D Math Primer
The Day You Finally Use Algebra: A 3D Math PrimerThe Day You Finally Use Algebra: A 3D Math Primer
The Day You Finally Use Algebra: A 3D Math Primer
 
Rasterisation of a circle by the bresenham algorithm
Rasterisation of a circle by the bresenham algorithmRasterisation of a circle by the bresenham algorithm
Rasterisation of a circle by the bresenham algorithm
 
Rasterisation of a circle by the bresenham algorithm
Rasterisation of a circle by the bresenham algorithmRasterisation of a circle by the bresenham algorithm
Rasterisation of a circle by the bresenham algorithm
 
Matlab file
Matlab file Matlab file
Matlab file
 
Graphs of the Sine and Cosine Functions Lecture
Graphs of the Sine and Cosine Functions LectureGraphs of the Sine and Cosine Functions Lecture
Graphs of the Sine and Cosine Functions Lecture
 
Elliptical curve cryptography
Elliptical curve cryptographyElliptical curve cryptography
Elliptical curve cryptography
 
ECC_basics.ppt
ECC_basics.pptECC_basics.ppt
ECC_basics.ppt
 
Chapter 3 - Part 1 [Autosaved].pptx
Chapter 3 - Part 1 [Autosaved].pptxChapter 3 - Part 1 [Autosaved].pptx
Chapter 3 - Part 1 [Autosaved].pptx
 
Ch01 basic concepts_nosoluiton
Ch01 basic concepts_nosoluitonCh01 basic concepts_nosoluiton
Ch01 basic concepts_nosoluiton
 
Computer Aided Manufacturing Design
Computer Aided Manufacturing DesignComputer Aided Manufacturing Design
Computer Aided Manufacturing Design
 
ECC_basics.ppt
ECC_basics.pptECC_basics.ppt
ECC_basics.ppt
 
Rational Functions
Rational FunctionsRational Functions
Rational Functions
 
07 cie552 image_mosaicing
07 cie552 image_mosaicing07 cie552 image_mosaicing
07 cie552 image_mosaicing
 
3D Math Without Presenter Notes
3D Math Without Presenter Notes3D Math Without Presenter Notes
3D Math Without Presenter Notes
 
Bresenham circle
Bresenham circleBresenham circle
Bresenham circle
 

Plus de Praveen Kumar (20)

Summer2014 internship
Summer2014 internshipSummer2014 internship
Summer2014 internship
 
Summer+training 2
Summer+training 2Summer+training 2
Summer+training 2
 
Summer+training
Summer+trainingSummer+training
Summer+training
 
Solutions1.1
Solutions1.1Solutions1.1
Solutions1.1
 
Slides15
Slides15Slides15
Slides15
 
Scribed lec8
Scribed lec8Scribed lec8
Scribed lec8
 
Scholarship sc st
Scholarship sc stScholarship sc st
Scholarship sc st
 
Networks 2
Networks 2Networks 2
Networks 2
 
Mithfh lecturenotes 9
Mithfh lecturenotes 9Mithfh lecturenotes 9
Mithfh lecturenotes 9
 
Mcs student
Mcs studentMcs student
Mcs student
 
Math350 hw2solutions
Math350 hw2solutionsMath350 hw2solutions
Math350 hw2solutions
 
Matching
MatchingMatching
Matching
 
Line circle draw
Line circle drawLine circle draw
Line circle draw
 
Lecture3
Lecture3Lecture3
Lecture3
 
Lec2 state space
Lec2 state spaceLec2 state space
Lec2 state space
 
Graphtheory
GraphtheoryGraphtheory
Graphtheory
 
Graphics display-devicesmod-1
Graphics display-devicesmod-1Graphics display-devicesmod-1
Graphics display-devicesmod-1
 
Games.4
Games.4Games.4
Games.4
 
Dda line-algorithm
Dda line-algorithmDda line-algorithm
Dda line-algorithm
 
Cs344 lect15-robotic-knowledge-inferencing-prolog-11feb08
Cs344 lect15-robotic-knowledge-inferencing-prolog-11feb08Cs344 lect15-robotic-knowledge-inferencing-prolog-11feb08
Cs344 lect15-robotic-knowledge-inferencing-prolog-11feb08
 

Dernier

USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptshraddhaparab530
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfVanessa Camilleri
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
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
 

Dernier (20)

USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.ppt
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
ICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdfICS2208 Lecture6 Notes for SL spaces.pdf
ICS2208 Lecture6 Notes for SL spaces.pdf
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
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
 

10 linescan

  • 1. Drawing • Most computer generated images made up of geometric primitives (polygons, lines, points) Scan Conversion 1: Lines, Circles and Fractals Greg Humphreys • Application draws them by setting bits in the framebuffer • Most graphics applications involve scene database management CS445: Intro Graphics University of Virginia, Fall 2003 A DDA Line Drawing Function Line(int x1, int y1, int x2, int y2) { int dx = x1 - x2, dy = y2 - y1; Scene Database Graphics Application Device Driver Framebuffer Display We Can Do Better Than That... • Get rid of all those nasty floating point operations • The idea: find the next pixel from the current one int n = max(abs(dx),abs(dy)); float dt = n, dxdt = dx/dt, dydt = dy/dt; float x = x1, y = y1; while (n--) { DrawPoint( round(x), round(y) ); x += dxdt; y += dydt; • So which of the green pixels is next? } } What’s bad about this? The Key The Midpoint Test • We’re only ever going to go right one pixel, or up and right one pixel (if the slope of the line is between 0 and 1). Call these two choices “E” and “NE” • Look at the vertical grid line that our line intersects • Let’s think of pixels as “lattice points” on a grid • On which side of the midpoint (y+1/2) does the intersection lie? • If it’s above the midpoint, go NE, otherwise go E • Given an X coordinate, we only need to choose between y and y+1 (y is the Y coordinate of the last pixel) 1
  • 2. Our Example Implicit Functions • Normally, a line is defined as y+3 • Instead, define be everywhere where y+2 • Now, if , and let the line , we’re “above” the line, and if , we’re “below” the line y+1 y x x+1 x+2 x+3 x+4 x+5 x+6 x+7 Who Cares? Midpoint Algorithm • We can evaluate the implicit line function at the midpoint to figure out where to draw next! Line(int x1, int y1, int x2, int y2) { int dx = x2 - x1, dy = y2 - y1; • In fact, we can use the last function evaluation to find the next one cheaply! • For ANY int e = 2*dy - dx; int incrE = 2*dy, incrNE = 2*(dy-dx); int x = x1, y = y1; : DrawPoint( x, y ); while (x < x2) { x++; if ( e <= 0 ) { e += incrE; } else { y++; e += incrNE; } DrawPoint( x, y ); } • “e” holds the implicit function evaluation at each x value (actually, it’s multiplied by 2, but all we care about is the sign). • Easy extension for lines with arbitrary slopes. } Midpoint Algorithm for Circles More Midpoint Circle Drawing • Only consider the second octant (the others are symmetric anyhow) • The circle’s implicit function (r is the radius): • Midpoint test still works: do we go right, or right and down? • Once we know the value of the implicit function at one midpoint, we can get the value at the next midpoint by the same differencing technique: E  If we’re going E: SE  If we’re going SE: 2
  • 3. Drawing the 2nd Octant Final Circle Drawer void Circle( int cx, int cy, int radius ) { int x = 0, y = radius, e = 1-radius; DrawPoint( x + cx, y + cy ); • Look at all those expensive multiplies! Can we get rid of them too? while (y > x) { if (e < 0) // Go “east” { e += 2*x + 3; } else // Go “south-east” { e += 2*(x-y) + 5; y--; } x++; DrawPoint( x + cx, y + cy ); } void Circle( int { int x = 0, y = int incrE = 3, DrawPoint( x + radius, e = 1-radius; incrSE = -2*radius + 5 cx, y + cy ); while (y > x) { if (e < 0) // Go “east” { e += incrE; incrE += 2; incrSE += 2; } else // Go “south-east” { e += incrSE; incrE += 2; incrSE += 4; y--; } x++; DrawPoint( x + cx, y + cy ); } • How about doing finite differencing on the “e” variable itself?  If we go E:  If we go SE: } cx, int cy, int radius ) This looks pretty fast! } Flood Fill Simple 4-connected Fill • The idea: fill a “connected region” with a solid color • The simplest algorithm to fill a 4-connected region is a recursive one: • Term definitions: 8 4 8 4 1 4 8 4 8 • The center “1” pixel is 4-connected to the pixels marked “4”, and 8-connected to the pixels marked “8” FloodFill( int x, int y, int inside_color, int new_color ) { if (GetColor( x, y ) == inside_color) { SetColor( x, y, new_color ); FloodFill( x+1, y , inside_color, new_color ); FloodFill( x-1, y , inside_color, new_color ); FloodFill( x, y+1, inside_color, new_color ); FloodFill( x, y-1, inside_color, new_color ); } } A Span-based Algorithm Fractals • Definition: a run is a horizontal span of identically colored pixels • Fractal: any curve or shape exhibiting self-similarity at any scale h b c s a d e f g i Start at pixel “s”, the seed. Find the run containing “s” (“b” to “a”). Fill that run with the new color. Then search every pixel above that run, looking for other pixels of the interior color. For each one found, find the right side of that run (“c”), and push that on a stack. Do the same for the pixels below (“d”). Then pop the stack and repeat the procedure with the new seed. The algorithm finds runs ending at “e”, “f”, “g”, “h”, and “i” • Fractals appear in nature all the time • Part of the general science of chaos 3
  • 4. The Koch Curve Properties of the Koch Curve • Start with a line • It occupies a finite area in the plane • Replace the line with four lines, and repeat: • It has infinite length • It is self-similar • It has a dimension of • It’s easier to draw in polar coordinates (hint, hint…) Non-Integral Dimension??? Self Similar Curves in Nature • Let’s look at other “self-similar” shapes: • How long is a coastline? Shape  Measure on a map  Walk around big boulders  Measure each grain of sand #Parts Scale Dimension 2 2 1 • Cellular structure of leaves 4 2 2 • Blood vessel structure 8 2 3 4 3 ? • Ethernet packet traffic (okay, that’s not really Nature) Drawing Fractal Trees Fractal Trees #define ANGLE 45 void tree (float X1, float Y1, float R, float Theta, int Level) { float SX, SY, EX, EY; if (Level > { EX = EY = line SX = SY = tree tree 0) X1 + (R * cos(Theta)); Y1 + (R * sin(Theta)); (X1, Y1, EX, EY); X1 + Y1 + (SX, (SX, ((R ((R SY, SY, * 0.5) * 0.5) R*0.8, R*0.8, * cos(Theta)); * sin(Theta)); Theta-ANGLE, Level-1); Theta+ANGLE, Level-1); } } 4
  • 5. Better Fractal Trees #define RT_ANGLE #define LFT_ANGLE Non Symmetric Tree 45 65 void non_sym_tree (float X1, float Y1, float R, float Theta, int Level) { float SX, SY, EX, EY; if (Level > 0) { EX = X1 + (R * cos(Theta)); EY = Y1 + (R * sin(Theta)); line (X1, Y1, EX, EY); SX = X1 + ((R * 0.4) * cos(Theta)); SY = Y1 + ((R * 0.4) * sin(Theta)); non_sym_tree (SX, SY, R*0.8, Theta-RT_ANGLE, Level-1); SX = X1 + ((R * 0.6) * cos(Theta)); SY = Y1 + ((R * 0.6) * sin(Theta)); non_sym_tree (SX, SY, R*0.8, Theta+LFT_ANGLE, Level-1); } } Even Better Trees Other Fractal Curves • The tree still doesn’t really look like a tree • C-curve (dimension = 2!) • To get a better looking picture, we should apply randomness to the recursion • Allow the length of branches to vary (between .4 and .6 of the parent branch, say) • Allow the angle of the branch to very (between 35 and 65 angles, say) • Allow the join point of the branch to the parent to vary Julia Sets Julia Set for C = .3+.6i • Each 2D point can be thought of as a complex number ( ) • Repeatedly replace each point with until the point goes to infinity or comes to a “fixed point” • Color the point based on how long it took the magnitude of the point to become > 2 5
  • 6. Julia Set for C = .2+.6i Julia Set for C = .1+.6i Mandelbrot Set Assignment 4 Demo • Almost like the Julia set, but use the original (x,y) point instead of a constant c 6