VECTORS Computer Graphics. A REVIEW OF VECTORS: Scalar Quantity Vector Quantity 2D vectors ...

27
VECTORS Computer Graphics

Transcript of VECTORS Computer Graphics. A REVIEW OF VECTORS: Scalar Quantity Vector Quantity 2D vectors ...

Page 1: VECTORS Computer Graphics. A REVIEW OF VECTORS:  Scalar Quantity  Vector Quantity  2D vectors  Graphical Representation of Vectors  Magnitude of.

VECTORSComputer Graphics

Page 2: VECTORS Computer Graphics. A REVIEW OF VECTORS:  Scalar Quantity  Vector Quantity  2D vectors  Graphical Representation of Vectors  Magnitude of.

A REVIEW OF VECTORS:

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

Page 3: VECTORS Computer Graphics. A REVIEW OF VECTORS:  Scalar Quantity  Vector Quantity  2D vectors  Graphical Representation of Vectors  Magnitude of.

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.

Page 4: VECTORS Computer Graphics. A REVIEW OF VECTORS:  Scalar Quantity  Vector Quantity  2D vectors  Graphical Representation of Vectors  Magnitude of.

3D VECTORS

Calculation of magnitude

of a vector.

Page 5: VECTORS Computer Graphics. A REVIEW OF VECTORS:  Scalar Quantity  Vector Quantity  2D vectors  Graphical Representation of Vectors  Magnitude of.

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.

Page 6: VECTORS Computer Graphics. A REVIEW OF VECTORS:  Scalar Quantity  Vector Quantity  2D vectors  Graphical Representation of Vectors  Magnitude of.

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

Page 7: VECTORS Computer Graphics. A REVIEW OF VECTORS:  Scalar Quantity  Vector Quantity  2D vectors  Graphical Representation of Vectors  Magnitude of.

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

Page 8: VECTORS Computer Graphics. A REVIEW OF VECTORS:  Scalar Quantity  Vector Quantity  2D vectors  Graphical Representation of Vectors  Magnitude of.

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

Page 9: VECTORS Computer Graphics. A REVIEW OF VECTORS:  Scalar Quantity  Vector Quantity  2D vectors  Graphical Representation of Vectors  Magnitude of.

GRAPHICAL REPRESENTATION FOR ADDITION AND SUBTRACTION OF VECTORS

Page 10: VECTORS Computer Graphics. A REVIEW OF VECTORS:  Scalar Quantity  Vector Quantity  2D vectors  Graphical Representation of Vectors  Magnitude of.

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

Page 11: VECTORS Computer Graphics. A REVIEW OF VECTORS:  Scalar Quantity  Vector Quantity  2D vectors  Graphical Representation of Vectors  Magnitude of.

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)

Page 12: VECTORS Computer Graphics. A REVIEW OF VECTORS:  Scalar Quantity  Vector Quantity  2D vectors  Graphical Representation of Vectors  Magnitude of.

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

Page 13: VECTORS Computer Graphics. A REVIEW OF VECTORS:  Scalar Quantity  Vector Quantity  2D vectors  Graphical Representation of Vectors  Magnitude of.

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.

Page 14: VECTORS Computer Graphics. A REVIEW OF VECTORS:  Scalar Quantity  Vector Quantity  2D vectors  Graphical Representation of Vectors  Magnitude of.

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

Page 15: VECTORS Computer Graphics. A REVIEW OF VECTORS:  Scalar Quantity  Vector Quantity  2D vectors  Graphical Representation of Vectors  Magnitude of.

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

Page 16: VECTORS Computer Graphics. A REVIEW OF VECTORS:  Scalar Quantity  Vector Quantity  2D vectors  Graphical Representation of Vectors  Magnitude of.

MULTIPLICATION OF VECTORS

These are vectors:

They can be multiplied using the• "Dot Product"

• “Cross Product”

Page 17: VECTORS Computer Graphics. A REVIEW OF VECTORS:  Scalar Quantity  Vector Quantity  2D vectors  Graphical Representation of Vectors  Magnitude of.

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

Page 18: VECTORS Computer Graphics. A REVIEW OF VECTORS:  Scalar Quantity  Vector Quantity  2D vectors  Graphical Representation of Vectors  Magnitude of.

EXAMPLE: CALCULATE THE DOT PRODUCT

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

Page 19: VECTORS Computer Graphics. A REVIEW OF VECTORS:  Scalar Quantity  Vector Quantity  2D vectors  Graphical Representation of Vectors  Magnitude of.

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.

Page 20: VECTORS Computer Graphics. A REVIEW OF VECTORS:  Scalar Quantity  Vector Quantity  2D vectors  Graphical Representation of Vectors  Magnitude of.

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:

Page 21: VECTORS Computer Graphics. A REVIEW OF VECTORS:  Scalar Quantity  Vector Quantity  2D vectors  Graphical Representation of Vectors  Magnitude of.

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:

Page 22: VECTORS Computer Graphics. A REVIEW OF VECTORS:  Scalar Quantity  Vector Quantity  2D vectors  Graphical Representation of Vectors  Magnitude of.

SCALAR PRODUCT IN BACK-FACE DETECTION

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

Page 23: VECTORS Computer Graphics. A REVIEW OF VECTORS:  Scalar Quantity  Vector Quantity  2D vectors  Graphical Representation of Vectors  Magnitude of.

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].

Page 24: VECTORS Computer Graphics. A REVIEW OF VECTORS:  Scalar Quantity  Vector Quantity  2D vectors  Graphical Representation of Vectors  Magnitude of.

SCALAR PRODUCT IN BACK-FACE DETECTION

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

Page 25: VECTORS Computer Graphics. A REVIEW OF VECTORS:  Scalar Quantity  Vector Quantity  2D vectors  Graphical Representation of Vectors  Magnitude of.

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!

Page 26: VECTORS Computer Graphics. A REVIEW OF VECTORS:  Scalar Quantity  Vector Quantity  2D vectors  Graphical Representation of Vectors  Magnitude of.

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

Page 27: VECTORS Computer Graphics. A REVIEW OF VECTORS:  Scalar Quantity  Vector Quantity  2D vectors  Graphical Representation of Vectors  Magnitude of.

FIND THE ANGLE BETWEEN VECTORS

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