linear interpolation

34
Linear Interpolation • If a=1, • If a=0, • If a=0.5, Midterm_Grade=a*Old_Grade+(1-a)*New_Grade The original grade The grade after you redo Some problems Midterm_Grade = 1*Old_Grade+0*New_Grade = Old_Grade Midterm_Grade = 0*Old_Grade+1*New_Grade = New_Grade Midterm_Grade = 0.5*Old_Grade+0.5*New_Grade =(Old_Grade+New_Grade)*0.5

Upload: niles

Post on 22-Feb-2016

30 views

Category:

Documents


0 download

DESCRIPTION

Linear Interpolation. The original grade. Midterm _Grade =a* O ld_Grade+(1-a)* New_Grade. The grade after you redo Some problems. Midterm _Grade = 1* O ld_Grade+0* New_Grade = Old_Grade. If a=1, If a=0, If a=0.5,. Midterm _Grade = 0* O ld_Grade+1* New_Grade = New _Grade. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Linear Interpolation

Linear Interpolation

• If a=1,

• If a=0,

• If a=0.5,

Midterm_Grade=a*Old_Grade+(1-a)*New_Grade

The original grade

The grade after you redo Some problems

Midterm_Grade = 1*Old_Grade+0*New_Grade = Old_Grade

Midterm_Grade = 0*Old_Grade+1*New_Grade = New_Grade

Midterm_Grade = 0.5*Old_Grade+0.5*New_Grade =(Old_Grade+New_Grade)*0.5

Page 2: Linear Interpolation

Linear Interpolation

• Now if you change the grade into two vertices:

V0

V1

Va=a*V1+(1-a)*V0

a=1

a=0

V0.5

a=0.5a=0.25

a=0.75

a>1

a<0This is how we define a line, a line segment, or a ray.

Page 3: Linear Interpolation

Linear Interpolation

• Now if know V1, V2, and V, how do you know a instead?

• We know:

V0

V1

V=a*V1+(1-a)*V0

Va

V-V0=a*(V1-V0)

a=|V-V0|/|V1-V0|

|V1-V0|

|V-V0|

Page 4: Linear Interpolation

Linear Interpolation• Now if you have two values C0 and C1 (color, depth, texture

coordinates…) at V0 and V1, how to get the value Ca at V:

V0

V1

Ca=a*C1+(1-a)*C0

Va

|V1-V0|

|V-V0|

C0

C1

Ca???

a=|V-V0|/|V1-V0|

Page 5: Linear Interpolation

Midterm Grading Formula

• Option 1: No new grade, just curve it. (a=1)

• Option 2: Redo two questions, take the average and curve it. (a=0.5)

• Option 3: Redo two questions, take the average but no curve. (a=0.5, b=1)

• Option 4: Redo all questions, take the average but no curve. (a=0.5, b=1)

Midterm_Grade=(a*Old_Grade+(1-a)*New_Grade)b

a: Interpolation coefficient b: Curve coefficient

Page 6: Linear Interpolation

Midterm Grading Formula• Redo two questions• Pro: less work for you (and for me)• Con: depends on the choice of questions, not very

fair for some people:• A: 3+3+3+3+3=15 (old); 3+5+5+3+3=19 (new).• B: 5+0+0+5+5=15 (old); 5+5+5+5+5=25 (new).

• Redo all questions• Con: more work• Pro: you get the second chance to learn; and it is

relatively fair

Page 7: Linear Interpolation

Midterm Grading Formula

• Details:

• Return the graded old exam package to you now (on Wednesday). So you know which answer is wrong and which is right.

• Only the old grade, but not the exam package. You know your overall performance, but don’t know which answer is wrong exactly.

• After you submit your new answers, you will get the graded old exam package.

Page 8: Linear Interpolation

Homogenous Space Vs. 3D Space

xyz

⎢⎢⎢

⎥⎥⎥

A point in the 3D Space

xyz1

⎢⎢⎢⎢

⎥⎥⎥⎥

A point in the homogenous Space (4D)

xyz

⎢⎢⎢

⎥⎥⎥

A point in the 3D Space

xyz1

⎢⎢⎢⎢

⎥⎥⎥⎥

A point in the homogenous Space

Page 9: Linear Interpolation

Homogenous Space Vs. 3D Space

a wb wc w

⎢⎢⎢

⎥⎥⎥=

xyz

⎢⎢⎢

⎥⎥⎥

A point in the 3D Space

abcw

⎢⎢⎢⎢

⎥⎥⎥⎥

A point in the homogenous Space

a wb wc ww w

⎢⎢⎢⎢

⎥⎥⎥⎥=

a wb wc w1

⎢⎢⎢⎢

⎥⎥⎥⎥

What if w is not 1? Scale it by 1/w!

Page 10: Linear Interpolation

Projection and Transformation

xyz

⎢⎢⎢

⎥⎥⎥

A point in the 3D Space

xyz1

⎢⎢⎢⎢

⎥⎥⎥⎥

A point in the homogenous Space (4D)

a b c de f g hi j k lm n o p

⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥

xyz1

⎢⎢⎢⎢

⎥⎥⎥⎥

Multiply it by your matrix

abcw

⎢⎢⎢⎢

⎥⎥⎥⎥

Your result in the homogenous Space (4D)

a wb wc w

⎢⎢⎢

⎥⎥⎥

Your solution in 3D!

Page 11: Linear Interpolation

Projection and Transformation

xyz

⎢⎢⎢

⎥⎥⎥

abc1

⎢⎢⎢⎢

⎥⎥⎥⎥

Transformation won’t change w. w is always 1.

xyz1

⎢⎢⎢⎢

⎥⎥⎥⎥

M

xyz1

⎢⎢⎢⎢

⎥⎥⎥⎥

xyz

⎢⎢⎢

⎥⎥⎥

abcw

⎢⎢⎢⎢

⎥⎥⎥⎥

Projection changes w!

xyz1

⎢⎢⎢⎢

⎥⎥⎥⎥

P

xyz1

⎢⎢⎢⎢

⎥⎥⎥⎥

a wb wc w

⎢⎢⎢

⎥⎥⎥

Depth Value(Z value)

2D image location

Page 12: Linear Interpolation

Transformation

x 'y 'z '1

⎢⎢⎢⎢

⎥⎥⎥⎥

A point in an absolute space

xyz1

⎢⎢⎢⎢

⎥⎥⎥⎥

M

xyz1

⎢⎢⎢⎢

⎥⎥⎥⎥

Its changed position in the absolute space

One way to understand the transformation:

Page 13: Linear Interpolation

Transformation

x 'y 'z '1

⎢⎢⎢⎢

⎥⎥⎥⎥

A point in one space

xyz1

⎢⎢⎢⎢

⎥⎥⎥⎥

M

xyz1

⎢⎢⎢⎢

⎥⎥⎥⎥

The same point, but in a new space

Another way to understand the transformation:

Page 14: Linear Interpolation

Transformationx 'y 'z '1

⎢⎢⎢⎢

⎥⎥⎥⎥

A point in the local space(or called the model space)

xyz1

⎢⎢⎢⎢

⎥⎥⎥⎥

Mmodelview

xyz1

⎢⎢⎢⎢

⎥⎥⎥⎥

A point in the eye space(or called the camera space)

x 'y 'z '1

⎢⎢⎢⎢

⎥⎥⎥⎥

A point in the local space(or called the model space)

xyz1

⎢⎢⎢⎢

⎥⎥⎥⎥

Mmodelview−1

x'y'z'1

⎢⎢⎢⎢

⎥⎥⎥⎥

A point in the eye space(or called the camera space)

Page 15: Linear Interpolation

Transformation

glLoadIdentity();glRotatef(…);glTranslatef(…);glScalef(…);glBegin(GL_POINTS);glVertex3fv(v);glEnd();

I

R

T

S

Mmodelview =I

Mmodelview =IR

Mmodelview =IRT

Mmodelview =IRTS

(eye space -> eye space)

(space No. 1 -> eye space)

(space No. 2 -> eye space)

(space No. 3 -> eye space)

Mmodelviewv=IRTSv=v'(space No. 3 -> eye space)

Page 16: Linear Interpolation

Transformation

Mmodelview =

m 00 m 01 m 02 m 03

m 10 m 11 m 12 m 13

m 20 m 21 m 22 m 23

1

⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥

The matrix not only transforms a vertex from the localspace into the eye space, it also tells us how the local space looks like in the eye space:

The local OriginThe local Y axis

The local X axis The local Z axis

Page 17: Linear Interpolation

Transformation

glLoadIdentity();//Camera motions (also as transformation)

//Do more transformations

glBegin(GL_POINTS);glVertex3fv(v);glEnd();

Eye space

World space

Local space

Mviewing

Mmodeling

Mmodelview

OpenGL only has the modelview matrix, which really contains two steps: viewing and modeling.

Page 18: Linear Interpolation

Shading

V0 V1

Phong ShadingVs

f(Vs)f(V0) f(V1)

• Now you did projection, you have polygons in 2D.• You do rasterization, so you have scanlines. Each line have

two endpoints and you have a lot of pixels between them.• Suppose you have a function f(x) that can give you a value at

any point, how do you use it to get a value for each pixel?

Page 19: Linear Interpolation

Shading

V0 V1

• Now you did projection, you have polygons in 2D.• You do rasterization, so you have scanlines. Each line have

two endpoints and you have a lot of pixels between them.• Suppose you have a function f(x) that can give you a value at

any point, how do you use it to get a value for each pixel?

Flat ShadingVs

f(V0)f(V0) f(V0) f(V0) f(V0) f(V0)

Page 20: Linear Interpolation

Shading

V0 V1

Gouroud ShadingVs

sf(V1)+(1-s)f(V0)f(V0) f(V1)

• Now you did projection, you have polygons in 2D.• You do rasterization, so you have scanlines. Each line have

two endpoints and you have a lot of pixels between them.• Suppose you have a function f(x) that can give you a value at

any point, how do you use it to get a value for each pixel?

Page 21: Linear Interpolation

Geometric Modeling

Page 22: Linear Interpolation

Basic GLUT Shapes• Spheres

• Cones

• Cubes

glutWireSphere(radius, slices, stacks)

glutSolidSphere(radius, slices, stacks)

glutWireCone(radius, height, slices, stacks)

glutSolidCone(radius, height, slices, stacks)

glutWireCube(size)

glutSolidCube(size)

Page 23: Linear Interpolation

Basic GLUT Shapes• Torus

• Teapot

• Polyhedron

glutWireTorus(inner_radius, outer_radius, slices, stacks)

glutSolidTorus(inner_radius, outer_radius, slices, stacks)

glutWireTeapot(size)

glutSolidTeapot(size)

glutWireDodecahedron(void)

glutWireOctahedron(void)

glutWireTetrahedron(void)

glutWireIcosahedron(void)

Page 24: Linear Interpolation

Basic GLUT Shapes• GLUT shapes and normals are pre-defined.

• They are typically centered at the origin.

• To move them to suitable locations, you should apply transformations to them.

• Most of them do not have texture coordinates. (But the teapot has texture coordinates. Someone must really like the teapot…)

Page 25: Linear Interpolation

About the Teapot• It was created by Martin Newell at the University of Utah in

1975.

• It was the unofficial graphics mascot. (What is the current one?)

• Pixar gave away free teapot toys every year during ACM SIGGRAPH conference. Try to get one if you have chance.

Page 26: Linear Interpolation

Basic GLU Shapes• GLU also has some primitive shapes.

• The draw style: GL_FILL, GL_LINE, GL_SILHOUETTE, GL_POINT.

• The orientation: GL_OUTSIDE, GL_INSIDE.• Normal: GL_NONE, GL_FLAT, GL_SMOOTH.• Texture: GL_FALSE, GL_TRUE.

GLUquadric* quad= gluNewQuadric();gluQuadricDrawStyle(quad, draw);gluQuadricOrientation(quad, orientation);gluQuadricNormals(quad, normal);gluQuadricTexture(quad, texture);gluCylinder(quad, base, top, height, slices, stacks);gluDeleteQuadric(quad);

Page 27: Linear Interpolation

Basic GLU Shapes

• More complicated to use (than GLUT shapes).

• But they also have more options.

• Still not flexible enough to change many things.

Page 28: Linear Interpolation

Parametric Surfaces

• A sphere can be defined the polar coordinates/spherical coordinates (θ, ϕ).

xyz

⎢⎢⎢

⎥⎥⎥=

rsinθ sinφrcosφrcosθsinφ

⎢⎢⎢

⎥⎥⎥

0 ≤θ ≤2π0 ≤φ ≤π

Page 29: Linear Interpolation

Creating a Sphere• The basic idea is to sample over (θ, ϕ).

2D Parameter Space 3D Space

θ

ϕ

(0, 0)

(2π, π)

(i, j) (i+1, j)

(i, j+1) (i+1, j+1)

Page 30: Linear Interpolation

Creating a Sphere• The code

for(i=0; i<n; i++)for(j=0; j<n; j++){

theta=i*2*PI/n;phi =j*PI/n;next_theta=(i+1)*2*PI/n;next_phi =(j+1)*PI/n;glBegin(GL_QUAD);glVertex3f(…i , j… );glVertex3f(…i+1, j… );glVertex3f(…i+1, j+1…);glVertex3f(…I , j+1…);glEnd();

}

Page 31: Linear Interpolation

Parametric Surfaces

• An ellipsoid is a scaled sphere.

xyz

⎢⎢⎢

⎥⎥⎥=

rx sinθsinφrycosφ

rz cosθsinφ

⎢⎢⎢

⎥⎥⎥

0 ≤θ ≤2π0 ≤φ ≤π

Page 32: Linear Interpolation

Creating an Ellipsoid

• The basic idea is the same as creating a sphere, except that it uses different radii for different axes.

• It is wrong to create a sphere and then simply scale it. Why?

• Normal calculation is not straightforward. It needs more math, or some approximation.

Page 33: Linear Interpolation

Creating a Cylinder• The basic idea is to sample over (θ, h).

2D Parameter Space 3D Space

θ

h

(0, 0)

(2π, H)

(i, j) (i+1, j)

(i, j+1) (i+1, j+1)

Page 34: Linear Interpolation

Creating a Cylinder• The code

for(i=0; i<n; i++)for(j=0; j<n; j++){

theta=i*2*PI/n;phi =j*H/n;next_theta=(i+1)*2*PI/n;next_phi =(j+1)*H/n;glBegin(GL_QUAD);glVertex3f(…i , j… );glVertex3f(…i+1, j… );glVertex3f(…i+1, j+1…);glVertex3f(…I , j+1…);glEnd();

}

xyz

⎢⎢⎢

⎥⎥⎥=

rsinθhrcosθ

⎢⎢⎢

⎥⎥⎥

0 ≤θ ≤2π0 ≤h≤H