0% found this document useful (0 votes)
26 views65 pages

cs405 03 Representation

Uploaded by

Ceren Haydaroglu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views65 pages

cs405 03 Representation

Uploaded by

Ceren Haydaroglu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 65

Representation

Tools for Graphics

• Vector Analysis

• Transformations
Vector Basics

• |b|= √b1^2+b2^2+bn^2 magnitute of b


• Dot product: v (v1....vN), w (w1,....wN)
­ V.W is the dot product
­ d = v.w = ∑viwi for i=1 to N
• |b||b|= b.b
• The angle between two vectors
­ b.c = |b|. |c| cos()
• Vectors b and c are perpendicular if b.c=0
Example
• V=2v1+3v2-4v3
• A=[2 3 –4]
• W= a1V1+a2V2+a3V3....

• Affine combination: A linear combination is an affine combination


when the coefficients a1, a2,... add up to 1

• Convex combination: each coefficient of the linear combination sum


to one and each one must be nonnegative.

• Note that this representation is with respect to a particular basis


• For example, in OpenGL we start by representing vectors using the
world basis but later the system needs a representation in terms of
the camera or eye basis
Representation
• Until now we have been able to work with geometric
entities without using any frame of reference, such a
coordinate system

• Need a frame of reference to relate points and objects


to our physical world.
­ For example, where is a point?
• Can’t answer without a reference system
­ World coordinates
­ Camera coordinates
Coordinate Systems
• Consider a basis v1, v2,…., vn
• A vector is written v=1v1+ 2v2 +….+nvn
• The list of scalars {1, 2, …. n}is the representation
of v with respect to the given basis
• We can write the representation as a row or column
array of scalars

a=[1 2 …. n]T=
Coordinate Systems
• Which is correct?

v
v

• Both are because vectors have no fixed location


Frames
• Coordinate System is insufficient to present points
• If we work in an affine space we can add a single
point, the origin, to the basis vectors to form a frame

v2
v1
P0
v3
• Frame determined by (P0, v1, v2, v3)
• Within this frame, every vector can be written as
v=1v1+ 2v2 +….+nvn
• Every point can be written as
P = P0 + 1v1+ 2v2 +….+nvn
Confusing Points and Vectors
Consider the point and the vector
P = P0 + 1v1+ 2v2 +….+nvn
v=1v1+ 2v2 +….+nvn
They appear to have the similar representations
p=[1 2 3] v=[1 2 3] v
which confuse the point with the vector p
A vector has no position v

can place anywhere


fixed
A Single Representation
If we define 0 • P = 0 and 1 • P = P then we can write
v=1v1+ 2v2 +3v3 = [1 2 3 0 ] [v1 v2 v3 P0] T

P = P0 + 1v1+ 2v2 +3v3= [1 2 3 1 ] [v1 v2 v3 P0] T

Thus we obtain the four-dimensional homogeneous


coordinate representation
v = [1 2 3 0 ] T
p = [1 2 3 1 ] T
Homogeneous Coordinates
The general form of four dimensional homogeneous
coordinates is
p=[x y x w] T
We return to a three dimensional point (for w0) by
xx/w
yy/w
zz/w
If w=0, the representation is that of a vector
Note that homogeneous coordinates replaces points in
three dimensions by lines through the origin in four
dimensions
Homogeneous Coordinates
and Computer Graphics
• Homogeneous coordinates are key to all computer
graphics systems
OpenGL uses 4D homogeneous coordinates for all its
vertices.

If you send it a triple of the form (x,y,z), it converts it


immediately to (x,y,z,1).
If you send it a 2D point (x,y), it first appends a 0 for the z
component and then a 1, to form (x,y,0,1).
Homogeneous Coordinates
and Computer Graphics
• Homogeneous coordinates are key to all computer
graphics systems
­ All standard transformations (rotation, translation,
scaling) can be implemented by matrix multiplications
with 4 x 4 matrices
­ Hardware pipeline works with 4 dimensional
representations
­ For orthographic viewing, we can maintain w=0 for
vectors and w=1 for points
­ For perspective we need a perspective division
• The difference of two points (x,y,z,1) and (u,v,w,1) is
(x-u, y-v, z-w, 0), which is a vector

• The sum of a point (x, y, z, 1) and a vector (d, e, f, 0)


is (x + d, y + e, z + f, 1), another point
Affine combination of points
Consider forming a linear combination of two points, P = (P1, P2, P3, 1)
and R = (R1, R2, R3, 1), using the scalars f and g:

fP + gR = (fP1 + gR1, fP2 + gR2, fP3 + gR3, f + g)

This is a valid vector if f + g = 0


It is not a valid point, unless f + g = 1

The only linear combination of points that is valid is an affine


combination.
P1 + P2 depends on the choice of coordinate system.

The affine combination 0.5 (P1 + P2) does not depend on this choice.
A point plus a vector is an affine combination of points

P = A + t (B - A)

P = t B + (1 – t) A !!!!!!!!!Why?
The Centroid of a triangle

Show that the three medians of T meet at a point that lies 2/3 of the
way along each median.
G = (E + F) / 2
The point that is two-thirds of the way from D to G is
D + (2/3)(G – D)

= (D + E + F) /3
Linear Interpolation of Two Points

The affine combination of points


P = A (1 – t) + B t

performs a linear interpolation between the points A and B.


lerp(a,b,t) provides a number that is the fraction t of the way from
a to b.
a+ (b-a)*t;

tween (A,B,t) computes the point P(t) that is the fraction t of the way
Along the straight line from point A to point B.
Tweening

P = (1 – t) Ai + t Bi

This polyline begins with the shape of A and ends with the shape of B,
but in between it is a blend of the two shapes.
Keyframe Animation
Quadratic and Cubic Tweening
1 = ((1-t) + t) 2

P = (1 – t)2 A + 2t (1 – t) B + t2 C

This is the Bezier curve for the points A, B, and C.

1 = ((1-t) + t) 3
Representing Lines and Planes
Lines
Parametric Representation
• Consider all points of the form
­ P()=P0 +  d
­ Set of all points that pass through P0 in the direction of
the vector d

for the segment, 0 ≤  ≤ 1;


for the ray, 0 ≤  < ∞;
for the line, -∞ <  < ∞;
• This form is known as the parametric form of the line

­ More robust and general than other forms

­ Extends to curves and surfaces


Rays and Line Segments
• If  ≥ 0, then P() is the ray leaving P0 in the direction d
If we use two points to define v, then
P( ) = Q +  (R-Q)=Q+v
=R + (1-)Q

For 0 ≤ ≤ 1 we get all the


points on the line segment
joining R and Q
Point normal form for the
Equation of a Line (Implicit form)
f x + g y = 1 (2D)
(f, g) . (x, y) = 1 (What is this ?)

Every point (x,y) that satisfies this equation lies on the


line so the equation provides a condition for a point
to be on the line.

(This form is very useful in such tasks as clipping, eliminating hidden


lines, and tracing rays.)
Point normal form (Implicit form)

The line passes through the points C and B. What is the point normal
form of L?

n . (R-C) = 0
For any R(x,y).
A certain dot product must turn out to be zero for
every point R on the line.
Example: L passes through C=(3,4) and B=(5,-2)

Find the point normal form of L.


Find the parametric form of L.
Planes
• A plane can be determined by a point and two vectors
or by three points

P(,)=R+u+v P(,)=R+(Q-R)+(P-Q)
The line segment that joins A and C is the set of points of the form

S () = C + (1-)A 0≤≤1


Suppose that we take an arbitrary point on this line segment and form
the line segment from this point to B
T () = S + (1-)B 0≤≤1

Such points are determined by both  and , and form the plane
determined by A,B, and C.
T () =C + (1-)A] + (1-)B
T () = C + A – C) + (1-)(B-C)
T () = C + A – C) + (1-)(B-C)

Noting that A-C and B-C are arbitrary vectors, a plane can be
determined as:

T (s,t) = C + su + tv

We can rearrange terms to obtain the affine combination of points:

T (s,t) = sA + tB + (1-s-t)C

In mathematics, an affine combination of


vectors x1, ..., xn is a linear combination in
which the sum of the coefficients is 1
Example: Plane passing through A=(3,3,3), B=(5,5,7) and C=(1,2,4)

Find the parametric form of the plane.

Find the point normal form of the plane.


The point normal form for a plane

A plane is completely specified by giving a single point B that lies


within it and the direction n of the normal to the plane.

n . (R – B) = 0
Example: Plane passing through A=(1,2,3) with normal vector
N=(2, -1, -2)

Write the Point Normal Form


Example: Find a parametric form for the plane 2x – y + 3z = 8
Normal n (2,-1,3)
A point on the plane C (4,0,0)
Two vectors on the plane:
Condition n.a=0
a(1,5,1) b(0,3,1)
Parametric form
P(s,t) = (4,0,0) + (1,5,1)s + (0,3,1)t
Given the normal n to a plane, can you find two points on the plane.
Planar patches

To each point (s,t) in parameter space, one 3D


point in the patch corrresponds P(s,t) = C +as + bt.
P(0,0) = C P(0,1) = C + b
P(1,0) = C + a P(1,1) = C + a + b
Example: Let C = (1,3,2), a = (1,1,0), b = (1,4,2)

Find the corners of the planar patch.


Example: Find the values of a, b and C that create a square patch of
length 4 on a side, centered at the origin and parallel to the x,z-plane.
Finding the Intersection of two line segments

AB (t) = A + bt b=B-A
CD (u) = C + du d=D-C

A + bt = C + du
bt = c + du c=C-A

d┴. bt = d┴. c

If d┴. b is not zero:

Two parent lines intersect


Similarly,
Example: Given the endpoints A = (0,6), B = (6,1), C = (1,3), and
D = (5,5), find the intersection of the lines AB and CD if it exists.
The Circle Through 3 points

The center S of the desired circle must be equidistant from all three
vertices, so it must lie on the perpendicular bisector of each side of
triangle ABC.
Intersection of lines with planes; clipping

n . (P – B) = 0

n . (A + cthit – B) = 0

n . (A – B) + (n . cthit) = 0
if n . c > 0 the ray is aimed “along with” the normal

if n . c = 0 the ray is parallel to the line

if n . c < 0 the ray is aimed “counter to” the normal


Polygons are fundamental objects that are used in 2D and 3D graphics.

In 3D, an object is often modeled as a polygonal “mesh”; a collection


of polygons.

If the skin forms a closed surface that encloses some space, the mesh
is called a polyhedron.
Polygon Intersection Problems

Is a given point P inside or outside the object?

Where does a given ray R first intersect the object?

Which part of a given line L lies inside the object, and which part
lies outside
Convex Polygons and Polyhedra

Convex polygon is completely described by a set of “bounding lines”

In 3D, a convex polyhedron is completely described by a set of


“bounding planes”
Finding the bounding lines

(-1, 0) . (P – (0,0) = 0
(0, -1) . (P – (0,0) = 0
(1, 1) . (P – (1,0) = 0
Note that in each case the outward normal is used
Ray Intersections and Clipping for convex polygons

Since P is convex, the ray hits P exactly twice.


Entering hit point = A + c tin
Exiting hit point = A + c tout
The ray is inside P for all t in the interval [tin, tout]
The Clipping problem

To find the clipped segment, compute tin and tout


A’ = A + c max(0,tin)
C’ = A + c min(1,tout)
How are tin and tout computed?

Consider each of the bounding lines of P in turn and find where the
ray A + ct intersects that line.
Assume that each bounding line of P is stored in point normal form as the
pair {B, n}
If n . c > 0 the ray is exiting from P
If n . c = 0 the ray is parallel to the line
If n . c < 0 the ray is entering P
[tin , tout ] is the candidate interval of t, the interval inside of which
the ray might lie inside the object.
• Initialize the candidate interval to [0,1]

• For each bounding line, find the hit time thit and determine whether
it is an entering or exiting hit
• If entering hit, set tin = max (tin, thit)
• If exiting hit, set tout = min (tout, thit)

• If the candidate interval is not empty, then, the segment from A + c


tin to A + c tout lies inside P. (For clipping, the endpoints of the clipped
line, for ray tracing, entering and exiting points of the ray)
• Stop if the candidate interval vanishes
The Cyrus-Beck clipping algorithm
(Clipping of a line segment against any convex polygon)
Clipping against arbitrary polygons

Find where the ray A + ct lies inside the polygon P given the list
of vertices P0, P1, ..., PN-1
The ray can enter and exit from P multiple times and the result of
clipping a segment against P may result in a list of segments rather
than a single one.

P is no longer described by a collection of infinite bounding lines in


point normal form; we must work with the N finite segments such as
P3P4 that form its edges.
Represent each edge of P parametrically.
The ith edge is given by Pi + eiu, for u in [0,1] ei = Pi+1 – Pi PN = P0
The ray A + ct hits the ith edge when t and u have the proper values to
Make A + ct = Pi + eiu

ct = bi + eiu

If is zero, the ith edge is parallel to the direction of c and there


is no intersection.
Example:

Edge u t
0 0.3846 0.2308
1 -0.727 -0.2727
2 0.9048 0.7142
3 0.4 0.6
4 0.375 0.375

You might also like