linearity - PowerPoint PPT Presentation

1 / 39
About This Presentation
Title:

linearity

Description:

The numbers we multiply the thingies by are called coefficients ... matrix as three row vectors, Fx, Fy, and Fz piled on top of one another, then ... – PowerPoint PPT presentation

Number of Views:36
Avg rating:3.0/5.0
Slides: 40
Provided by: ianhor2
Category:
Tags: linearity | piled

less

Transcript and Presenter's Notes

Title: linearity


1
linearity
2
Linear combinations
  • A linear combination of thingies is
  • A sum of
  • multiples of
  • the thingies (numbers, vectors, whatever)
  • Some less important terminology
  • The numbers we multiply the thingies by are
    called coefficients
  • When the coefficients sum to 1, we get a weighted
    average of the thingies

3
Useful fact
  • A linear combination
  • of linear combinations
  • is still a linear combination
  • Example
  • 2x3y is a linear combination
  • 3x2y is a linear combination
  • 3(2x3y)2(3x2y) is
  • A linear combination of the linear combinations
  • But equals 12x13y, a linear combination of x and
    y

4
Coordinates revisited
  • If a vector a
  • Has coordinates ax, ay, and az
  • Then we can think of a as
  • a linear combination
  • of vectors pointing along the axes
  • x, y, and z
  • (sometimes called basis vectors)
  • a axxayyazz
  • Coordinates are a way of thinking of vectors as
    linear combinations of basis vectors (axes)

a (ax, ay, az)
y
x
z
5
Linearity
  • Linear means line-like
  • A function is linear if it can be swapped with
    addition and multiplication
  • f(xy) f(x)f(y)
  • f(sx) sf(x)
  • Equivalently a function is linear if it can be
    swapped with linear combinations
  • Most of science and mathematics is based on
    linearity
  • NB this is a slightly different definition
    than you probably got in high school

6
Everything is addition (and multiplication)
  • Not surprisingly
  • Any linear function is really
  • A sum (addition) of
  • multiples of
  • its inputs
  • So a linear function is a linear combination of
    its inputs
  • However, we wont prove it
  • When a and b are numbers
  • f(a, b) k1a k2b
  • When a is a vector
  • f(a) k1axk2ayk3az
  • Remember dot products?

7
What if the output of f is a vector?
  • If
  • f is linear
  • a is a linear combination of the vectors x, y,
    and z
  • i.e. a axxayyazz
  • Then
  • f(a) f(axxayyazz)
  • f(axx)f(ayy)f(ayy)
  • axf(x) ayf(y) ayf(y)
  • So f is a linear combination of f(x), f(y), f(z)
  • So to compute a linear function on a vector, you
    only need to know
  • Its coodinates (ax, ay, az)
  • The output of f on the axes
  • f(x), f(y), f(z)

8
Why linearity matters
  • Common(thankfully, very common)
  • Most things are linear, at least approximately
  • Physics is linear (on a small scale)
  • Comprehensible
  • Theres a deep, simple theory of linear systems
  • Complex systems basically means the study of
    everything that isnt linear
  • Chaotic systems are always non-linear systems
  • Calculable
  • Easily reduced to addition and multiplication
  • Easily combined
  • If f(x) and g(x) are linear, then f(g(x)) is
    linear
  • Controllable
  • Linear systems are the most stable and predictable

9
Local linearity
  • Nearly all functions look linear if you zoom in
    on a small enough part
  • The differential of a function at some point is
  • The closest
  • linear approximation
  • to a function
  • at that point
  • Differential calculus is basically the study of
  • How to approximate non-linear functions
  • with linear approximations

10
Linearity rocks
  • All the following are linear
  • Rotating a vector
  • Scaling a vector (stretching/shrinking)
  • Shear
  • Changing coordinate systems
  • Dot products
  • Orthographic projection

11
Describing linear functions
  • Every linear function is described by a few
    numbers
  • If f maps numbers to numbers
  • Then f(a) ka
  • I.e. just multiplication
  • f is determined by one number (k)
  • If f maps numbers to vectors
  • Then f(a) va
  • I.e. just scalar multiplication of a vector
  • For some vector v
  • So f is determined by three numbers (vx, vy, vz)
  • If f maps vectors to numbers
  • Then f(a) kxaxkyaykzaz
  • I.e. a dot product
  • So f is determined by three numbers (kx, ky, kz)
  • If f maps vectors to vectors
  • Then f(a) axf(x)ayf(y)azf(z)
  • So f is determined by three vectors
  • f(x), f(y), f(z)
  • Or 9 numbers
  • f(x) fxx, fxy, fxz
  • f(y) fyz, fyy, fyz
  • f(z) fzx, fzy, fzz

12
Matrices
  • A matrix is a bookkeeping device for keeping
    track of vectors linear functions
  • Table of numbers, e.g.
  • You can also think of
  • Vectors as (skinny) matrices
  • And scalars as (really skinny) matrices

13
Matrix multiplication
  • Remember that
  • if f(x) and g(x) are linear
  • Then f(g(x)) is also linear
  • That means that given
  • The matrix for f(x), and
  • The matrix g(x)
  • You ought to be able to find
  • The matrix for f(g(x))
  • You can, and the procedure is called matrix
    multiplication(see appendix)
  • We wont go into how it works, but suffice it to
    say
  • Its consists of doing a lot of linear
    combinations
  • Or you can think of it as doing a lot of dot
    products

14
Matrix multiplication rocks
  • All the following are linear
  • Rotating a vector
  • Scaling a vector (stretching/shrinking)
  • Shear
  • Changing coordinate systems
  • Dot products
  • Orthographic projection
  • Matrices give us an efficient way to
  • Represent linear functions
  • Compute linear functions
  • Combine many linear functions into one linear
    function

15
Unfortunately
  • There are a couple of things wed really like to
    do in graphics that arent linear
  • Translation
  • Perspective projection

16
Homogeneous coordinates
  • Fortunately, some twisted mind came up with a
    great trick for circumventing this problem
  • Represent points in 3-space as 4 dimensional
    vectors
  • (ax, ay, az, 1)
  • where the fourth coordinate is always 1

17
Linear functions on homogeneous coordinate
  • But wait
  • This seems like it just makes things worse!
  • If we take a linear transform of one of these
    weird vectors
  • We probably wont even end up with a vector that
    ends with 1
  • One more trick
  • If we get a vector that ends with a number other
    than 1
  • e.g. (x, y, z, w)
  • We just understand that the other coordinates
    should be divided by this last number to get the
    real coodinates
  • (x, y, z, w) really means (x/w, y/w, z/w, 1)

18
Homogeneous coordinates rock
  • It turns out that these tricks let us represent
    all the common graphics transforms as linear
    functions
  • Rotation, scale, shear, orthographic projection,
  • and translation and perspective projection
  • Just trust me (or see the appendix)
  • That means
  • We can represent all of these as (4x4) matrices
  • We can reduce an arbitrary series of these
    operations to a single matrix multiplication
  • Moreover, the hardware designers can make very
    very fast matrix hardware
  • This is what allows us to have fast 3D graphics
    cards

19
display architectures
20
Raw graphics calls
  • The simplest kind of display API just includes
    calls to draw the basic shapes
  • All position and attribute information specified
    in the call
  • DrawLine(start, end, color)
  • DrawRectangle(corner1, corner2, color)
  • DrawEllipse(corner1, corner2, color)
  • DrawString(string, font, size, position)

21
Raw graphics calls
  • The simplest kind of display API just includes
    calls to draw the basic shapes
  • All position and attribute information specified
    in the call
  • DrawLine(start, end, color)
  • DrawRectangle(corner1, corner2, color)
  • DrawEllipse(corner1, corner2, color)
  • DrawString(string, font, size, position)

22
Graphics callswith a transform stack
  • Most systems (GDI, OpenGL, DirectX) also support
    transform matrices
  • System keeps track of a current transform
  • Always applied to shapes as theyre drawn
  • DrawLine(start, end, color)
  • DrawRectangle(corner1, corner2, color)
  • DrawEllipse(corner1, corner2, color)
  • DrawString(string, font, size, position)

23
Graphics callswith a transform stack
  • Most systems (GDI, OpenGL, DirectX) also support
    transform matrices
  • System keeps track of a current transform
  • Always applied to shapes as theyre drawn
  • Transform calls (rotate, translate, etc) change
    the current transform
  • DrawLine(start, end, color)
  • DrawRectangle(corner1, corner2, color)
  • DrawEllipse(corner1, corner2, color)
  • DrawString(string, font, size, position)
  • RotateTransform(angle)
  • TranslateTransform(point)
  • Scale(xscale, yscale)

24
Graphics callswith a transform stack
  • Most systems (GDI, OpenGL, DirectX) also support
    transform matrices
  • System keeps track of a current transform
  • Always applied to shapes as theyre drawn
  • Transform calls (rotate, translate, etc) change
    the current transform
  • Stack calls, remember the current transform and
    restore old transforms
  • DrawLine(start, end, color)
  • DrawRectangle(corner1, corner2, color)
  • DrawEllipse(corner1, corner2, color)
  • DrawString(string, font, size, position)
  • RotateTransform(angle)
  • TranslateTransform(point)
  • Scale(xscale, yscale)
  • Save()
  • Restore()

25
Scene graphs
group
  • Most systems (Meta, Maya, VRML, SVG) represent
    the image as a hierarchy of objects
  • Objects in the hierarchy are also called nodes
  • Nodes can be either
  • Objects (box, sphere, etc.)
  • Groups
  • Groups that also apply transformations (motion,
    scaling, coloring)

rotate
box
box
paint
box
  • Scene graph created for the Meta code
  • group box 100 100 rotate 45
    box 50 50 paint red box 20
    20

26
Rendering a scene graph
group
start
  • Systems render (i.e. draw) a scene graph by doing
    a depth-first traversal of the graph
  • Draw the node
  • Draw all its children (recursively)
  • Pop the transformation stack (if necessary)

Restore
rotate
box
Save RotateTransform
DrawRectangle
Restore
box
paint
DrawRectangle
Save SetColor
box
DrawRectangle
27
Schematic codefor rendering a scene graph
  • define Picture class etc.
  • define Box class Box args
    Picture
  • define Group class Group children
    Picture
  • define Rotated class Rotated angle
    children Group
  • define Painted class Painted color
    children Group
  • define-method draw Group o gfor-each
    child ? draw child g
    o.children
  • define-method draw Box b gg.DrawRectangle
    args
  • define-method draw Rotated r
    gg.Saveg.RotateTransform anglecall-next-m
    ethodg.Restore
  • define-method draw Painted r
    gg.Saveg.SetFill colorcall-next-method
    g.Restore

28
appendix
  • a confusingly terse introduction to matrix
    multiplication

29
Column vectors
  • In the matrix world, we think of vectors as
    skinny matrices called column vectors
  • Sometimes, we also write them as short matrices
    called row vectors

30
Multiplying a matrix and a column vector
  • Multiplying a column vector by a matrix gives us
    the value of the linear function represented by
    the matrix
  • If we think of the matrix as three row vectors,
    Fx, Fy, and Fz piled on top of one another, then
  • The multiplication process is like three dot
    products
  • Each coordinate of the result is a dot product of
    the input vector with its corresponding row
    vector
  • VFx, VFy, or VFz

31
Multiplying a matrix and a column vector
  • The multiplication process is like three dot
    products

32
Multiplying two matrices
  • The product of the matrices for two linear
    functions f(v) and g(v), gives us the matrix for
    the linear function f(g(v))
  • To multiply two matrices, we think of
  • The first matrix as three row vectors, Rx, Ry,
    Rz, and
  • The second matrix as three column vectors, Cx,
    Cy, Cz
  • The matrix product is just all the dot products
    of these vectors

33
Multiplying two matrices
34
appendix 2
  • common matrices in graphics
  • (no, none of this should be intuitively obvious
    to you)

35
Scaling
  • To scale an object by some scale factor c,
    multiply all its points by

36
Stretch
  • To stretch an object along the x axis by some
    scale factor c, multiply all its points by

37
Rotation matrix
  • To rotate an object about the Z axis, rotate all
    its points by
  • Youll have to take my word for it

38
Translation matrix
  • To translate an object by (x, y, z), multiply all
    points by
  • This works because the last coordinate is always
    1, so x always gets added to the x coordinate, y
    to the y coordinate, etc.

39
Perspective projection
  • To do perspective projection, we need to divide
    the x and y coordinates by z
  • We can achieve the same result in homogeneous
    coordinates by multiplying the last (fake)
    coordinate by z
  • Heres the matrix
Write a Comment
User Comments (0)
About PowerShow.com