You are on page 1of 18

Escuela Profesional de

Ciencia de la Computación

ICC Fase 1

Computer graphics
Mathematical Foundations

MSc. Vicente Machaca Arceda

Universidad Nacional de San Agustín de Arequipa

May 12, 2021

MSc. Vicente Machaca Arceda (UNSA) 1704146 1 / 16


Overview

1 Vectors
Definition
Dot product
Cross product
vmachacaa@unsa.edu.pe

MSc. Vicente Machaca Arceda (UNSA) 1704146 2 / 16


Vectors Definition

Table of Contents

1 Vectors
Definition
Dot product
Cross product
vmachacaa@unsa.edu.pe

MSc. Vicente Machaca Arceda (UNSA) 1704146 3 / 16


Vectors Definition

Vectors
Vectors specify a magnitude and direction. In 3D graphics,
vectors are represented as a point in space. The vector is the
distance and direction from the origin to that point.
vmachacaa@unsa.edu.pe

Figure: Vector representation in computer graphics. Source: [1]

MSc. Vicente Machaca Arceda (UNSA) 1704146 4 / 16


Vectors Definition

Vectors
Vector V (shown in red) can be specified either as the difference
between points P1 and P2, or as an equivalent distance from
the origin to P3. In all of our applications, we specify V as
simply (x,y,z)
vmachacaa@unsa.edu.pe

Figure: Vector representation in computer graphics. Source: [1]

MSc. Vicente Machaca Arceda (UNSA) 1704146 5 / 16


Vectors Definition

vector operations

Addition and Subtraction


~ ±B
A ~ = (u ± x, v ± y , w ± z)

glm: vec3 ± vec3


GLSL: vec3 ± vec3

Normalize (change to length=1)


~
A ~
A
 = =
~
|A| sqrt(u + v 2 + w 2 )
2

~ = lenght of A
where |A| ~
vmachacaa@unsa.edu.pe

glm: normalize(vec3) or normalize(vec4)


GLSL: normalize(vec3) or normalize(vec4)

MSc. Vicente Machaca Arceda (UNSA) 1704146 6 / 16


Vectors Definition

vector operations

Dot Product
vmachacaa@unsa.edu.pe

MSc. Vicente Machaca Arceda (UNSA) 1704146 7 / 16


Vectors Definition

vector operations

Dot Product
~ •B
A ~ = ux + vy + wz

glm: dot(vec3,vec3) or dot(vec4,vec4)


GLSL: dot(vec3,vec3) or dot(vec4,vec4)

Cross Product
vmachacaa@unsa.edu.pe

MSc. Vicente Machaca Arceda (UNSA) 1704146 7 / 16


Vectors Definition

vector operations

Dot Product
~ •B
A ~ = ux + vy + wz

glm: dot(vec3,vec3) or dot(vec4,vec4)


GLSL: dot(vec3,vec3) or dot(vec4,vec4)

Cross Product
~ ×B
A ~ = (vz − wy , wx − uz, uy − vx)

glm: cross(vec3,vec3)
vmachacaa@unsa.edu.pe

GLSL: cross(vec3,vec3)

MSc. Vicente Machaca Arceda (UNSA) 1704146 7 / 16


Vectors Dot product

Table of Contents

1 Vectors
Definition
Dot product
Cross product

MSc. Vicente Machaca Arceda (UNSA) 1704146 8 / 16


Vectors Dot product

Dot product
Explanation

V~ •W ~
cos(θ) =
~ | ∗ |W
|V ~|

~ and W
Therefore, if V ~ are
normalized (i.e., of unit length,
here we use the notation for
~ •W
V ~ = |V
~ | ∗ |W
~ | ∗ cos(θ) normalization: V̂ and Ŵ . then:

cos(θ) = V̂ • Ŵ
θ = arcos(V̂ • Ŵ )

MSc. Vicente Machaca Arceda (UNSA) 1704146 9 / 16


Vectors Dot product

Dot product
Application

Uses Formula

Vector magnitude

Two vectors are perpendicular if ?

Two vectors are parallel if ?

Two vectors are parallel but pointing in


opposite direction if ?

MSc. Vicente Machaca Arceda (UNSA) 1704146 10 / 16


Vectors Dot product

Dot product
Application

Uses Formula
p
Vector magnitude ~ •W
V ~

Two vectors are perpendicular if ? ~ •W


V ~ =0

Two vectors are parallel if ? ~ •W


V ~ = |V
~ | ∗ |W
~|

~ •W
Two vectors are parallel but pointing in V ~ = −|V
~ | ∗ |W
~|
opposite direction if ?

MSc. Vicente Machaca Arceda (UNSA) 1704146 11 / 16


Vectors Cross product

Table of Contents

1 Vectors
Definition
Dot product
Cross product

MSc. Vicente Machaca Arceda (UNSA) 1704146 12 / 16


Vectors Cross product

Cross product
Explanation

~ ×W
V ~ = |V
~ | ∗ |W
~ | ∗ sin(θ) ∗ n

~
θ is the angle between V
and W ~
n is a unit vector
perpendicular to V ~ and W
~

~ is perpendicular (normal) to
R Moreover,
~ and W
V ~ , with a direction
given by the right-hand rule. ~ ×W
V ~ = −(W
~ ×V
~)

MSc. Vicente Machaca Arceda (UNSA) 1704146 13 / 16


Vectors Cross product

Cross product
Explanation

The ability to find normal


vectors by using the cross
product will become extremely
useful when we study lighting.

~ =V
P ~2 − V
~1
~ ~ ~1
Q = V3 − V
Figure: Computing outward ~ ~
N =P ×Q ~
normals.

MSc. Vicente Machaca Arceda (UNSA) 1704146 14 / 16


Vectors Cross product

References I

V. S. Gordon and J. L. Clevenger, Computer Graphics


Programming in OpenGL with C++. Stylus Publishing,
LLC, 2020.

MSc. Vicente Machaca Arceda (UNSA) 1704146 15 / 16


Vectors Cross product

Questions?

MSc. Vicente Machaca Arceda (UNSA) 1704146 16 / 16

You might also like