2IV60 Computer graphics set 7: Basic Geometric Modeling

39
2IV60 Computer graphics set 7: Basic Geometric Modeling Jack van Wijk TU/e

description

2IV60 Computer graphics set 7: Basic Geometric Modeling. Jack van Wijk TU/e. Geometric modeling 1. The world is full of all kind of objects: Trees, people, cars, housed, clouds, rocks, waves, pencil sharpeners, fire, mountains, plants, … How can we describe these, such that they are - PowerPoint PPT Presentation

Transcript of 2IV60 Computer graphics set 7: Basic Geometric Modeling

Page 1: 2IV60 Computer graphics set 7: Basic Geometric Modeling

2IV60 Computer graphicsset 7: Basic Geometric Modeling

Jack van Wijk

TU/e

Page 2: 2IV60 Computer graphics set 7: Basic Geometric Modeling

Geometric modeling 1

The world is full of all kind of objects:Trees, people, cars, housed, clouds, rocks, waves,

pencil sharpeners, fire, mountains, plants, …

How can we describe these, such that they are- easy to enter; - easy to process;- easy to display?

Complex problem, HUGE topic!

Page 3: 2IV60 Computer graphics set 7: Basic Geometric Modeling

Geometric modeling 2

Input:

• by user- preferably on a high level, customized to

application

• by scanning objects- laser scanners: points- medical scanners: voxels

Page 4: 2IV60 Computer graphics set 7: Basic Geometric Modeling

Geometric modeling 3

triangles

User

Scanner conversion

conversion

graphicspipeline

image

3D points,voxels

Instructions,specifications

Page 5: 2IV60 Computer graphics set 7: Basic Geometric Modeling

Smooth Curves (2D)

Two standard methods:

• Parametric: X(t) = (x(t), y(t))

• Implicit: f(x, y) = 0

H&B A-8,9:772-774

Page 6: 2IV60 Computer graphics set 7: Basic Geometric Modeling

Parametric description line 1

Given point P and vector V:

X(t) = P + Vt

Given two points P en Q:

X(t) = P + (Q P)t , or

= P(1t) + Qt

Segment: tmin t tmax

x

y

P

V

t

Q

H&B A-8,9:772-774

Page 7: 2IV60 Computer graphics set 7: Basic Geometric Modeling

Parametric description curve

• X(t) = (x(t), y(t))

• Drawing a curve in a simple way,

approximate with a polyline:

MoveTo(X(0));

for i := 1 to N do LineTo(X(it));

H&B A-8,9:772-774

Page 8: 2IV60 Computer graphics set 7: Basic Geometric Modeling

Drawing a curve with OpenGL 1

X(float t):Point;

{ P[0]= …; P[1]=…; P[2]=…; return P; };

DrawX(); {N = 12; // use symbolic name for the number of segments

int i;

float dt := (tmax – tmin)/N;glBegin(GL_LINE_STRIP); // GL_LINE_LOOP if closed curvefor (i = 0; i <= N; i++) // bounds here: 0 - N

glVertex3fv(X(tmin + i*dt));

glEnd();

} H&B 4-5:82-83

Page 9: 2IV60 Computer graphics set 7: Basic Geometric Modeling

Drawing a curve with OpenGL 2

• Using too few points: – jagged appearance;

• Using too many points: – slow, – fat appearance (many segments per pixel).

H&B 4-5:82-83

Page 10: 2IV60 Computer graphics set 7: Basic Geometric Modeling

Drawing a curve with OpenGL 3

• Decide on #points: – characteristics shape;– size of shape on screen.– beforehand or adjust automatically.

H&B 4-5:82-83

Page 11: 2IV60 Computer graphics set 7: Basic Geometric Modeling

Implicit description line

• (X P).N = 0

with N.V = 0

(N: normal vector)

• Also:

ax+by+c=0 x

y

P

V

N

H&B A-8,9:772-774

Page 12: 2IV60 Computer graphics set 7: Basic Geometric Modeling

Implicit description curve

f >0

f <0

f = 0

f =-1

f = 1

f =-2

H&B A-8,9:772-774

Page 13: 2IV60 Computer graphics set 7: Basic Geometric Modeling

Circle

0

:ric)nonparamet(or Implicit

10

),2sin,2cos(),(

:Parametric

222

ryx

t

trtryx x

y

r

H&B A-8,9:772-774

Page 14: 2IV60 Computer graphics set 7: Basic Geometric Modeling

Curves (3D)

Two standard methods:

• Parametric: X(t) = (x(t), y(t), z(t))

• Implicit: f(x, y, z) = 0 and g(x, y, z) = 0Intersection of two surfaces

H&B A-8,9:772-774

Page 15: 2IV60 Computer graphics set 7: Basic Geometric Modeling

Circle in 3D

0

and 0

:Implicit

10

),0,2sin,2cos(),,(

:Parametric

222

z

ryx

t

trtrzyx

x

y

r

z

H&B A-8,9:772-774

Page 16: 2IV60 Computer graphics set 7: Basic Geometric Modeling

Surfaces

H&B A-8,9:772-774

• Polyhedra

• Parametric surfaces

• Implicit surfaces

Page 17: 2IV60 Computer graphics set 7: Basic Geometric Modeling

Polyhedra

• Set of polygons that describe the surface of an object

• Often only triangles (hardware!)

• Many variations for storage (zie H&B 4-7)

• Often additional information per vertex (color, normal, texture, …)

H&B 13-1:418

Page 18: 2IV60 Computer graphics set 7: Basic Geometric Modeling

Curved surfaces

• Parametric: X(u,v) = (x(u,v), y(u,v), z(u,v))

• Implicit: f(x, y, z) = 0

H&B 13-3:421-422

Page 19: 2IV60 Computer graphics set 7: Basic Geometric Modeling

Sphere 1

1,0

)cos(),(

)sin()2sin(),(

)sin()2cos(),(

:Parametric

vu

vrvuz

vurvuy

vurvux

x

yz

v constant, u varies

u constant, v varies

H&B 13-4:422-424

Page 20: 2IV60 Computer graphics set 7: Basic Geometric Modeling

Sphere 2

x

y

H&B A-8,9:807-808

z

v constant, u varies

u constant, v varies1,0

,/,/with

),(),(

),(),(

:ices with vertfacets Make

:Display

111

1

Nji

NjvNiu

,vu,vu

,vu,vu

NN

ji

jiji

jiji

XX

XX

u

v

Page 21: 2IV60 Computer graphics set 7: Basic Geometric Modeling

Sphere 3

parts. in two space divides Again,

No :0),,(

Yes :0),,(

:object inside is ),,(punt ifTest

0),,(

:ndescriptioImplicit 2222

f

zyxf

zyxf

zyx

rzyxzyxf

x

yz

H&B 13-4:422-424

Page 22: 2IV60 Computer graphics set 7: Basic Geometric Modeling

Partial Derivatives 1

y

yxfyyxf

y

yxfyxf

x

yxfyxxf

x

yxfyxf

x

xfxxf

dx

xdfxf

y

x

x

),(),(lim

),(),(

),(),(lim

),(),(

: variables twooffunction for sderivative Partial

)()(lim

)()('

: variableone offunction for derivative Standard

0y

0x

0

H&B A10:774

Page 23: 2IV60 Computer graphics set 7: Basic Geometric Modeling

Partial Derivatives 2

2

32

9),(

: ation todifferenti standard

apply and constant, as consider , toderivative partial For the

4),(

: ation todifferenti standard

apply and constant, as consider , toderivative partial For the

32),(:Example

yxx

yxf

y

xy

yxx

yxf

x

yx

yxyxyxf

H&B A10:774

Page 24: 2IV60 Computer graphics set 7: Basic Geometric Modeling

Normal on surface 1

vector. velocity a is )( then time,is if:Note

)(,

)(,

)()(

:ctorTangent ve

))(),(),(( )( curve Parametric

:Given

uu

du

udz

du

udy

du

udxu

uzuyuxu

T

T

P

H&B A-10:774-775

T(u)

P(u)

u

Page 25: 2IV60 Computer graphics set 7: Basic Geometric Modeling

Normal on surface 2

),(,

),(,

),(),(

:direction-in ctor Tangent ve

),(,

),(,

),(),(

:direction-in ctor Tangent ve

)),(),,(),,(( ),( surface. Parametric

:Given

v

vuz

v

vuy

v

vuxvu

v

u

vuz

u

vuy

u

vuxvu

u

vuzvuyvuxvu

v

u

T

T

P

Tu(u,v)

P(u,v)

u

Tv(u,v)

v

H&B A-10:774-775

Page 26: 2IV60 Computer graphics set 7: Basic Geometric Modeling

Normal on surface 3

),( ),(),(

:surface toNormal surface. of

plane in tangent are ),( and ),(

),(,

),(,

),(),(

:direction-in ctor Tangent ve

),(,

),(,

),(),(

:direction-in ctor Tangent ve

vuvuvu

vuvu

v

vuz

v

vuy

v

vuxvu

v

u

vuz

u

vuy

u

vuxvu

u

vu

vu

v

u

TTN

TT

T

T

Tu(u,v)

P(u,v)

u

Tv(u,v)

v

N

H&B A-10:774-775

Page 27: 2IV60 Computer graphics set 7: Basic Geometric Modeling

Normal on surface 4

0 ),2sin( ),2cos(2

0 ),2sin(2 ),2cos(2

),(),(),(

,0 ,0

/),( ,/),( ,/),(),(

0 ),2cos(2 ),2sin(2

/),( ,/),( ,/),(),(

),(

)2sin(),(

)2cos(),(

:1,0 with ,height and radiusith cylinder w Example

uurh

ururh

vuvuvu

h

vvuzvvuyvvuxvu

urur

uvuzuvuyuvuxvu

hvvuz

urvuy

urvux

vuhr

vu

v

u

TTN

T

T

xy

z

v

u

Tu

Tv

N

H&B A-10:774-775

Page 28: 2IV60 Computer graphics set 7: Basic Geometric Modeling

Normal on surface 5

),(

),(

),(

)sin(2

)cos()sin()2(cos2)cos()sin()2(sin2

)(sin)2sin(2

)(sin)2cos(2

),(),(

)sin( ),cos()2sin( ),cos()2cos(),(

0 ),sin()2cos(2 ),sin()2sin(2),(

)cos(),(

)sin()2sin(),(

)sin()2cos(),(

:sphere Example

2

222222

222

222

vuz

vuy

vux

vr

vvurvvur

vur

vur

vuvu

vrvurvurvu

vurvurvu

vrvuz

vurvuy

vurvux

vu

v

u

TT

T

T

H&B A-10:774-775

Page 29: 2IV60 Computer graphics set 7: Basic Geometric Modeling

Normal on surface 6

increasefastest ofdirection

,,

grad) is ( ),,(),,(

: vectorNormal

0),,( surfaceImplicit

:Given

f

z

f

y

f

x

f

zyxfzyx

zyxf

N

N(x,y,z)

(x,y,z)

f(x,y,z)=0

H&B A-10:774-775

Page 30: 2IV60 Computer graphics set 7: Basic Geometric Modeling

Normal on surface 7

f >0

f <0

f = 0

H&B A-10:774-775

Page 31: 2IV60 Computer graphics set 7: Basic Geometric Modeling

Normal on surface 8

)0,2,2(

,,),,(

0),,(

:1,0with

,height and radius

cylinder, Example

222

yx

z

f

y

f

x

fzyx

ryxzyxf

vu

hr

N

xy

z

N

H&B A-10:774-775

Page 32: 2IV60 Computer graphics set 7: Basic Geometric Modeling

Quadratic surfaces 1

allyparametric described beeasily alsoCan

0),,( :cone

0),,( :sphere

0),,( :cylinder

:Example

0

0),,(equation degree Second

:surfaces Quadratic

222

2222

222

222

zyxzyxf

rzyxzyxf

ryxzyxf

jizhygxfyzexzdxyczbyax

zyxf

xy

z

H&B 13-4:422-424

Page 33: 2IV60 Computer graphics set 7: Basic Geometric Modeling

Quadratic surfaces 2

01),,( :ellipsoid

0),,( :sphere

cigar) (mentos, sphere scaled :Ellipsoid

222

2222

c

z

b

y

a

xzyxf

rzyxzyxf

xy

z

ac

b

H&B 13-4:422-424

Page 34: 2IV60 Computer graphics set 7: Basic Geometric Modeling

Quadratic surfaces 3

0)(),,( :Generic

0)(),,( :plane 0In

surface) 4 (degree car tyre donut, :Torus

22222

222

rzryxzyxf

rzryzyxfx

a

a

(0, y, z)

y as

ra

r

z asy (x, y, z)

y as

x as H&B 13-4:422-424

Page 35: 2IV60 Computer graphics set 7: Basic Geometric Modeling

Drawing surfaces with OpenGL 1

• Quadratic surfaces: GLU and GLUT offer some basic functions:– glutSolidSphere(r, nLon, nLat);– glutSolidCone(rbase, rheight, nLon, nLat);– glutSolidTeapot(size);– gluSphere, gluCylinder,

• Teapot? – Google: Utah teapot;– Google: Stanford bunny.

H&B 13-6:425-431

Page 36: 2IV60 Computer graphics set 7: Basic Geometric Modeling

Drawing surfaces with OpenGL 1

• Quadratic surfaces: GLU and GLUT offer some basic functions:– glutSolidSphere(r, nLon, nLat);– glutSolidCone(rbase, rheight, nLon, nLat);– glutSolidTeapot(size);– gluSphere, gluCylinder,

• Alternative: Define your own, custom versions, based on standard way to render parametric surfaces.

H&B 13-6:425-431

Page 37: 2IV60 Computer graphics set 7: Basic Geometric Modeling

Drawing surfaces with OpenGL 2X(float u, v):Point; { P[0]= …; P[1]=…; P[2]=…; return P; };

DrawX(); {NU, NV = 12; // use symbolic names for numbers of points againint i, j;float du := (umax – umin)/NU; float dv := (vmax – vmin)/NV;

for (j = 0; j < NV; j++) { glBegin(GL_QUAD_STRIP);

for (i = 0; i <= NU; j++) { glVertex3fv(X(umin + i*du, vmin + j*dv));glVertex3fv(X(umin + i*du, vmin +

(j+1)*dv));}glEnd();

}

Page 38: 2IV60 Computer graphics set 7: Basic Geometric Modeling

Drawing surfaces with OpenGL 3

Many variations possible– using triangle strips;– inserting normals, shading info, texture, ...

Selecting the number of facets:– too few: jagged appearance;– too many: slow;– decide beforehand or automatically, based

on size on screen and curvature surface.H&B 4-5:82-83

Page 39: 2IV60 Computer graphics set 7: Basic Geometric Modeling

Next…

• We now know how to define basic objects.

• Stay tuned for splines: arbitrary curves and curved surfaces.

• But first: let’s consider illumination and shading.