Docsity

Dot Products and Cross Products of Vectors: Properties and Applications, Slides of Computer Graphics and Animation

Partial preview of the text

Download Dot Products and Cross Products of Vectors: Properties and Applications and more Slides Computer Graphics and Animation in PDF only on Docsity!

Dot Products with General Vectors

 The dot product is a scalar value that tells

us something about the relationship

between two vectors

 If ab > 0 then _ < 90º

 If ab < 0 then _ > 90º

 If ab = 0 then _ = 90º (or one or more of

the vectors is degenerate (0,0,0))

Dot Products with One Unit Vector

a

u

au

 If | u |=1.0 then a · u is the length of the projection

of a onto u

Example: Distance to Plane

 The distance is the length of the projection

of x - p onto n :

p

n

- x

x-p

dist = ( x − p )⋅ n

Dot Products with Unit Vectors

b

_ a

ab = 0

0 < ab <

ab = -

ab = 1

-1 < ab <

cos ( θ )

a b

a b

a

b

Properties of the Cross Product

0

sin

× =

× =

× =

×

a b

a b

a b a b

a b

θ

area of parallelogram ab

is a vector perpendicular to both

a and b , in the direction defined by

the right hand rule

if a and b are parallel

Example: Normal of a Triangle

 Find the unit length normal of the triangle

defined by 3D points a , b , and c

a

b

c

Example: Area of a Triangle

 Find the area of the triangle defined by 3D

points a , b , and c

a

b

c

Example: Area of a Triangle

= ( b − a )× ( c − a )

area

b-a

c-a

a

b

c

Example: Alignment to Target

p

h

t t-p

_

a

( )

( )

( )

( )

× −

× −

−

t p

h t p

h t p

h t p

a

1

θ cos

Vector Class

class Vector3 {

public:

Vector3() {x=0.0f; y=0.0f; z=0.0f;}

Vector3(float x0,float y0,float z0) {x=x0; y=y0; z=z0;}

void Set(float x0,float y0,float z0) {x=x0; y=y0; z=z0;}

void Add(Vector3 &a) {x+=a.x; y+=a.y; z+=a.z;}

void Add(Vector3 &a,Vector3 &b) {x=a.x+b.x; y=a.y+b.y; z=a.z+b.z;}

void Subtract(Vector3 &a) {x-=a.x; y-=a.y; z-=a.z;}

void Subtract(Vector3 &a,Vector3 &b) {x=a.x-b.x; y=a.y-b.y; z=a.z-b.z;}

void Negate() {x=-x; y=-y; z=-z;}

void Negate(Vector3 &a) {x=-a.x; y=-a.y; z=-a.z;}

void Scale(float s) {x=s; y=s; z*=s;}

void Scale(float s,Vector3 &a) {x=sa.x; y=sa.y; z=s*a.z;}

float Dot(Vector3 &a) {return xa.x+ya.y+z*a.z;}

void Cross(Vector3 &a,Vector3 &b)

{x=a.yb.z-a.zb.y; y=a.zb.x-a.xb.z; z=a.xb.y-a.yb.x;}

float Magnitude() {return sqrtf(xx+yy+z*z);}

void Normalize() {Scale(1.0f/Magnitude());}

float x,y,z;

};