27
CSC 123 – Computational Art Points and Vectors Zoë Wood

CSC 123 – Computational Art Points and Vectors Zoë Wood

  • View
    224

  • Download
    3

Embed Size (px)

Citation preview

Page 1: CSC 123 – Computational Art Points and Vectors Zoë Wood

CSC 123 – Computational ArtPoints and Vectors

Zoë Wood

Page 2: CSC 123 – Computational Art Points and Vectors Zoë Wood

Representing Points and Vectors

• A 2D point:

– Represents a location with respect to some coordinate system

• A 2D vector:

– Represents a displacement from a position

y

xv

y

xp

Page 3: CSC 123 – Computational Art Points and Vectors Zoë Wood

Vectors

• Objects with length and direction.• Represent motion between points in space.

• We will think of a vector as a displacement from one point to another.

• We use bold typeface to indicate vectors.

v

Page 4: CSC 123 – Computational Art Points and Vectors Zoë Wood

Vectors as Displacements

• As a displacement, a vector has length and direction, but no inherent location.

• It doesn’t matter if you step one foot forward in Boston or in New York.

vv v

v

v

v

Page 5: CSC 123 – Computational Art Points and Vectors Zoë Wood

Vector Notation• We represent vectors as a list of components.• By convention, we write vectors as a column

matrix:

• We can also write them as row matrix, indicated by vT:vT = [x0, x1] or wT = [x0, x1 , x2]

• All components of the zero vector 0 are 0.

1

0

x

xv

2

1

0

x

x

x

wor

Page 6: CSC 123 – Computational Art Points and Vectors Zoë Wood

Vector Operations

• Addition and multiplication by a scalar:– a + b– s*a

• Examples:

_

_*6

_

_

2-

3;

5

2

a

b

ba

a

Page 7: CSC 123 – Computational Art Points and Vectors Zoë Wood

Vector Operations

• Addition and multiplication by a scalar:– a + b– s*a

• Examples:

30

12*6

3

5

2-

3;

5

2

a

b

b

a

a

Page 8: CSC 123 – Computational Art Points and Vectors Zoë Wood

Vector Scaling – geometric interpretation

• Multiplying a vector by a scalar multiplies the vector’s length without changing its direction:

v

2 * v3.5 * v

Page 9: CSC 123 – Computational Art Points and Vectors Zoë Wood

Vector scalar Multiplication

• Given wT = [x0, x1 , x2] and scalars s and t s * wT = [s * x0, s * x1 , s * x2]

• Properties of Vector multiplication– Associative: (st)V = s(tV)– Multiplicative Identity: 1V = V– Scalar Distribution: (s+t)V = sV+tV– Vector Distribution: s(V+W) = sV+sW

Page 10: CSC 123 – Computational Art Points and Vectors Zoë Wood

Vector addition – geometric interpretation

Paralleologram rule• To visualize what vector addition is

doing, here is a 2D example:

V

W

V+W

Page 11: CSC 123 – Computational Art Points and Vectors Zoë Wood

Vector Addition

• Head to tail: At the end of a, place the start of b.

a + b = b + a

• Components: a + b = [a0 + b0, a1 + b1]T

ba

a+b

Page 12: CSC 123 – Computational Art Points and Vectors Zoë Wood

Unary Minus

• Algebraically, -v = (-1) v.• The geometric interpretation of -v is a

vector in the opposite direction:

v

-v

Page 13: CSC 123 – Computational Art Points and Vectors Zoë Wood

Vector Subtraction

• b - a = -a + b

• Components: b - a = [b0 - a0, b1 - a1]T

b

ab-a

-a+b

Page 14: CSC 123 – Computational Art Points and Vectors Zoë Wood

Linear Combinations

• A linear combination of m vectors is a vector of the form:

where a1, a2, …, am are scalars.

• Example:

m21 ,,, vvv

,aaa mm2211 vvvw

_

_62

0

1-;

4

3

21

21

v

vv

v

Page 15: CSC 123 – Computational Art Points and Vectors Zoë Wood

Linear Combinations

• A linear combination of m vectors is a vector of the form:

where a1, a2, …, am are scalars.

• Example:

m21 ,,, vvv

,aaa mm2211 vvvw

8

062

0

1-;

4

3

21

21

v

v

v

v

Page 16: CSC 123 – Computational Art Points and Vectors Zoë Wood

Vector Addition

• Given vT = [x0, x1 , x2] and wT = [y0, y1 , y2]

– V+W = [x0 +y0, x1 + y1 , x2 + y2]

• Properties of Vector addition– Commutative: V+W=W+V– Associative (U+V)+W = U+(V+W)– Additive Identity: V+0 = V– Additive Inverse: V+W = 0, W=-V

Page 17: CSC 123 – Computational Art Points and Vectors Zoë Wood

Points and Vectors

• We normally say v = [3 2 7]T.• Similarly, for a point we say P = [3 2 7]T.

• But points and vectors are very different:– Points: have a location, but no direction.– Vectors: have direction, but no location.

• Point: A fixed location in a geometric world.• Vector: Displacement between points in the

world.

Page 18: CSC 123 – Computational Art Points and Vectors Zoë Wood

Vectors to Specify Locations

• Locations can be represented as displacements from another location.

• There is some understood origin location O from which all other locations are stored as offsets.

• Note that locations are not vectors!• Locations are described using points.

v

O

P

Page 19: CSC 123 – Computational Art Points and Vectors Zoë Wood

Operations on Vectors and Points•Linear operations on vectors make sense,

but the same operations do not make sense for points:

•Addition: –Vectors: concatenation of displacements.–Points: ?? (SLO + LA = ?)

•Multiplication by a scalar:–Vectors: increases displacement by a factor.–Points: ?? (What is 7 times the North Pole?)

•Zero element:–Vectors: The zero vector represents no displacement.

–Points: ?? (Is there a zero point?)

Page 20: CSC 123 – Computational Art Points and Vectors Zoë Wood

Operations on Points

• However, some operations with points make sense.

• We can subtract two points. The result is the motion from one point to the other:

P - Q = v

• We can also start with a point and move to another point:

Q + v = P

Page 21: CSC 123 – Computational Art Points and Vectors Zoë Wood

Other operations

• There are other operations on 3D vectors– dot product– cross product

• We won’t talk about these

Page 22: CSC 123 – Computational Art Points and Vectors Zoë Wood

Vector Basis

• Vectors which are linearly independent form a basis.

• The vectors are called basis vectors.• Any vector can be expressed as linear

combination of the basis vectors:

• Note that the coefficients ac and bc are unique.

bac cc ba

Page 23: CSC 123 – Computational Art Points and Vectors Zoë Wood

Orthogonal Basis

• If the two vectors are at right angles to each other, we call the it an orthogonal basis.

• If they are also vectors with length one, we call it an orthonormal basis.

• In 2D, we can use two such special vectors x and y to define the Cartesian basis vectors

• x = [1 0] y = [0 1] x

y

Page 24: CSC 123 – Computational Art Points and Vectors Zoë Wood

Cartisian

• Descarté• One reason why cartesian coordinates

are nice

x

y

2

0.5

yxc ).50(2

cBy Pythagorean theorem:

length of c is:

22aa yx c

Page 25: CSC 123 – Computational Art Points and Vectors Zoë Wood

Normalizing a vector

• In order to make a vector be a ‘normal’ vector it must be of unit length.

• We can normalize a vector by dividing each component by its length

ˆ v = v / v

Page 26: CSC 123 – Computational Art Points and Vectors Zoë Wood

How can we use these?

• When we want to control movement, we can use vectors

• For example if we want to have a faces’ eyeballs follow the mouse…

Page 27: CSC 123 – Computational Art Points and Vectors Zoë Wood

Problem

• Move eyeballs to the edge of a circle in a given direction– Compute the vector, which is a displacement

fromthe current position towhere the mouse wasclicked

– Scale the vector to only be aslong as the eye’s radius

– Displace the eyeball to rimof the eye