Docsity

Trigonometry and Parametric Functions in 3D Computer Graphics, Slides of Fundamentals of E-Commerce

Partial preview of the text

Download Trigonometry and Parametric Functions in 3D Computer Graphics and more Slides Fundamentals of E-Commerce in PDF only on Docsity!

3D Computer Graphics

Time permitting: Linear Interpolation

Animating parametric surfaces

Trigonometry Review • Sin() and cos() connect

angles

to^ coordinates

P = (x,y)^ X+

X-

Y+ Y-

theta

Trigonometry Review

-^ Angles and co-ordinates^ –^

The^ unit circle

is the set of all points exactly one unit away from the origin. In fact, radians measure arclength on theunit circle. (The unit circle has a circumference of 2

π.)

-^ sin()

and^ cos()

are functions that give the vertical and horizontal positions (respectively) of a point on the unitcircle at angle

theta.

theta^

X+

Y+

(x,y)

^ Ex:^ cos(0°

)^ = 1;^ sin(0°

)^ = 0; so

if P=(X,Y) andX = cos(0)Y = sin(0)thenP=(1,0)

Trigonometry Review

-^ Angles, co-ordinates, and radius^ –

sin() and cos() return the (X,Y) co-ordinates on theunit circle. – To get a bigger circle, multiply sin() and cos() by a^ radius

. The

radius

is the distance from the origin.

-^ For example, say theta=45° and r=5.Then X=rcos(theta) and Y=rsin(theta), orX=5cos(45°) and Y=5sin(45°).

theta^

X+

Y+

(x,y)

^ In general, when you work withsin() and cos(), just remember:if you multiply them both by thesame value, you’re

changing

the size of the circle

they work

in.

Parametric Functions

•^ The idea of

parametric functions

is the idea that you

can have two variables and one depends on the otherbut the other doesn’t depend on the one.^ –^ X=cos(t) is a parametric function. X

is a function of

t, but t

can be whatever it wants to be. – You can say that a parametric function is a function

in n

dimensions

where n is the number of independent

variables.^ •^ Y=f(x) is

in one dimension

.

-^ X=sin(t), Y=cos(t) are

in one dimension

and produce 2D results.

•^ Z=f(x,y) is in two dimensions, and produces 3D output. – The Three Musketeers are not a parametric function.

Parametric Functions • To draw a parametric function in one dimension with 2D or 3D outputsin OpenGL: void^ drawFunction(void){ double

x,^ y; double

t; glBegin(GL_LINE_STRIP);for^ (t

=^ -5;

t<=5;

t+=0.01)

{^ evalFn

(t,^ x,

y); glVertex3f(x,y,0);} glEnd();}

void^ evalFn(double

t, double

&x, double

&y) { x^ =^

cos(t);y = sin(t);

} ...will draw a circle.

Parametric Functions - Examples

Parametric Functions

•^ Rendering 2Dsurfaces ismore complex--you need to^ render all four

void drawFunction(void){ Vec^ A,

B, C,^

D;

for^ (double

u^ =^ -1;

u<=1; u+=0.1) for^ (double

v^ =^ -1;

v<=1;^

v+=0.1)

{ A^ =^ evalFn(u,

v); B^ =^ evalFn(u,

v+0.1); C^ =^ evalFn(u+0.1,

v+0.1); D^ =^ evalFn(u+0.1,

v); glBegin(GL_QUADS);glVertex3f(A.x(),A.y(),A.z());glVertex3f(B.x(),B.y(),B.z());glVertex3f(C.x(),C.y(),C.z());glVertex3f(D.x(),D.y(),D.z());glEnd();} }

Vec^ evalFn(double

u,double v) { double

x,^ y,^

z; x^ =^ cos(PIu)sin(PI*(v-1)/2);y^ =^

cos(PI(v-1)/2); z^ =^ sin(PIu)sin(PI(v-1)/2);return^ Vec(x,y,z);}