vector and matrix algebra - korea...

25
Graphics Graphics Lab @ Korea University http://kucg.korea.ac.kr Vector and Matrix Algebra Korea Univ. Computer Graphics Lab.

Upload: others

Post on 18-Jan-2021

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Vector and Matrix Algebra - Korea Universitykucg.korea.ac.kr/new/course/2010_2/CNCE340/tutor/02Vector... · 2002. 1. 17. · Graphics Graphics Lab @ Korea University Vector Algebra

Graphics

Graphics Lab @ Korea University http://kucg.korea.ac.kr

Vector and

Matrix Algebra

Korea Univ.

Computer Graphics Lab.

Page 2: Vector and Matrix Algebra - Korea Universitykucg.korea.ac.kr/new/course/2010_2/CNCE340/tutor/02Vector... · 2002. 1. 17. · Graphics Graphics Lab @ Korea University Vector Algebra

Graphics

Graphics Lab @ Korea University

Vector Algebra

http://kucg.korea.ac.kr

Page 3: Vector and Matrix Algebra - Korea Universitykucg.korea.ac.kr/new/course/2010_2/CNCE340/tutor/02Vector... · 2002. 1. 17. · Graphics Graphics Lab @ Korea University Vector Algebra

KUCG

Graphics Lab @ Korea University

Vector

Vector

Direction + magnitude

http://kucg.korea.ac.kr

Page 4: Vector and Matrix Algebra - Korea Universitykucg.korea.ac.kr/new/course/2010_2/CNCE340/tutor/02Vector... · 2002. 1. 17. · Graphics Graphics Lab @ Korea University Vector Algebra

KUCG

Graphics Lab @ Korea University

Vector-valued Quantities

Force

Direction + strength

Displacement

Direction + distance of moving object …

Velocities

Direction + speed

http://kucg.korea.ac.kr

Page 5: Vector and Matrix Algebra - Korea Universitykucg.korea.ac.kr/new/course/2010_2/CNCE340/tutor/02Vector... · 2002. 1. 17. · Graphics Graphics Lab @ Korea University Vector Algebra

KUCG

Graphics Lab @ Korea University

Vectors for Pure Direction

Direction the player is looking in a 3D game

Direction a polygon is facing

Direction in which a ray of light travels

http://kucg.korea.ac.kr

Page 6: Vector and Matrix Algebra - Korea Universitykucg.korea.ac.kr/new/course/2010_2/CNCE340/tutor/02Vector... · 2002. 1. 17. · Graphics Graphics Lab @ Korea University Vector Algebra

KUCG

Graphics Lab @ Korea University

Drawing Vectors

magnitude) anddirection (same vu

y

u v

w

x

Head

Tail

http://kucg.korea.ac.kr

Page 7: Vector and Matrix Algebra - Korea Universitykucg.korea.ac.kr/new/course/2010_2/CNCE340/tutor/02Vector... · 2002. 1. 17. · Graphics Graphics Lab @ Korea University Vector Algebra

KUCG

Graphics Lab @ Korea University

Point and Vector

Point (x, y, z)

A location in 3D space

Vector (x, y, z)

Direction + magnitude

Not fixed at specific location

http://kucg.korea.ac.kr

Page 8: Vector and Matrix Algebra - Korea Universitykucg.korea.ac.kr/new/course/2010_2/CNCE340/tutor/02Vector... · 2002. 1. 17. · Graphics Graphics Lab @ Korea University Vector Algebra

KUCG

Graphics Lab @ Korea University

Left-handed vs. Right-handed

Left-handed Coordinate System

Direct3D

Right-handed Coordinate System

OpenGL & Math textbooks

[Left-handed] [Right-handed]

http://kucg.korea.ac.kr

Page 9: Vector and Matrix Algebra - Korea Universitykucg.korea.ac.kr/new/course/2010_2/CNCE340/tutor/02Vector... · 2002. 1. 17. · Graphics Graphics Lab @ Korea University Vector Algebra

KUCG

Graphics Lab @ Korea University

Basic Vector Operations

Equality

Addition/Subtraction

Scalar Multiplication

http://kucg.korea.ac.kr

Page 10: Vector and Matrix Algebra - Korea Universitykucg.korea.ac.kr/new/course/2010_2/CNCE340/tutor/02Vector... · 2002. 1. 17. · Graphics Graphics Lab @ Korea University Vector Algebra

KUCG

Graphics Lab @ Korea University

Geometric Interpretations

Scalar Multiplication

Addition

Subtraction

http://kucg.korea.ac.kr

Page 11: Vector and Matrix Algebra - Korea Universitykucg.korea.ac.kr/new/course/2010_2/CNCE340/tutor/02Vector... · 2002. 1. 17. · Graphics Graphics Lab @ Korea University Vector Algebra

KUCG

Graphics Lab @ Korea University

Vector Length/Norm/Magnitude

22),( yxhyx T

[Pythagorean Formula]

222),,( zyxzyx T

http://kucg.korea.ac.kr

Page 12: Vector and Matrix Algebra - Korea Universitykucg.korea.ac.kr/new/course/2010_2/CNCE340/tutor/02Vector... · 2002. 1. 17. · Graphics Graphics Lab @ Korea University Vector Algebra

KUCG

Graphics Lab @ Korea University

Unit Vector

Unit Vector

Having length 1

Normalization

Making unit vector

u

z

u

y

u

x

u

u

,,

http://kucg.korea.ac.kr

Page 13: Vector and Matrix Algebra - Korea Universitykucg.korea.ac.kr/new/course/2010_2/CNCE340/tutor/02Vector... · 2002. 1. 17. · Graphics Graphics Lab @ Korea University Vector Algebra

KUCG

Graphics Lab @ Korea University

Dot (Inner/Scalar) Product

Dot Product of Two Vectors

Result : scalar value

Thus, dot product is called scalar product

+

+

-

-

http://kucg.korea.ac.kr

Page 14: Vector and Matrix Algebra - Korea Universitykucg.korea.ac.kr/new/course/2010_2/CNCE340/tutor/02Vector... · 2002. 1. 17. · Graphics Graphics Lab @ Korea University Vector Algebra

KUCG

Graphics Lab @ Korea University

Cross (Outer/Vector) Product

Cross Product of Two Vectors

w is orthogonal to u and v

Result : vector

Thus, cross product is called vector product

http://kucg.korea.ac.kr

Page 15: Vector and Matrix Algebra - Korea Universitykucg.korea.ac.kr/new/course/2010_2/CNCE340/tutor/02Vector... · 2002. 1. 17. · Graphics Graphics Lab @ Korea University Vector Algebra

KUCG

Graphics Lab @ Korea University

Vector Application : Ray

http://kucg.korea.ac.kr

Page 16: Vector and Matrix Algebra - Korea Universitykucg.korea.ac.kr/new/course/2010_2/CNCE340/tutor/02Vector... · 2002. 1. 17. · Graphics Graphics Lab @ Korea University Vector Algebra

KUCG

Graphics Lab @ Korea University

Vector Application : Line Segment

http://kucg.korea.ac.kr

Page 17: Vector and Matrix Algebra - Korea Universitykucg.korea.ac.kr/new/course/2010_2/CNCE340/tutor/02Vector... · 2002. 1. 17. · Graphics Graphics Lab @ Korea University Vector Algebra

KUCG

Graphics Lab @ Korea University

Vector in Practice

class VECTOR

{

public:

float Magnitude();

float InnerProduct(VECTOR v);

VECTOR CrossProduct(VECTOR v);

float x;

float y;

float z;

};

float VECTOR::Magnitude()

{

return sqrt(x*x + y*y + z*z);

}

float VECTOR::InnerProduct(VECTOR v)

{

return (x * v.x + y * v.y + z * v.z);

}

VECTOR VECTOR::CrossProduct(VECTOR v)

{

VECTOR result;

result.x = y * v.z - z * v.y;

result.y = z * v.x - x * v.z;

result.z = x * v.y - y * v.x;

return result;

}

http://kucg.korea.ac.kr

Page 18: Vector and Matrix Algebra - Korea Universitykucg.korea.ac.kr/new/course/2010_2/CNCE340/tutor/02Vector... · 2002. 1. 17. · Graphics Graphics Lab @ Korea University Vector Algebra

Graphics

Graphics Lab @ Korea University

Matrix Algebra

http://kucg.korea.ac.kr

Page 19: Vector and Matrix Algebra - Korea Universitykucg.korea.ac.kr/new/course/2010_2/CNCE340/tutor/02Vector... · 2002. 1. 17. · Graphics Graphics Lab @ Korea University Vector Algebra

KUCG

Graphics Lab @ Korea University

Matrix Examples

Matrix A : Dimension 4x4

Square matrix

Matrix B : Dimension 3x2

Matrix u : Row vector

Matrix v : Column vector

http://kucg.korea.ac.kr

Page 20: Vector and Matrix Algebra - Korea Universitykucg.korea.ac.kr/new/course/2010_2/CNCE340/tutor/02Vector... · 2002. 1. 17. · Graphics Graphics Lab @ Korea University Vector Algebra

KUCG

Graphics Lab @ Korea University

Matrix as Vectors

Rows of a Matrix as Vectors

Columns of a Matrix as Vectors

http://kucg.korea.ac.kr

Page 21: Vector and Matrix Algebra - Korea Universitykucg.korea.ac.kr/new/course/2010_2/CNCE340/tutor/02Vector... · 2002. 1. 17. · Graphics Graphics Lab @ Korea University Vector Algebra

KUCG

Graphics Lab @ Korea University

Basic Matrix Operations

Equality

Addition/Subtraction

Scalar Multiplication

http://kucg.korea.ac.kr

Page 22: Vector and Matrix Algebra - Korea Universitykucg.korea.ac.kr/new/course/2010_2/CNCE340/tutor/02Vector... · 2002. 1. 17. · Graphics Graphics Lab @ Korea University Vector Algebra

KUCG

Graphics Lab @ Korea University

Matrix Multiplications

Associativity

http://kucg.korea.ac.kr

Page 23: Vector and Matrix Algebra - Korea Universitykucg.korea.ac.kr/new/course/2010_2/CNCE340/tutor/02Vector... · 2002. 1. 17. · Graphics Graphics Lab @ Korea University Vector Algebra

KUCG

Graphics Lab @ Korea University

Vector-Matrix Multiplication

http://kucg.korea.ac.kr

Page 24: Vector and Matrix Algebra - Korea Universitykucg.korea.ac.kr/new/course/2010_2/CNCE340/tutor/02Vector... · 2002. 1. 17. · Graphics Graphics Lab @ Korea University Vector Algebra

KUCG

Graphics Lab @ Korea University

Various Matrices

Transpose of MxN Matrix : NxM Matrix

Identity Matrix

http://kucg.korea.ac.kr

Page 25: Vector and Matrix Algebra - Korea Universitykucg.korea.ac.kr/new/course/2010_2/CNCE340/tutor/02Vector... · 2002. 1. 17. · Graphics Graphics Lab @ Korea University Vector Algebra

KUCG

Graphics Lab @ Korea University

Matrix in Practice

class MATRIX

{

public:

MATRIX Add(MATRIX m);

MATRIX Subtract(MATRIX m);

MATRIX Multiply(MATRIX m);

MATRIX Transpose();

float ele[4][4];

float num_of_rows;

float num_of_columns;

};

MATRIX MATRIX::Add(MATRIX m)

{

MATRIX result;

for(int i = 0; i < num_of_rows; i++)

for(int j = 0; j < num_of_columns; j++)

result.ele[i][j] = ele[i][j] + m.ele[i][j];

return result;

}

MATRIX MATRIX::Multiply(MATRIX m)

{

int i, j, k;

MATRIX result;

for(i = 0; i < num_of_rows; i++)

for(j = 0; j < num_of_columns; j++)

result.ele[i][j] = 0.0;

if(num_of_columns == m.num_of_rows)

{

result.num_of_rows = num_of_rows;

result.num_of_columns = m. num_of_columns;

for(i = 0; i < num_of_rows; i++)

for(j = 0; j < m.num_of_columns; j++)

for(k = 0; k < num_of_columns; k++)

result.ele[i][j] += ele[i][k] * m.ele[k][j];

}

return result;

}

http://kucg.korea.ac.kr