Sei sulla pagina 1di 40

Vector Graphics

Rawesak Tanawongsuwan
ccrtw@mahidol.ac.th
4 86

Vector Graphics
• Compact

• Scalable


http://www.prepressure.com/image/bitmapvector.htm
Resolution-independent

• Hence attractive for networked multimedia,


but not widely used on WWW

• SVG standard and Flash may lead to more


vector Web graphics
4 87

Coordinates
• Rectangular array of pixels, each pixel may be
identified by row and column numbers (r,c)

• Extend to Cartesian coordinates

• Any point in the plane can be identified by


its horizontal and vertical distance from the
origin

• P = (x, y) (3,4)
4 88

Vectors
• Specify a displacement by movements in x
and y directions

• Displacement is also a pair of numbers

• P2 - P1 = (x2-x1, y2-y1), displacement


(movement) from P1 to P2
P2
• P2 - P1 ≠ P1 - P2
P2 − P1
y2 − y1

P1
x2 − x1
4 88–89

Rendering
• Represent lines, curves, shapes,... by parameters of their
defining equations
• e.g. line y = mx + c, store m and c (or endpoints)

• Compute pixels which must be set in order to draw the line etc

• In general, result will exhibit 'jaggies'


• Pixels' coordinates are integers, equations use real numbers
4

Aliasing

http://en.wikipedia.org/wiki/Aliasing
4 89–91

Anti-aliasing
• Rendering is sampling & reconstruction

• Abstract continuous line &c must be


approximated by discrete pixels of
finite size

• Jaggies are instance of phenomenon of


http://www.its2.uidaho.edu/photoshop/intro/anti-aliasing.htm aliasing

• Mitigate effect by colouring pixels in


shades of grey (for a black line),
brightness varies according to extent
of intersection with an idealized 1 pixel
wide line

http://www.richleader.com/images/Pulse/bargainbin/bargain_bin_review/anti-aliasing.png
4

Anti-aliasing

http://en.wikipedia.org/wiki/Anti-aliasing
4 91–92

Shapes
• Drawing programs and vector graphics
languages provide basic repertoire of shapes
that can easily be represented mathematically

• Rectangles and squares (may have rounded


corners)

• Ellipses and circles

• Straight lines, polylines and polygons

• Smooth (Bézier) curves


4

Spline representations

• A piecewise polynomial function that can have a


locally very simple form, yet at the same time be
globally flexible and smooth.

• Splines are very useful for modeling arbitrary


functions, and are used extensively in computer
graphics.
From http://mathworld.wolfram.com/Spline.html
4

Spline usage
• Design curve and surface shapes

• Digitize drawings

• Specify animation paths for the objects or the


camera position in a scene

• CAD applications
4

Interpolation and Approximation


Splines
• A spline curve is specified by a
set of coordinate positions called
control points

• A curve is said to interpolate the


set of control points if all the
control points are connected

• A curve is said to approximate


the set of control points if some
or all of the control points are not
on the curve path
4

Bézier spline curves


• Bézier spline is a spline approximation method
• Have many properties that are useful for curve and
surface design
• A Bézier curve section can be fitted to any number
of control points (but in general we consider four
points or cubic)
• The degree of the Bézier polynomial is determined
by the number of control points to be approximated
and their relative position
4

Bézier spline curves


• A Bézier curve is a polynomial of degree n-1

• 3 points  parabola

• 4 points  cubic
4

Properties of Bézier curves

• The curve connects the first and last control points

• The slope at the beginning of the curve is along the


line joining the first two control points

• The slope at the end of the curve is along the line


joining the last two control points
4 92–94

Bézier Curves

• Smooth curves
completely specified
by four control points
• 2 endpoints (P1, P4)
• 2 direction points
(P2, P3)

• Sweep of the curve is


determined by length
and direction of lines
from endpoints to
direction points
4 94–96

Paths
• Bézier curves can be easily combined to make
elaborate smooth paths
• Closed path joins up on itself, open path
doesn't
4

Join paths
• If two curves join at a point in such a way that their
direction lines through that point form a single line
extending the same distance in both directions, the
join will be smooth
• Pen tool in drawing programs lets you build up
curves in this way by dragging at successive
anchor points
4 96–99

Stroke & Fill


• Apply stroke to make path visible
(like tracing with ink)

• Specify width and colour etc

• Apply fill to closed path or shape


(like colouring it in)

• Specify colour or a gradient or


pattern

• Gradients may be linear or


radial; Illustrator also supports
mesh gradients
4

Pattern fills
• Allow a repeating pattern to fill in an area. Patterns are
built out of elements called tiles (small piece of image)

• Constructing tiles that join seamlessly requires a certain


amount of skill
4

Inside or Outside

• Fill an area  which areas are inside the


shape or outside
4

Nonzero winding-number rule


• Counts the number of times the boundary of an object winds
around the point P in a counterclockwise direction

• Add 1 when we intersect an edge comes from right to left

• Subtract 1 when we intersect an edge comes from left to right

• If the result is nonzero, P is considered to be an interior point

• Otherwise, P is an exterior point


4 101–102

Transformations
• Manipulate vector objects in certain ways by
changing stored values that describe them
• Translation (linear movement)
• Scaling
• Reflection
• Rotation
• Shearing (skewing)

• Perform transformations with direct


manipulation (tools) or numerically (dialogue)
4

Transformations
4

Transformations
translate
rotate

shear
scale

reflect
4

Filtering
4

Sample images
(done by Illustrator)

http://northlite.50megs.com/illus/illusgallery/IllustratorGallery/
4

Larger version
4 103–104

3-D Vector Graphics


Y • Conceptually simple extension of 2-D

v • Add z-axis at right angles to x- and y-axes

• Point is defined by (x, y, z) coordinates,


X vector is triple of values, etc

Y
• Practically complicated and difficult

• Requires 3-D visualization skills

• Complex tools are hard to master

X • Considerable processing power is needed


Z
4 105

3-D Rendering
• Start with mathematical model of objects in 3-
D space, need a 2-D picture, usually in
perspective

• Need to define viewpoint (camera position)

• Must consider lighting


• Can have different light sources – spots,
diffuse, ...
• Surface characteristics of object (texture,
shininess, etc) determine how it appears
under different lighting conditions
• Need a model based on physics of light
4

Winner of
POVCOMP 2004

'The Last Guardian'

by Johnny Yip

http://www.povcomp.com/results.php
4
"The Kitchen"
by Jaime Vives Piqueres - ranked 2nd

http://www.povcomp.com/results.php
4
"Dissolution" by NEWT - ranked 3rd

http://www.povcomp.com/results.php
4 106

Constructive Solid Geometry


• Build 3-D models out of a few primitive objects – cube,
cylinder, sphere, pyramid,...

• Apply distortions such as squashing or stretching

• Combine objects using spatial equivalents of set operations

• Union, intersection, difference

Mechanical bodies were made with CSG


4 106–108

Free Form Modelling


• Use object's boundary surface to define it

• cf. use of outline to define 2-D shape

• Construct surface as mesh of flat polygons


http://www.highend3d.com/maya/

• Use triangles for fast rendering (games) tutorials/peter/model2.3d

• Can generalize Bézier curves to 3-D surfaces

• Generate objects by sweeping 2-D cross


section along a path http://eric.boissard.free.fr/projects.html

• Extrusion and lathing

http://www.flashdevils.com/reviews.php?id=1345&Swift%203D%20v3.html
4 108–111

Procedural Modelling
• Define an object by giving algorithm for constructing it

• Fractals
• Exhibit same structure at all levels of detail
• Model landscape features, clouds etc

• Particle systems

http://astronomy.swin.edu.au/~pbourke/fractals/fracintro/

http://www.darwin3d.com/gamedev/gdm0798.jpg

https://www.internal.pandromeda.com/engineering/
musgrave/unsecure/S01_Course_Notes.html
4 111–112

3-D Rendering
• Wire frame

• Simple mathematical projection


of 3-D model

• Useful for previews

• Hidden surface removal

• Non-trivial, but well understood

• Can colour surfaces arbitrarily,


sufficient for removing visual http://images.pennnet.com/articles/cgw/cap/cap_72723.jpg

ambiguity of wire frame


4 113–114

Shading Algorithms
• Interpolate colour across each polygon to disguise discontinuities

• Gouraud and Phong shading

• Phong shading takes account of specular reflection


4

Shading Algorithms
• Take account of interaction between objects

• Ray tracing and radiosity


4

Let’s wait for CG class!

Potrebbero piacerti anche