103
Suriyong L. Geometric Objects and Transformations Coordinate systems and frames Working with representation Object transformation

Geometric Objects and Transformations

  • Upload
    gusty

  • View
    85

  • Download
    0

Embed Size (px)

DESCRIPTION

Geometric Objects and Transformations. Coordinate systems and frames Working with representation Object transformation. Introduction. Mathematical of Object Euclidean vector spaces Vector space with measure of size Independent of coordinate system Parametric form system. - PowerPoint PPT Presentation

Citation preview

Page 1: Geometric Objects and Transformations

Suriyong L.

Geometric Objects and Transformations

Coordinate systems and framesWorking with representation

Object transformation

Page 2: Geometric Objects and Transformations

Suriyong L.

Introduction

• Mathematical of Object– Euclidean vector spaces

• Vector space with measure of size– Independent of coordinate system

• Parametric form system

Page 3: Geometric Objects and Transformations

Suriyong L.

Scalars, Points, and Vectors

• Geometric object description in space– By length, angle– With 3 fundamental types scalars, points and

vector

Page 4: Geometric Objects and Transformations

Suriyong L.

The geometric View

• Point : a location in the space– Mathematical for point

• Neither a size nor shape– Properties

• location– What for :

• Specify an object

Page 5: Geometric Objects and Transformations

Suriyong L.

Scalars

• Quantity of object or relation objects• Ex. Distance between object• Specify with real / complex number• Useful rule for scalar

– communitivity and Associativity in multiplicity, additivity

– Ex. a+b = b+a, (a+b)+c = a+(b+c)

Page 6: Geometric Objects and Transformations

Suriyong L.

Vector

• Quantity with direction and magnitude ex. velocity, force– Does not have a fixed position in space– Synonymously to line segment

• Computer graphics often connect points with directed line segment– Line segment: a segment of line which

has both magnitude and direction

Directed line segment that connects points

Identical vectors

Page 7: Geometric Objects and Transformations

Suriyong L.

Vector properties• Its lengths changed by real number• B = 2A

– B is double in size to vector A with the same direction• Vector combining: (addition)

– Use head to tail combining, the result is the sum of the vector– Any vector in space is able to do addition, independent of its location– Scalar-vector addition make sense: ex. A + 2B – 3C

• Inverse vector:– The vector that has opposite direction to the original vector

Parallel line segments

Addition of line segments Inverse vectors

Page 8: Geometric Objects and Transformations

Suriyong L.

Vector operation• Scalar multiplying

– Result change in length (magnitude) • Point-vector addition

– Result change in displacement to the new point position

• Point-point subtraction– Result is a vector between 2 points

• Note: Some expression involving scalars, vectors and

points make sense ex. P+3v, or P-2Q+3v while P+3Q-v do not

Point-vector addition

Page 9: Geometric Objects and Transformations

Suriyong L.

Coordinate-free geometry

• For graphics system let the object relate to each other but independent of coordinate system

• Let object relate to an arbitrary location and orientation of the original axis

Object and coordinate system

Object without coordinate system

Page 10: Geometric Objects and Transformations

Suriyong L.

The mathematical view: Vector and Affine Spaces

• Scalar operation– Addition , multiplication

• If operation obey closure, associativity, commutivity and inverse properties, the element form a scalar field

– Ex. field . Real number, complex number, rational function

Page 11: Geometric Objects and Transformations

Suriyong L.

Vector space

• 2 distinct type of entities in vector space– Scalar and vector

• Scalar-vector multiplication– Vector and vector

• Vector – vector addition

• Euclidean space– Extension of vector space– Add a measure of size or distance to define object– Ex. Length of line segment

Page 12: Geometric Objects and Transformations

Suriyong L.

Affine space (space of transformation)

• Extension of vector space– Include point to vector space– Have vector-point addition and point-point

operation

Page 13: Geometric Objects and Transformations

Suriyong L.

Computer Science View• Prefer to see object as

abstract data type (ADT)• Operations and data are

defined independently• Fundamental to modern

computer science• Like C++ language features :

class and overloading

Computational point of view declaration (Independent of data type declaration)

Operation that independent of data type

vector u,v;point p,q;scalar a, b;

q = p+a*v;

Page 14: Geometric Objects and Transformations

Suriyong L.

Geometric ADT

• Learn how to perform geometric operation and forming geometric object

• Let Greek letter a, b, g,... : scalars

Upper-case letter P, Q, R,… : points

Bold lower-case letters u, v, w,… : vector

Page 15: Geometric Objects and Transformations

• The operation of vector-scalar multiplication

• Subtraction of two points, P and Q -> vector v

• Add vector with point get point

• Vector-vector operation can be in point form

Suriyong L.

Point-point subtraction

Use of the head-to-tail rule(a) For vectors, (b)For points

Page 16: Geometric Objects and Transformations

Suriyong L.

Lines

• General term definition• Called parametric form of line• Point generating by varying alpha• Line is infinity in length• One we see just line segment

Parametric line equation

Line in an affine space

Page 17: Geometric Objects and Transformations

Suriyong L.

Affine sumIf P is a point on line

P=Q+avv = R – Q;

ThusP = Q + a(R-Q)

= aR + (1-a)QLet

a = a1 and (1-a) = a2

Thus a1 + a2 = 1

Then P=a1R+a2Q

Points on line can be found between point Q and P(a)

Affine line addition

Page 18: Geometric Objects and Transformations

Suriyong L.

Convexity

• Convex object – Any point that lying on

line segment connect any two points in the object also in the object

• Affine sum definition

...1 1 2 2 n nP = P P Pa a a When

... 11 2 n =a a a

Objects defined by n points P1, P2,…,Pn. Consider the form

Line segment that connects two points

Page 19: Geometric Objects and Transformations

• An object is convex iff for any two points in the object all points on the line segment between these points are also in the object

Suriyong L.19

P

Q Q

P

convexnot convex

Convexity

Page 20: Geometric Objects and Transformations

Suriyong L.

is called the convex hull of the set of pointsconvex hull includes all line segments connecting pairs of points i[P1,P2,…,Pn]The notion of convexity is extreamly important in the design of curves and surfaces;

Convex hull

Convex hull

The set of points formed by the affine sum of n points, under the additional restriction

iα 0, i = 1,2,...,n

Page 21: Geometric Objects and Transformations

Suriyong L.

Dot and Cross product

• Dot (inner product)– u.v: result is magnitude of 2 vectors– If u.v = 0, u and v are orthogonal vector– Unit product is

Dot product and projection

Page 22: Geometric Objects and Transformations

Suriyong L.

Cross product• Result is vector• Forming from right hand coordinate system

Note: right-handed coordinate systemu points in the direction of the thumb v points in the direction of the index fingern points in the direction of the middle finger

Cross product

Page 23: Geometric Objects and Transformations

Suriyong L.

Plane• Infinite flat area• Direct extension of parametric line• Define with 3 non-co-linear points• Suppose P, Q and R are points in plane• The plane equation

and

Page 24: Geometric Objects and Transformations

Suriyong L.

The plane can have vector (normal vector) formed from u and v

Let

n : plane vector

Thus

General plane equation

Page 25: Geometric Objects and Transformations

Suriyong L.

3D primitives

Object are not lying on plane

Curves in three dimension Surfaces in three dimensions Volumetric objects

Page 26: Geometric Objects and Transformations

Suriyong L.

2 problems when incorporate in 3D

• Complex mathematic– Not all object that has 3D efficient

implementation• Approximated method may be used• 3 features characteristic to describe object

– Hollow– Vertices– Flat convex polygon composition

Page 27: Geometric Objects and Transformations

Suriyong L.

• Represents Vector in 3D space with 3 basis vector

thus

Coordinate system and frame

Vector derived from three basis vectors

Page 28: Geometric Objects and Transformations

Suriyong L.

Point and vector representation in affine space• It is not enough to use only vector to represent

point in space• Frame: fix point (origin) and basis vector

– Vector: represent with 3 basis– Point: fix point and 3 basis

Coordinate system (a) with vector emerging from a common point, (b) with vector moved

A Dangerous representation of vector

Page 29: Geometric Objects and Transformations

Representations and N-tuples• Any vector v representation

Where

• In column matrix form

• Known as Euclidean :

Suriyong L.

Page 30: Geometric Objects and Transformations

Coordinate System ChangingWorld /User frame Camera frame

– Done by MODELVIEW matrix– Use 2 basis set of vector and – Representation of by

Let

and

represent matrix from to

Suriyong L.

Page 31: Geometric Objects and Transformations

Let

Equivalent to

Where

Assume : the representation of with respect to

or

Where

Then using our representation of the second basis in terms of the first, we find that

Thus

The matrix (MT)-1 takes us from a to b:

We can transfer coefficient matrix from one to the other

Suriyong L.

Page 32: Geometric Objects and Transformations

Suriyong L.

• This changing let us to work with different coordinate system but origin unchanged

• Able to use them to represent rotation and scaling but not translation

Rotation and scaling of a basis Translation of a basis

2 examples 2 different frames

Page 33: Geometric Objects and Transformations

Suriyong L.

Example: Suppose that we have a vector whose representation in some basis is

1 a 2

3

We can denote the three basis vectors and , , and hence, = +2 +3Now suppose that we want to

1 2 3

1 2 3

w

=

v v vw v v v

1 1

2 1 2

3 1 2 3

make a new basis from the three vectors , , and The matrix M is

1 0 0 M= 1 1 0

1 1 1

1 2 3v v vu vu v vu v v v

Page 34: Geometric Objects and Transformations

The matrix that converts a representation in , and to one in which the basis vector are and is

In the new system, the representation of w is

That is

Suriyong L.

Page 35: Geometric Objects and Transformations

Suriyong L.

Homogeneous Coordinate3 basis vector is not enough to make point and vector differentFor any point:

In the frame specified by (v1, v2, v3, P0), any point P can be written uniquely as

The we can express this relation formally, using a matrix product, as

The yellow matrix called homogeneous-coordinate representation of point P

Page 36: Geometric Objects and Transformations

In the same frame, any vector w can be written

w can be represented by the column matrix

If and , can be expressed as

Suriyong L.

Page 37: Geometric Objects and Transformations

Can be written in the form

M : the matrix representation of the change of frames.

Suppose a and b are the homogeneous-coordinate representations, then

Hence,

Suriyong L.

Page 38: Geometric Objects and Transformations

When we work with representations, as is usually the case, we are interested in , which is of the form

Only 12 coefficients

Suriyong L.

Advantage of using homogeneous representationo use 4D matrix instead of 3D matrix

o less calculationo modern hardware support the representation

o parallelism for high speed calculation

Page 39: Geometric Objects and Transformations

Suriyong L.

Example

1 1

2 1 2

3 1 2 3

If we start with the basic vector , and and convert to a basis determined by the same , and then the three equations are the same

,

The reference point does not c

1 2 3

1 2 3

v v vu u u

u vu v vu v v v

hange, so we add the equation =

Thus, the matrices in which we are interested are the matrix1 0 0 01 1 0 0

M=1 1 1 00 0 0 1

its transpose, and their inverses.

0 0Q P

Page 40: Geometric Objects and Transformations

Suppose move the point to (1, 2, 3, 1)

with displacement vector

And move from point P0 to Q0 then

The matrix becomes

Its inverse is

We can move back and forth between representation

Thus

to

Suriyong L.

Page 41: Geometric Objects and Transformations

Suriyong L.

Original vector

b= (MT)-

1a<-

The origin in the new system is represented as 12

a30

11

b30

is transformed to

Page 42: Geometric Objects and Transformations

Suriyong L.

Working with Representation• Represent object from a frame to another such as

world frame to camera frame• Form of representation

a = Cb ; a, b object in two representation frame• Object:

– 3 vector, u, v, n, and 1 new frame origin, p -> (u, v, n, p)– 4 entities -> 4-tuples -> R4

• The solution is inverse matrix form of C, let’s say DD = C-1

Page 43: Geometric Objects and Transformations

Suriyong L.

1 1 1 1

2 2 2 2

3 3 3 3

11 1 1 1

1 2 2 2 2

3 3 3 3

DI D

0 0 0 1or

C

0 0 0 1

u v n pu v n p

u v n pu v n p

u v n pu v n p

u v n pu v n p

Page 44: Geometric Objects and Transformations

Suriyong L.

Frames in OpenGL• 2 frames:

– Camera: regard as fix– World:

• The model-view matrix position related to camera• Convert homogeneous coordinates representation of object to camera

frame

• OpenGL provided matrix stack for store model view matrices or frames

• By default camera and world have the same origin• If moving world frame distance d from camera the

model-view matrix would be

Page 45: Geometric Objects and Transformations

Suriyong L.

Camera and world frames

1 0 0 00 1 0 0

A=0 0 10 0 0 1

-d

Page 46: Geometric Objects and Transformations

Suriyong L.

Suppose camera at point (1, 0, 1, 1)

• World frame center point of camera

• Representation of world frame for camera

• Camera orientation: up or down

• Forming orthogonal product for determining v let’s say u

Camera at (1,0,1) pointing toward the origin

Page 47: Geometric Objects and Transformations

Suriyong L.

The model view matrix M

Result: Original origin is 1 unit in the n direction from the origin in the camera frame which is the point (0, 0, 1, 1)

OpenGL model view matrixOpenGL set a model-view matrix by send an array of 16 elements to glLoadMatrixWe use this for transformation like rotation, translation and scales etc.

1

T 1

1 10 01 0 1 1 2 20 1 0 0 0 1 0 0

(M )1 0 1 1 1 10 1

2 20 0 0 10 0 0 1

Page 48: Geometric Objects and Transformations

Suriyong L.

Modeling a Color Cube• A number of distinct task that we

must perform to generate the image– Modeling– Converting to the camera frame– Clipping– Projecting– Removing hidden surfaces– Rasterizing One frame of cube animation

Page 49: Geometric Objects and Transformations

Suriyong L.

Modeling a Cube• Model as 6 planes intersection or six polygons as cube facets• Ex. of cube definition

// object may defined as

void polygon(int a, int b, int c , int d) {/* draw a polygon via list of vertices */ glBegin(GL_POLYGON);

glVertex3fv(vertices[a]);glVertex3fv(vertices[b]);glVertex3fv(vertices[c]);glVertex3fv(vertices[d]);

glEnd();}

GLfloat vertices[8][3] = {{-1.0,-1.0,-1.0}, {1.0,-1.0,-1.0}, {1.0,1.0,-1.0}, {-1.0,1.0,-1.0}, {-1.0,-1.0,1.0}, {1.0,-1.0,1.0}, {1.0,1.0,1.0}, {-1.0,1.0,1.0}

};// ortypedef point3[3];

// then may define aspoint3 vertices[8] = {

{-1.0,-1.0,-1.0}, {1.0,-1.0,-1.0}, {1.0,1.0,-1.0}, {-1.0,1.0,-1.0}, {-1.0,-1.0,1.0}, {1.0,-1.0,1.0}, {1.0,1.0,1.0}, {-1.0,1.0,1.0}

};

Page 50: Geometric Objects and Transformations

Suriyong L.

Inward and outward pointing faces

• Be careful about the order of vertices

• facing outward: vertices order is 0, 3, 2, 1 etc., obey right hand rule

Traversal of the edges of a polygon

Page 51: Geometric Objects and Transformations

Suriyong L.

Data Structure for Object Representation

• Topology of Cube description– Use glBegin(GL_POLYGON); six times– Use glBegin(GL_QUADS); follow by 24

vertices• Think as polyhedron

– Vertex shared by 3 surfaces– Each pair of vertices define edges– Each edge is shared by two faces

Page 52: Geometric Objects and Transformations

Suriyong L.

Vertex-list representation of a cube

Page 53: Geometric Objects and Transformations

Suriyong L.

The color cube• Color to vertex list -> color 6 faces• Define function “quad” for drawing quadrilateral polygon• Next define 6 faces, be careful about define outwarding

typedef GLfloat point3[3];

point3 vertices[8] = {{-1.0,-1.0, 1.0},{-1.0, 1.0, 1.0}, {1.0,1.0, 1.0}, {1.0,-1.0, 1.0}, {-1.0,-1.0,-1.0}, {1.0,-1.0,-1.0}, {1.0,1.0,-1.0},

{-1.0,1.0,-1.0}};GLfloat colors[8][3] = {{0.0,0.0,0.0},{1.0,0.0,0.0}, {1.0,1.0,0.0}, {0.0,1.0,0.0},

{0.0,0.0,1.0}, {1.0,0.0,1.0}, {1.0,1.0,1.0}, {0.0,1.0,1.0}};

void quad(int a, int b, int c , int d) {glBegin(GL_QUADS); glColor3fv(colors[a]); glVertex3fv(vertices[a]); glColor3fv(colors[b]); glVertex3fv(vertices[b]);

glColor3fv(colors[c]); glVertex3fv(vertices[c]); glColor3fv(colors[d]); glVertex3fv(vertices[d]); glEnd();

}void colorcube() { quad(0, 3, 2, 1); quad(2, 3, 7, 6); quad(0, 4, 7, 3); quad(1, 2, 6, 5); quad(4, 5, 6, 7); quad(0, 1, 5, 4);}

Page 54: Geometric Objects and Transformations

Color the cube surface

•  

Suriyong L.

Projection of polygon

Bilinear interpolation

Page 55: Geometric Objects and Transformations

Vertex Array• Use encapsulation, data structure & method together

– Few function call• 3 step using vertex array

– Enable functionality of vertex array: part of initialization– Tell OpenGL where and in what format the array are: part of

initialization– Render the object :part of display call back

• 6 different type of array– Vertex, color, color index, normal texture coordinate and edge flag– Enabling the arrays by

glEnableClientState(GL_COLOR_ARRAY);glEnableClientState(GL_VERTEX_ARRAY);

Page 56: Geometric Objects and Transformations

Suriyong L.

// The arrays are the same as before and can be set up as globals:

GLfloat vertices[] = {{-1,-1,-1},{1,-1,1},{1,1,-1},{-1,1,-1},{-1,-1,1}, {1,-1,1}, {1,1,1}, {-1,1,1}};

GLfloat colors[] = {{0,0,0},{1,0,0},{1,1,0},{0,1,0},{0,0,1},{1,0,1}, {1,1,1},{0,1,1}};

// Next identify where the arrays are by

glVertexPointer(3, GL_FLOAT, 0, vertices);

glColorPointer(3, GL_FLOAT, 0, colors);

// Define the array to hold the 24 order of vertex indices for 6 faces

GLubyte cubeIndices[24] = {0,3,2,1, 2,3,7,6, 0,4,7,3, 1,2,6,5, 4,5,6,7, 0,1,5,4};

glDrawElements(type, n, format, pointer);

for (i=0; i<6; i++)

glDrawElement(GL_POLYGON, 4, GL_UNSIGNED_BYTE, &cubeIndex[4*i]};

// Do better by seeing each face as quadrilateral polygon

glDrawElements(GL_QUADS, 24, GL_UNSIGNED_BYTE, cubeIndices);

// GL_QUADS starts a new quadrilateral after each four vertices

Page 57: Geometric Objects and Transformations

Suriyong L.

Affine transformation

Transformation:A function that takes a point (or vector) and maps that points (or vector) in to another point (or vector)Point transform

Vector transform

Transformation

Page 58: Geometric Objects and Transformations

Suriyong L.

Transformation form of 4D matrix

Transformation function must be linearity function

For vector has 12 degree of freedom for point and vector

f p q f p f qa b a b

v Au

11 12 13 14

21 22 23 24

31 32 33 34

A

0 0 0 1

a a a aa a a aa a a a

1

2

3

u

0

aaa

1

2

3

1

v

bbb

Page 59: Geometric Objects and Transformations

Suriyong L.

Rigid body transformation

• Shape doesn’t change• Only change in position and orientation• They are: Translation and rotation.

Page 60: Geometric Objects and Transformations

Suriyong L.

Translation

• For all point P of the object– No reference point to frame or representation– 3 degree of freedom

Translation. (a) Object in original position. (b) Object translated

Is an operation that displaces points by a fixed distance in a given directionTo specify a translation, just specify a displacement vector d thus

P P d

Page 61: Geometric Objects and Transformations

Suriyong L.

Rotation

• Need axis and angle as input parameter

2D Point rotation θ radian around origin (Z axis) Two-dimensional rotation

x = r.cosf ; y = r.sinf

x’ = r.cos(q f= r.cosf.cosq r.sinf.sinq= x.cosq – y.sinq

y’ = r.sin(qf)= r.cosf.sinq +r.sinf.cosq = x.sinq+y.cosq

These equations can be written in matrix form ascos sin

sin cos

x xy y

q qq q

Page 62: Geometric Objects and Transformations

Suriyong L.

3 features for rotation(3 degrees of freedom)

• Around fixed point (origin)• Direction ccw is positive• A line

Rotation arount a fixed point.

Page 63: Geometric Objects and Transformations

Suriyong L.

3D rotation• Must define 3 input parameter

– Fixed Point (Pf)– Rotation angle (θ)– A line or vector (rotation axis)

• 3 degrees of freedom• 2 angle necessary specified

orientation of vector• 1 angle for amount of rotation

Three-dimensional rotation

Page 64: Geometric Objects and Transformations

Suriyong L.

Scaling• Non rigid-body transformation• 2 type of scaling

– Uniform: scale in all direction -> bigger, smaller– Nonuniform: scale in single direction

• Use in modeling and scaling

Non rigid body transformations

Uniform and nonuniform scaling

Page 65: Geometric Objects and Transformations

Suriyong L.

Scaling: input parameter

• 3 degrees of freedom– Point (Pf) – Direction (v)– Scale factor (a)

• a > 1 : get bigger• 0 £ a < 1 : smaller• a < 0 : reflected

Reflection

Effect of scale factor

Page 66: Geometric Objects and Transformations

Suriyong L.

Transformation in homogeneous coordinateMost graphics APIs force us to work within some reference system. Although we can alter this reference system – usually a frame – we cannot work with high-level representations, such as the expression.

Q = P + αv.

Instead, we work with representations in homogeneous coordinates, and with expressions such as

q = p + αv.

Within a frame, each affine transformation is represented by a 4x4 matrix of the form

Page 67: Geometric Objects and Transformations

TranslationIf we move the point p to p by displacing by a distance d then

p = p+dDefine

p = , p= , d=

1 1 0 may be written for each of components

x

y

z

x xy yz z

It

aaa

Let T is a translation matrix, we may written in matrix form as: And

1 0 00 1 0

T=0 0 10 0 0 1

Sometimes write it as

x

y

z

x

y

z

x xy y

z z

p Tp

aa

a

aaa

T , ,x y za a a

Page 68: Geometric Objects and Transformations

Suriyong L.

ScalingUse fixed point parameter as referenceScaling in one direction means scale in each direction elementThe scaling equation are:

For the homogeneous form

where

We may say that the inverse form of scaling is :

Page 69: Geometric Objects and Transformations

Suriyong L.

Rotation2D rotation is actual 3D rotation around Z axisFor general equations:

.cos .sin

.sin .cosx x yy x yz z

q qq q

z

z

z

For the Homogeneous equation, let denotes R is a rotation matrix around z axisThen the homogeneous form for rotation is p =R pwhere

cos sin 0 0sin cos 0 0

R0 0 1 00 0 0 1

q qq q

q

Page 70: Geometric Objects and Transformations

Suriyong L.

x

For rotation about x-axis the rotation matrix R

1 0 0 00 cos sin 0

R R0 sin cos 00 0 0 1

and for rotation about y-axis R

cos 0 sin 00 1 0 0

R Rsin 0 cos 00 0 0 1

x

x

y

y y

q qq

q q

q q

qq q

-1 T

For inverse rotation transformation in each axis: Rotate to the same axis with equivalent angle backward:

R = R R

We call a matrix whose inverse is equal to its transpose is call an or

q q q

thogonal matrix

Page 71: Geometric Objects and Transformations

Suriyong L.

Shear

• Let pull in top right edge and bottom left edge– Neither y nor z are changed– Call x shear direction

Shear

Page 72: Geometric Objects and Transformations

Suriyong L.

Computation of the shear matrix

cot xx x yy yz z

q

Leading to the shearing matrix

1 cot 0 00 1 0 0

H0 0 1 00 0 0 1

x

x x

q

q

Inverse of the shearing matrix: shear in the opposite direction

1H Hx x x xq q

x

Page 73: Geometric Objects and Transformations

Suriyong L.

Shear in other direction

cot

1 0 0 0cot 1 0 0

H0 0 1 00 0 0 1

y

yy y

x xy y x

z z

q

qq

Shear in y-axis direction when look on xy-plane

cot1 0 0 00 1 0 0

Hcot 0 1 0

0 0 0 1

z

z zz

x xy yz z x q

qq

Shear in z-axis direction when look on zx-plane

What about Hy and Hz when look in yz plane ?

Page 74: Geometric Objects and Transformations

Shearing general form

• shear with reference line

Suriyong L.

(0,0)

(0,1) (1,1)

(1,0) (0,0) (1,0)

(2,1) (3,1)

x x

y y

(0,0)

(0,1) (1,1)

(1,0) (1/2,0) (3/2,0)

(1,1) (2,1)

x x

y y

yref =-1

Page 75: Geometric Objects and Transformations

Suriyong L.

Concatenation of transformation

Pipeline transformation

Application of transformations one at a time

The sequence of transformation isq=CBAp

It can be seen that one do first must be near most to inputWe may proceed in two stepsCalculate total transformation matrix:

M=CBA

Matrix operation : q=Mp

Page 76: Geometric Objects and Transformations

Suriyong L.

Derive example of M: rotation about a fixed point

<- This is what we try to do.

Transformation processes

Sequence of transformation

Rotation of a cube about its center

 

Page 77: Geometric Objects and Transformations

Suriyong L.

General rotation

Rotation of a cube about the x-axis

Rotation of a cube about the z-axis. The cube is show (a) before rotation, and (b) after rotation

Rotation of a cube about the y-axis

R R R Rx y z

Page 78: Geometric Objects and Transformations

Suriyong L.

The Instance transformation• From the example object, 2 options to do with

object– Define object to its vertices and location

with the desire orientation and size– Define each object type once at a

convenience size, place and orientation , next move to its place

• Object in the scene is instance of the prototype

• If apply transformation, called instance transformation

• We can use database and identifier for eachScene of simple objects

Page 79: Geometric Objects and Transformations

Suriyong L.

Instance transformation

M=TRS //instant transformation equation of object

Page 80: Geometric Objects and Transformations

Suriyong L.

Rotation around arbitrary axis

• Input parameter– Object point– Vector (line segment or 2 points)– Angle of rotation

• Idea– Translate to origin first T(-P0)– Rotate

• q-axis component • q around 1 component axis, let say z

Page 81: Geometric Objects and Transformations

Suriyong L.

<- Convert u to unit length vector

<- Shift to origin (T(-P)), end shift back (T(P))

<- Individual axis rotation z first

Rotation of a cube about an arbitrary axis

R = Rx(-qx).Ry(-qy).Rz(q).Ry(qy).Rx(qx)

Let rotation axis vector is u and

u = P2 – P1

Movement of the fixed point to the origin

Page 82: Geometric Objects and Transformations

Suriyong L.

Problem: How we fine θx and θy ?

<- From v, unit vector

<-<-

f = angle of vector respect to origin

Sequence of rotations

Direction angles

2 2 2x y z 1a a a

cos cos cos2 2 2x y z 1f f f

coscos

cos

x x

y y

z z

f af a

f a

Page 83: Geometric Objects and Transformations

Suriyong L.

<- For rotation around X, project vector to plane XZ (X=0) meanwhile projection on YZ plane with length d

->

Computation of the x rotation

Computation of the y rotation

2 2y zd a a

1 0 0 0

0 0

0 0

0 0 0 1

yz

x xy z

d dR

d d

aa

qa a

0 0

0 1 0 00 0

0 0 0 1

x

y yx

d

Rd

a

qa

Finally we calculate all the matrices to find

0 0M T p T px x y y z y y x xR R R R Rq q q q q

Page 84: Geometric Objects and Transformations

• Example: rotate around origin to point (1,2,3) 45 degree

Normalized vector (1, 2, 3)

Z axis rotation (0,0,1,0) 45 degree => θz = 45o

X axis (1,0,0,0) rotation angle is Y axis rotation

Suriyong L.

Page 85: Geometric Objects and Transformations

Last take back to point

Suriyong L.

Page 86: Geometric Objects and Transformations

Suriyong L.

OpenGL transformation matrices

• Use glMatrixMode function for selected operation to apply

• Most graphic system use Current Transformation Matrix (CTM) for any transformation

Current transformation matrix (CTM)

Page 87: Geometric Objects and Transformations

Suriyong L.

CTM step

• Applied Identity matrix unless operate every round– C <- I

• Applied Translation– C <- CT

• Applied Scaling– C <- CS

• Applied Rotation– C <- CR

• Or postmultiply with M– C <- M or C <- CM

Page 88: Geometric Objects and Transformations

Suriyong L.

CTM: Translation, rotation and scaling

• CTM may be viewed as the part of all primitive product GL_MODELVIEW and GL_PROJECTION

• From function of glMatrixMode

Model-view and projection matrices

Page 89: Geometric Objects and Transformations

Suriyong L.

Rotation about a fixed point matrix step

glMatrixMode(GL_MODELVIEW);glLoadIdentity();glTranslatef(4.0, 5.0, 6.0);glRotatef(45.0, 1.0, 2.0, 3.0);glTranslatef(-4.0, -5.0, -6.0);

//rotate 45 deg. around a vector line 1,2,3// with fixed point of (4, 5, 6)

Page 90: Geometric Objects and Transformations

Modeling more than 1 independent object

• use paradigm of glPushMatrix() and glPopMatrix()

Suriyong L.

Page 91: Geometric Objects and Transformations

Suriyong L.

The quaternion• Extension of complex number• Useful for animation and hardware

implementation of rotation• Consider the complex number

• Rotate point (a, b) around z axis with θ radian• quaternion is equivalent to rotate in 3D space

ic a ib re q

2 2 1; tan

ic a ib reWhere

br a ba

q

q

(a, b)

θ

Page 92: Geometric Objects and Transformations

Suriyong L.

Quaternion form

• q0 define rotation angle• q define point

0 1 2 3 0

1 2 3 1 2 3

2 2 2

, , , ,q

q , ,

1

a q q q q q

whereq q q q i q j q k

and

i j k i j k

Page 93: Geometric Objects and Transformations

Suriyong L.

Multiplication properties

• Identity– (1, 0)

• Inverse

Page 94: Geometric Objects and Transformations

Suriyong L.

Rotation with quaternion• Let p=(0,p) // point in space with p= (x,y,z)• And unit quaternion r and its inverse r-1

// v is a unit vector // inverse of quaternion

r : rotation of θ around a unit vector, thus rotate of point p around v with θ and p’ is

if v= (0,0,1) //rotate around z axis, p’ will be

Page 95: Geometric Objects and Transformations

Quaternion to Rotation MatrixReplace:

Suriyong L.

Page 96: Geometric Objects and Transformations

Using quaternion in OpenGL

• can use only in the rotation transformation• the other transformations still use the matrix

manipulation.• when use in OpenGL

– multiplay the object first and transform the result to matrix form

– use at the display state

Suriyong L.

Page 97: Geometric Objects and Transformations

Case study Trackball

Suriyong L.

Page 98: Geometric Objects and Transformations

Suriyong L.

Exercise4.1Consider the solution of either constant-coefficient linear differential

or difference equations (recurrences). Show that the solutions of the homogeneous equations form a vector space. Relate the solution for a particular in homogeneous equation to an affine space.

4.2Show that the following sequences commute:a. A rotation and a uniform scaling b. Two rotations about the same axis c. Two translations

4.3Write a library of functions that will allow you to do geometric programming. Your library should contain functions for manipulating the basic geometric types (points, lines, vectors) and operations on those types, including dot and cross products. It should allow you to change frames. You can also create functions to interface with OpenGL, so that you can display the results of geometric calculations.

Page 99: Geometric Objects and Transformations

Suriyong L.

4.4 If we are interested in only two-dimensional graphics, we can use three-dimensional homogeneous coordinates by representing a point as p = [x y 1]T and a vector as v =[a b 0]T. Find the 3x3 rotation, translation, scaling, and shear matrices. How many degrees of freedom are there in an affine transformation for transforming two-dimensional points?

4.5 We can specify an affine transformation by considering the location of a small number of points both before and after these points have been transformed. In three dimensions, how many points must we consider to specify the transformation uniquely? How does the required number of points change when we work in two dimensions?

4.6 How must we change the rotation matrices if we are working in a left-handed system and we retain our definition of a positive rotation?

4.7 Show that any sequence of rotations and translations can be replaced by a single rotation about the origin, followed by a translation.

4.8 Derive the shear transformation from the rotation, translation, and scaling transformations.

Page 100: Geometric Objects and Transformations

Suriyong L.

4.9 In two dimensions, we can specify a line by the equation y = mx + b. Find an affine transformation to reflect two- dimensional points about this line. Extend your result to reflection about a plane in three dimensions,

4.10 In Section 4.8 we showed that an arbitrary rotation matrix could be composed from successive rotations about the three axes. How many ways can we compose a given rotation if we can do only three simple rotations? Are all three of the simple rotation matrices necessary?

4.11 Add shear to the instance transformation. Show how to use this expanded instance transformation to generate parallelepipeds from a unit cube.

4.12 Find a homogeneous-coordinate representation of a plane.4.13 Determine the rotation matrix formed by glRotate. That is, assume that

the fixed point is the origin and that the parameters are those of the function.

4.14 Write a program to generate a Sierpinski gasket as follows. Start with a white triangle. At each step, use transformations to generate three similar triangles that are drawn over the original triangle, leaving the center of the triangle white and the three corners black.

Page 101: Geometric Objects and Transformations

Suriyong L.

4.15 Start with a cube centered at the origin and aligned with the coordinate axes. Find a rotation matrix that will orient the cube symmetrically, as shown in Figure 4.65.

4.16 We have used vertices in three dimensions to define objects such as three-dimensional polygons. Given a set of vertices, find a test to determine whether the polygon that they determine is planar.

4.17 Three vertices determine a triangle if they do not lie in the same line. Devise a rest for co-linearity of three vertices.

4.18 We defined an instance transformation as the product of a translation, a rotation, and a scaling. Can we accomplish the same effect by applying these three types of transformations in a different order?

4.19 Write a program that allows you to orient the cube with one mouse button, to translate it with a second, and to zoom in and out with a third.

Page 102: Geometric Objects and Transformations

Suriyong L.

4.20 Given two nonparallel three-dimensional vectors u and r, how can we form an orthogonal coordinate system in which u is one of the basis vectors?

4.21 An incremental rotation about the z-axis is determined by the matrix

What negative aspects are there if we use this matrix for a large number of steps? Hint: consider points a distance of 1 from the origin. Can you suggest a remedy?

4.22 Find the quaternion for 90-degree rotations about the x- and y-axes. Determine their product.

Page 103: Geometric Objects and Transformations

Suriyong L.

4.23 Determine the rotation matrix

find the corresponding quaternion.4.24 Redo the trackball program using quaternion instead of

rotation matrices.4.25 Implement a simple package in C++ that can do the required

mathematical operations for transformations. Such a package might include matrices, vectors, and frames