- 87 Views
- Uploaded on
- Presentation posted in: General

Introduction to 3D Graphics Lecture 2: Mathematics of the Simple Camera

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Introduction to 3D GraphicsLecture 2: Mathematics of the Simple Camera

Anthony Steed

University College London

- Basic Maths
- Points
- Vectors

- Simple Camera
- Scenes with spheres
- COP on +z

- Local illumination
- Ambient
- Diffuse
- Specular

- Basic Maths
- Points
- Vectors

- Simple Camera
- Scenes with spheres
- COP on +z

- Local illumination
- Ambient
- Diffuse
- Specular

- In computer graphics we need mathematics both for describing our scenes and also for performing operations on it, such as projecting and transforming it.
- Coordinate systems (right- and left-handed), serves as a reference point.
- 3 axis labelled x, y, z at right angles.

Y

Y

X

X

Z

Z

Left-Handed System

(Z goes in to the screen)

Right-Handed System

(Z comes out of the screen)

- Gives us a position in relation to the origin of our coordinate system

- Is a direction in 3D space
- Points != Vectors
- Point – Point = Vector
- Vector+Vector = Vector
- Point + Vector = Point
- Point + Point = ?

y

x

Vector addition

sum v + w

w

v

v + w

v

2v

(1/2)V

(-1)v

Scalar multiplication of

vectors (they remain parallel)

w

P

v - w

v

v

w

O

Vector difference

v - w = v + (-w)

Vector OP

- Length (modulus) of a vector V (x, y, z)
- |V| =

- A unit vector

- a · b = |a| |b| cos
cos = a · b/ |a| |b|

- a · b = xa ·xb + ya ·yb + za ·zb
- what happens when the vectors are unit
- if dot product == 0 or == 1?
- This is purely a scalar number not a vector

- The result is not a scalar but a vector which is normal to the plane of the other 2
- direction is found using the determinant
- i(yvzu -zvyu), -j(xvzu - zvxu), k(xvyu - yvxu)

- size is a x b = |a||b|sin
- cross product of vector with it self is null

x(t) = x0 + t(x1 -x0)

y(t) = y0 + t(y1 -y0)

z(t) = z0 + t(z1 -z0)

Given two points P0 = (x0, y0, z0) and

P1 = (x1, y1, z1) the line passing through

them can be expressed as:

P(t) = P0 + t(P1 -P0)

=

With - < t <

hypotenuse

c

b

a

P

r

yp

xp

(0, 0)

- Pythagoras Theorem:
- Given a circle through the origin with radius r, then for any point P on it we have:

a2 + b2 = c2

x2 + y2 = r2

(x-xc)2 + (y-yc)2 = r2

So for the general case

- If the circle is not centered on the origin:

We still have

yp

P

(xp,yp)

a2 + b2 = r2

r

b

b

but

yc

a

(xc,yc)

a = xp-xc

b = yp-yc

xp

xc

(0, 0)

a

- Pythagoras theorem generalises to 3D giving

Based on that we can easily

a2 + b2 + c2 = d2

prove that the general equation of a sphere is:

(x-xc)2 + (y-yc)2 + (z-zc)2 = r2

x2 + y2 + z2 = r2

and at origin:

- Basic Maths
- Points
- Vectors

- Simple Camera
- Scenes with spheres
- COP on +z

- Local illumination
- Ambient
- Diffuse
- Specular

Y

d

ymax

Z

-Z

COP

ymin

(xmax, ymax)

(xmin, ymin)

- Map screen pixels (M by N window) to points in camera view plane

(xmax, ymax)

(M-1, N-1)

(0,0)

(xmin, ymin)

- Consider pixel i,j
- It corresponds to a rectangle
width = (xmax-xmin)/M

height = (ymax-ymin)/N

- Our ray goes through the center of the pixel
- Thus the ray goes through the point
(xmin + width*(i+0.5), ymin + height*(j+0.5), 0.0)

- Thus the ray from the COP through pixel i,j is defined by
p(t) = (x(t), y(t), z(t)) =

(t*(xmin + width*(i+0.5)),

t*(ymin + height*(j+0.5)),

t*d-d)

- Intersection of Sphere and line (sphere at origin)
- Substitute the ray equation in the sphere equation and solve!
- Get an equation in t of the form
At2 + 2Bt + C = 0

If b2 – AC < 0 then the ray doesn’t intersect the sphere.

If b2 -AC = 0 the ray graze (is tangent to the sphere)

If b2 – AC > 0 then there are two roots given by

t = (-b (b2 – AC))/A

chose the highest value one (the one closest to the COP)

- Intersection of Sphere and line (general case)
- Sphere is centred at (a,b,c)
- Translate the start of the ray by (-a,-b,-c)
- Proceed as before

- Basic Maths
- Points
- Vectors

- Simple Camera
- Scenes with spheres
- COP on +z

- Local illumination
- Ambient
- Diffuse
- Specular

- Approximation to global illumination
- Each object is illuminated to a certain extent by “stray” light
- Constant across a whole object

- Often used simply to make sure everything is lit, just in case it isn’t struck by light direct from a light source

- Ambient light usually set for whole scene (Ia)
- Each object reflects only a proportion of that (ka)
- So far then

Ir = kaIa

But we use RGB so

Ir, red = ka,redIa,red

Ir,green = ka,greenIa,green

Ir,blue = ka,blueIa,blue

- Reflected intensity is proportional to cos
- L is the direction to the light
- N is the surface normal

- The normalised intensity of the light incident on the surface due to a ray from a light source
- The light reflected due to Lambert’s law
- The proportion of light reflected rather than absorbed (kd)

- Ambient and diffuse components
- Again kd is wavelength dependent and we work with kd,red kd,green and kd, blue

Ir = kaIa + kdIi (n.l)

- Add the diffuse terms
- Ii,j is the incoming intensity of light j
- lj is the vector to light j

m

Ir = kaIa + kdIi,j (n.l j)

j =1

- Would almost never see the specular highlight

- E is the direction to the eye
- N is the normal
- L is the direction to the light
- H bisects E and L

- m is the power of the light
- High m implies smaller specular highlight
- Low m makes the highlight more blurred

ksIi (h.n)m

- Ambient, diffuse&specular components
- Again if there are multiple lights there is a sum of the specular and diffuse components for each light
(This is the time to worry about clamping values to 0,1 required for monitor display)

Ir = kaIa + Ii (kd (n.l) + ks(h.n)m )

- We can now draw images
- Forming rays from the camera
- Intersecting those rays with objects in the scene
- Colouring the pixels

- Immediate work required
- More interesting scenes
- A useful camera
- At the moment we must move the objects in front of the camera to be able to see them