vectors computer graphics. a review of vectors: scalar quantity vector quantity 2d vectors ...

Post on 19-Dec-2015

286 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

VECTORSComputer Graphics

A REVIEW OF VECTORS:

Scalar Quantity Vector Quantity 2D vectors Graphical Representation of Vectors Magnitude of a vector Direction of a Vector

3D VECTORS

A vector in 3D have three

Components along x, y and

Z axis. Its magnitude and

Direction can be measured

Using Pythagorean theorem

For 3D.

3D VECTORS

Calculation of magnitude

of a vector.

VECTOR MANIPULATION

As vectors are different to scalars, there are rules to control how the two mathematical entities interact with one another.

We need to consider vector addition, subtraction and products, and how a vector is scaled.

SCALING A VECTOR Given a vector n, 2n means that the vector’s

components are scaled by a factor of 2. For example,

Similarly, if we divide

Vector n by 2 then all of

Its components have halved

VECTOR ADDITION AND SUBTRACTION

For vectors r and s, the

Addition and subtraction of

Is done as;

a+b= b+a

a-b ≠ b-a

VECTOR ADDITION AND SUBTRACTIONThe tail of vector s is attached to the head of vector r. The resultant vector t = r + s is defined by adding the corresponding

components of r and s together. In subtraction , the components of vector s are reversed to produce an equal and opposite vector

GRAPHICAL REPRESENTATION FOR ADDITION AND SUBTRACTION OF VECTORS

EXAMPLE: ADDITION OF VECTORS

The most common way is to break up a vector into x and y pieces, like this:

The vector a is broken up into

the two vectors ax and ay

EXAMPLE: ADDITION OF VECTORS And here is how to add two vectors after breaking

them into x and y parts:

The vector (8,13) and the vector (26,7) add up to the vector (34,20)

EXAMPLE: ADD THE VECTORS A = (8,13) AND B = (26,7)

UNIT VECTOR

A unit vector has a magnitude of 1.

i= [1 0 0] where |i|= 1 in computer graphics software, vectors are used to

control the orientation of surfaces, light sources and the virtual camera

Unit vectors reduce the computation time in computer graphics software.

CONVERSION OF A VECTOR INTO UNIT VECTOR: NORMALIZING

Normalizing is achieved by dividing the components of a vector by its magnitude. For a vector r,

when r = [x y z] and magnitude of r is Then, unit vector of r can be calculated as

NORMALIZING EXAMPLE:

r = [1 2 3] |r| = √ 1^2+ 2^2 +3^2 = √14 ˆr = 1 [1 2 3] ≈ [0.267 0.535 0.802] √ 14

MULTIPLICATION OF VECTORS

These are vectors:

They can be multiplied using the• "Dot Product"

• “Cross Product”

DOT PRODUCT (SCALAR PRODECT)

a · b = |a| × |b| × cos(θ) OR

a · b = ax × bx + ay × by

Where: |a| is the magnitude (length) of vector a |b| is the magnitude (length) of vector b θ is the angle between a and b So we multiply the length of a times the length of b, then

multiply by the cosine of the angle between a and b

EXAMPLE: CALCULATE THE DOT PRODUCT

r= [2 -1 3] s= [3 7 5]

SCALAR PRODUCT IN LIGHTING CALCULATIONS

Lambert’s law states that the intensity of illumination on a diffuse surface is proportional to the cosine of the angle between the surface normal vector and the lightsource direction.

SCALAR PRODUCT IN LIGHTING CALCULATIONS Figure shows a scenario where a light source

is located at (20, 20, 40), and the illuminated point is (0, 10, 0). In this situation, incident light intensity on surface can be calculated by multiplying cosβ with the light source intensity. To begin with, we are given the normal vector ˆn to the surface. In this case ˆn is a unit vector: i.e. | ˆn| = 1:

SCALAR PRODUCT IN LIGHTING CALCULATIONS

Unit vector n = [0 1 0]The direction of the light source from the surface is defined by the vector s:

SCALAR PRODUCT IN BACK-FACE DETECTION

The angle between the surface normal and the camera’s line of sight determines the polygon’s visibility

SCALAR PRODUCT IN BACK-FACE DETECTION

The virtual camera is located at (0, 0, 0) and the polygon’s vertex is (10, 10, 40). The normal vector is

n = [5 5 −2].

SCALAR PRODUCT IN BACK-FACE DETECTION

angle greater than 90 shows that the polygon is invisible for the camera.

CROSS PRODUCT (VECTOR PRODUCT)

The Cross Product a × b of two vectors is another vector that is at right angles to both. And it all happens in 3 dimensions!

CROSS PRODUCT (VECTOR PRODUCT) a × b = |a| |b| sin(θ) n

|a| is the magnitude (length) of vector a |b| is the magnitude (length) of vector b θ is the angle between a and b n is the unit vector at right angles to both a

and b

FIND THE ANGLE BETWEEN VECTORS

r= [2 0 3] s= [2 4 5]

top related