0% found this document useful (0 votes)
9 views55 pages

mod 2

The document discusses geometric objects and transformations, focusing on representations of vectors and the change of coordinate systems. It explains transformations such as translation, rotation, scaling, and reflection, along with their matrix representations and applications in OpenGL. Additionally, it covers the concept of homogeneous coordinates for consistent handling of affine transformations.

Uploaded by

prakyatshetty15
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views55 pages

mod 2

The document discusses geometric objects and transformations, focusing on representations of vectors and the change of coordinate systems. It explains transformations such as translation, rotation, scaling, and reflection, along with their matrix representations and applications in OpenGL. Additionally, it covers the concept of homogeneous coordinates for consistent handling of affine transformations.

Uploaded by

prakyatshetty15
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 55

Geometric Objects

and Transformations Dr Basavaraj Patil


Representations and N-Tuples
• Suppose that vectors e1, e2, and e3 form a
basis. The representation of any vector, v, is
given by the component (α1, α2, α3) of a vector
a where
• v = α1e1 + α2e2 + α3e3
• The basis vectors must themselves have
representations that we can denote e1, e2, and
e3, given by
• e1 = (1, 0, 0)T
• e2 = (0, 1, 0) T
• e3 = (0, 0, 1) T
Representations and N-Tuples

• In other words, the 3-tuple (1, 0, 0) is the


representation of the first basis vector
Change of Coordinate
Systems
• We are required to find how the representation
of a vector changes when we change the basis
vectors
• In OpenGL, we specify our geometry using the
coordinate system or frame that is natural for the
model, which is known as the object or model
frame
• Models are then brought into the world frame
Change of Coordinate
Systems
• At some point, we want to know how these
objects appear to the camera
• It is natural at that point to convert from the
world frame to the camera or eye frame
• The conversion from the object frame to the eye
frame is done by the model-view matrix
Change of Coordinate
Systems
Confusing Points and
Vectors
• Consider the point and the vector
• P = P0 + b1v1+ b2v2 +….+bnvn
• v=a1v1+ a2v2 +….+anvn
• They appear to have the similar representations
• p=[b1 b2 b3] v=[a1 a2 a3] v
• which confuses the point with the vector p
• A vector has no position v

Vector can be placed anywhere

point: fixed
•Transformations (Derivation)
•Translation
•Rotation
•Scaling

•Transformations in Homogeneous Co-


Ordinates (Derivation)
Modeling a Colored Cube
• Traversal of the edges of a polygon
• Outward Facing – Traversed
Counterclockwise
• Eg : 0,3,2,1 specifies outward facing
• 0,1,2,3 specifies back face of the
polygon
Modeling a Colored Cube

• By carefully specifying front and back


faces, we can eliminate (or Cull) faces that
are not visible.
Data Structures for object
representation
Bilinear Interpolation
• The colors C0, C1, and C2 are the ones
assigned to the vertices in the application
program
Bilinear Interpolation
• We first use linear interpolation to
interpolate colors, along the edges
between vertices 0 and 1, creating RGB
colors along the edges through the
parametric equations as follows:
• C01(α) = (1− α)C0 + αC1
• As α goes from 0 to 1, we generate colors,
C01(α) along this edge
Bilinear Interpolation
• We first use linear interpolation to
interpolate colors, along the edges
between vertices 0 and 1, creating RGB
colors along the edges through the
parametric equations as follows:
• C01(α) = (1− α)C0 + αC1
• As α goes from 0 to 1, we generate colors,
C01(α) along this edge
TWO
DIMENSIONAL Dr Basavaraj Patil

TRANSFORMATION
CONTENT
TRANSFORMATION PRINCIPLES
CONCATENATION
MATRIX REPRESENTATIONS
TRANSFORMATION
Transform every point on an object according to certain rule.
Q (x’, y’)

P (x,y) T

Initial Object

Transformed Object

x x’ The point Q is the image of P under the


y y’ transformation T.
TRANSLATION (55,60)

(20,35)

(45,30)
(65,30)

x x  tx
(10,5) (30,5)
y y  t y
The vector (tx, ty) is called the offset vector.
TRANSLATION (OPENGL)

Specifying a 2D-Translation:

glTranslatef(tx, ty, 0.0);

(The z component is set to 0 for 2D translation).


Rotation About the Origin
y
(x’,y’)

(x’,y’)
(x,y)
(x,y)
q

o x
x   x cos  y sin 
y   x sin   y cos
The above 2D rotation is actually a rotation about the
z-axis (0,0,1) by an angle .
ROTATION ABOUT THE
ORIGIN
Specifying a 2D-Rotation about the origin:

glRotatef(theta, 0.0, 0.0, 1.0);

theta: Angle of rotation in degrees.


The above function defines a rotation about the z-axis (0,0,1).
Rotation About a Pivot Point

(x’,y’) (x,y)

(xp , yp)
Pivot Point

• Pivot point is the point of rotation


• Pivot point need not necessarily be on the object
Rotation About a Pivot Point

STEP-1: Translate the pivot point to the origin


(x,y)

(x1, y1)

(xp , yp)

x1  x  x p

y1  y  y p
Rotation About a Pivot Point

STEP-2: Rotate about the origin

(x2, y2) (x1, y1)

x 2  x1 cos   y1sin 

y 2  x1 sin   y1 cos 
Rotation About a Pivot Point
STEP-3: Translate the pivot point to original position
(x’, y’)

(x2, y2)

(xp, yp)

x  x 2  x p

y  y 2  y p
Rotation About a Pivot Point
x  ( x  x p ) cos  ( y  y p ) sin   x p
y  ( x  x p ) sin   ( y  y p ) cos  y p

Specifying a 2D-Rotation about a pivot point (xp,yp):

glTranslatef(xp, yp, 0);


glRotatef(theta, 0, 0, 1.0);
glTranslatef(-xp, -yp, 0);

Note the OpenGL specification of the sequence of transformations in the


reverse order !
Scaling About the Origin

(x’,y’)

x   x. s x
(x,y) (x,y)
y   y. s y
(x’,y’)

Uniform Non-Uniform

( sx , s y  0) The parameters sx, sy are called scale factors.


sx  s y sx  s y
Scaling About the Origin

Specifying a 2D-Scaling with respect to the origin:

glScalef(sx, sy, 1.0);

sx, sy: Scale factors along x, y.


For proper scaling sx, sy must be positive.
For 2D scaling, the third scale factor must be set to 1.0.
Scaling About a Fixed Point

• Translate the fixed point to origin


(x,y) • Scale with respect to the origin
(x’,y’) • Translate the fixed point to its original
position.

(xf , yf )

x ( x  x f ).s x  x f
y  ( y  y f ).s y  y f
y
REFLECTIONS Initial
Object
Reflection about y
x =  x

Reflection about
origin
Reflection about x
x =  x y =  y
y =  y
REFLECTIONS

Reflection about x: glScalef(1, -1, 1);


Reflection about y: glScalef(-1, 1, 1);
Reflection about origin: glScalef(-1, -1, 1);
SHEAR

x   x  hx y
y y

• A shear transformation in the x-direction (along x)


shifts the points in the x-direction proportional
to the y-coordinate.
• The y-coordinate of each point is unaffected.
Matrix Representations

 x   x   t x 
Translation  y    y    t 
     y

Rotation [Origin]
 x   cos  sin    x 
 y    sin  cos   y 
    
 x   sx 0   x 
Scaling [Origin]  y    0 s   y 
   y 
Matrix Representations

 x  1 0   x 
Reflection about x  y  0  1  y 
    
 x   1 0  x 
Reflection about y
 y  0 1  y 
    
Reflection about  x   1 0   x 
the Origin  y  0  1  y 
    
Matrix Representations

Shear along x  x  1 h   x 


 y  0 1   y 
    
 x  1 0  x 
Shear along y
 y  h 1  y 
    
HOMOGENEOUS
COORDINATES
• To obtain square matrices an
additional row was added to the
matrix and an additional coordinate,
the w-coordinate, was added to the
vector for a point. In this way a
point in 2D space is expressed in
three-dimensional homogeneous
coordinates.
• This technique of representing a
point in a space whose dimension is
one greater than that of the point is
called homogeneous representation.
It provides a consistent, uniform
way of handling affine
transformations.
Homogeneous Coordinates
• If we use homogeneous coordinates, the geometric
transformations given above can be represented using
only a matrix pre-multiplication.
• A composite transformation can then be represented
by a product of the corresponding matrices.
Cartesian Homogeneous
( x, y ) 
  ( xh, yh, h), h 0

 a b
 ,    ( a, b, c), c 0
 c c
Examples: (5, 8) (15, 24, 3)
(x, y) (x, y, 1)
Homogeneous Coordinates
Basic Transformations
 x   1 0 t x   x 
Translation  y   0 1 t   y 
P’=TP    y 
 1   0 0 1   1 
 x   cos  sin  0  x 
Rotation [O]  y    sin  cos 0  y 
P’=RP     
 1   0 0 1  1 
 x   sx 0 0  x 
Scaling [O]  y    0 s 0  y 
P’=SP    y  
 1   0 0 1  1 
Inverse of Transformations

If,  x   x then,  x  x 
 y  [T ] y   y  [T ] 1  y 
       
 1   1   1   1 

1
Examples: T (t x , t y ) T ( t x , t y )
R  1 ( ) R(  )
1 1
S ( s x , s y ) S  , 
1
s s 
 x y
H x 1 (h) H x ( h)
Transformation Matrices

Additional Properties:

T (t x , t y )T (u x , u y ) T (t x  u x , t y  u y )

R (1 ) R ( 2 ) R (1   2 )

R ( ) 1

S ( s x , s y ) S ( wx , wy ) S ( s x wx , s y wy )
Composite Transformations

Transformation T followed by  x   x
 y  [ R ][Q ][T ] y 
Transformation Q followed by    
Transformation R:  1   1 

Example: (Scaling with respect to a fixed point)


 x   1 0 x f   sx 0 0  1 0  x f   x 
 y   0 1      
0  0 1  y f   y 
   yf  0 sy
 1   0 0 1   0 0 1  0 0 1   1 

Order of Transformations
Order of Transformations
In composite transformations, the order of
transformations is very important.
Rotation followed by Translation:

Translation followed by Rotation:


Order of Transformations (OpenGL)
OpenGL postmultiplies the current matrix
with the new transformation matrix
glMatrixMode(GL_MODELVIEW); Current Matrix

glLoadIdentity(); [I]

glTranslatef(tx, ty, 0); [T]

glRotatef(theta, 0, 0, 1.0); [T][R]

glVertex2f(x,y); [T][R]P

Rotation followed by Translation !!


General Properties
Preserved Attributes
Line Angle Distance Area

Translation Yes Yes Yes Yes

Rotation Yes Yes Yes Yes

Scaling Yes No No No

Reflection Yes Yes Yes Yes

Shear Yes No No Yes


Affine Transformation
A general invertible, linear, transformation.

x  a1 x  b1 y  c1
y  a 2 x  b2 y  c2
(a1b2  a 2 b1 0)

Transformation Matrix:

 a1 b1 c1 
a b2 c 2 
 2
 0 0 1 
CONCATENATION.
We perform 2 translations on the same point:

P T ( d x1 , d y1 ) P
P T ( d x 2 , d y 2 ) P
P T ( d x1 , d y1 ) T ( d x 2 , d y 2 ) P T ( d x1  d x 2 , d y1  d y 2 ) P

So we expect :
T ( d x1 , d y1 ) T ( d x 2 , d y 2 ) T ( d x1  d x 2 , d y1  d y 2 )
CONCATENATION.

The matrix productT (d x1 , d y1 ) T (d x 2 , d y 2 ) is :


 1 0 d x1   1 0 d x 2 
 0 1 d  . 0 1 d  ?
 y1   y2 

 0 0 1   0 0 1 
Matrix product is variously referred to as compounding,
concatenation, or composition
CONCATENATION.
The matrix productT (d x1 , d y1 ) T (d x 2 , d y 2 ) is :
 1 0 d x1   1 0 d x 2   1 0 d x1  d x 2 
 0 1 d  . 0 1 d   0 1 d  d 
 y1   y2   y1 y2 

 0 0 1   0 0 1   0 0 1 

Matrix product is variously referred to as compounding, concatenation, or


composition.
PROPERTIES OF
TRANSLATIONS.
1. T (0,0) I
2. T ( s x , s y ) T (t x , t y ) T ( s x  t x , s y  t y )
3. T ( s x , s y ) T (t x , t y ) T (t x , t y ) T ( s x , s y )
4. T -1 ( s x , s y ) T ( s x , s y )

Note : 3. translation matrices are commutative.


HOMOGENEOUS FORM OF
SCALE.
Recall the (x,y) form of Scale :  sx 0
S ( s x , s y ) 
0 s y 

In homogeneous coordinates :

 sx 0 0
S ( s x , s y )  0 sy 0
 0 0 1
Orthogonal Projections
• The equations of the projections are

• We can write this result using


homogeneous coordinates as :
Projections in OpenGL
• The infinite pyramid in below fig becomes
a finite clipping volume by adding front and
back clipping planes
• The resulting view volume is a frustum
OpenGL Perspective
glFrustum(left,right,bottom,top,near,far)
OpenGL Perspective
• A typical sequence of this projection matrix
is as follows
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(left, right, bottom, top, near,
far);
OpenGL Orthogonal Viewing
glOrtho(left,right,bottom,top,near,far)

near and far measured from camera

You might also like