Interactive Computer Graphics Transformations - PowerPoint PPT Presentation

1 / 55
About This Presentation
Title:

Interactive Computer Graphics Transformations

Description:

Department of Computer Science. University of Cape Town. July 2002. jgain_at_cs. ... steady rotation about a single vector but may instead cause weird oscillations. ... – PowerPoint PPT presentation

Number of Views:80
Avg rating:3.0/5.0
Slides: 56
Provided by: edwin58
Category:

less

Transcript and Presenter's Notes

Title: Interactive Computer Graphics Transformations


1
Interactive Computer GraphicsTransformations
  • James Gain and Edwin Blake
  • Department of Computer ScienceUniversity of Cape
    Town
  • July 2002jgain_at_cs.uct.ac.za

2
Map of the Lecture
  • Vector Geometry
  • Vector, Affine and Euclidean Spaces
  • Coordinate Systems
  • Euclidean, Polar, Homogenous Coordinate Systems
  • Transformations
  • Coordinate System, Object, Viewing Transformations

Transformations
Viewing
Shading
3
Vector Geometry
  • Enables fundamental operations with points and
    vectors
  • Independent of any particular co-ordinate system
  • Robust, simple and efficient algorithms
  • Operations
  • Closest point, inside/outside and intersection
    tests
  • Entities
  • Vectors, points, lines, planes and polygons

4
Points
  • Discrete positions
  • Represented by co-ordinate triples
    relative to co-ordinate axes
  • Class Point double x,y,z
  • But addition, subtraction, multiplication and
    division of points are not defined

5
Illegal Operation on Points
  • The results of arithmetic operations on points
  • depend on the co-ordinate system
  • have no geometric meaning
  • A contradiction finding the midpoint
    is legal.

6
Vectors
  • Pointers indicating direction and magnitude
  • Also represented by co-ordinate triples
    but with no fixed position
  • Class Vector double i,j,k
  • Clearly distinct from points

7
Vector Space
  • Domain in which vectors live
  • Consists of
  • A set of vectors
  • Two closed operations addition and scalar
    multiplication
  • Special zero vector, , for which
    and

Can be of any dimension, . Typically 2D or
3D Conceptually similar to an object-oriented
class (data vector, methods operations)
8
Implementing a Vector Space
  • class Vector
  • double i,j,k
  • inline void scale(double c)
  • i i c j j c k k c
  • inline Vector add(Vector a, Vector b)
  • i a.i b.i
  • j a.j b.j
  • k a.k b.k

9
Affine Space
  • Domain in which points live
  • Consists of
  • A set of points
  • An associated vector space
  • Two extra operations
  • (a) subtraction of two points to form
    a vector
  • (b) addition of a point and vector to
    produce a new point
  • Unlike the zero vector there is no distinguished
    point

10
Implementing an Affine Space
  • class Point
  • double x,y,z
  • inline void sub(Point q, Vector v)
  • v-gti q.x - p.x v-gtj q.y - p.y
  • v-gtk q.z - p.z
  • inline void plus(Point p, Vector v)
  • x p.x v.i y p.y v.j
  • z p.z v.k

11
Addition and Multiplication of Points
  • undefined
  • vector
  • BUT midpoint calculation point
  • Recast in terms of legal operations
  • point
  • point iff

12
Euclidean Space
  • An affine space with the additional concept of
    distance
  • Consists of
  • An affine space
  • Two new operations, dot product and
    cross product
  • Distance between two points length
    of the vector between them

13
Length of a Vector
  • From Pythagoras the length of a vector is
  • In order to normalize a vector it is scaled by
    the reciprocal of its length

14
Dot Product
  • Variously known as inner, dot, or scalar product.
  • Implementation
  • double dot(Vector v, Vector w)
    return (a.i b.i a.j b.j a.k b.k)
  • where is the angle between
    and fitted tail to tail.

15
Cross Product
  • Variously known as the outer, cross or vector
    product.
  • and
  • Implementation
  • Vectorcross(Vector a, Vector b) i
    (a.j b.k) - (a.k b.j) j (a.k
    b.i) - (a.i b.k) k (a.i b.j) - (a.j
    b.i)
  • Produces a vector orthogonal to the
    arguments in the same sense as the
    co-ordinate axes.

16
Lines
  • From two points, and , a spanning line
    segment or interpolating line can be found.
  • Geometric entities usually have two forms
  • Implicit
  • Parametric
  • Line equations (a point on the line
    satisfies)
  • Implicit
  • Parametric ( parameter)

17
Planes
  • From three points, , and , an
    interpolating plane can be found.
  • Plane equations (a point on the plane
    satisfies)
  • Implicit
    ( normal, point
    on the plane)
  • Parametric
    ( parameters)
  • The implicit equation can be rewritten in the
    more familiar form where

18
Derivation of the Implicit Plane
  • Given the three points, , and .
  • Find a vector normal to the plane
  • This assumes that the points are not collinear
    (all in a straight line).
  • Set

19
Exercise Backface Culling
  • Given
  • A left-handed 3D co-ordinate system
  • A triangle with vertices, , and
    , which form a clockwise ordering when
    viewed from the front
  • A viewpoint
  • Design an algorithm which determined whether the
    back or front of is visible from

20
Solution Backface Culling
  • IF THEN RETURN undefined
  • IF THEN RETURN side-on
  • IF THEN RETURN back-facing
  • ELSE RETURN front-facing

21
Cartesian Co-ordinate Systems
  • Consists of a reference point (the origin) and
    three mutually perpendicular lines passing
    through this point (the axes) labelled
  • A labelling of the axes has either a left-handed
    or right-handed orientation
  • Right-hand rule a co-ordinate system is
    right-handed if, whenever the thumb is aligned
    with ve and the forefinger with ve ,
    then the index finger points in the direction of
    ve . Otherwise the orientation is left-handed
  • If unit vectors are aligned with the different
    axes then together they form an orthonormal
    (orthogonal and normal) basis for the co-ordinate
    system

22
Polar Co-ordinate Systems
  • Alternative system using rotation angles
  • Orient a ray by rotating in the plane (
    ) and then elevating it towards the -axis (
    ). A point is then located at a distance ( )
    along the ray
  • A point is defined by the polar
    co-ordinates
  • Conversion from polar to Cartesian
    co-ordinates

23
Transformations
  • Objects typically consist of a collection of
    interrelated points, e.g. a polygon-mesh
  • A predefined object can be modified to an
    arbitrary location, orientation and size by
    applying the same transformation to all its
    constituent points
  • BUT, this only work if the transformation is
    affine
  • Preserve straight lines
  • Need only transform the endpoints of a line
    rather than every single point along it
  • Transformations are extremely useful in both
    modelling and rendering

24
Basic 2D Transformations
  • Scale
  • About the origin.
  • By factors and .
  • If then balanced,
    otherwise unbalanced.
  • Translate
  • Along the vector .
  • Reflect
  • In one or both of the co-ordinate
    axes.

25
Further 2D Transformations
  • Shear
  • Parallel to an axis.
  • By an angle .
  • Rotate
  • About the origin.
  • Counter-clockwise by an angle .

26
Derivation of Rotation

27
The Matrix Representation of 2D Transformations
  • A transformation can be encoded by
    pre-multiplying a transformation matrix,
    with a column vector of co-ordinates,
  • Be aware that some texts post-multiply a
    co-ordinate row vector with a transformation
    matrix
  • The transformation matrices are transposed with
    respect to each other.

28
Transformation Matrices
  • Scale (by factors and ) Shear
    (parallel to by )
  • Reflect (in ) Rotate (by angle )

29
Homogenous Co-ordinates
  • 2D Translations cannot be encoded using
    matrix multiplication because points at the
    origin never move.
  • Instead use homogenous co-ordinates
  • These are projections of 3D points along a
    ray from the origin onto the plane

30
Homogenous Projections
  • An infinite number of homogenous co-ordinates map
    to every 2D point.
    are all equivalent to .
  • Points at infinity have and cannot be
    projected onto the plane because this
    would involve division by zero
  • These points can be used to represent vectors
  • Conversion

31
Matrices for Homogenous Co-ordinates
  • where is a standard
    transformation
  • Translation

32
Concatenating Transformations
  • It is frequently necessary to perform a sequence
    of transformations on the same object.
  • These can be merged into a single transformation
    by matrix multiplication.
  • Example shearing then reflecting

33
Order is Important
  • Matrix multiplication is not commutative
  • The order in which transformations are combined
    affects the outcome.

34
Non-Standard Transformations
  • Centred at a point other than the origin
  • Or involving a line which is not parallel to any
    co-ordinate axis.
  • Example A rotation by about the point
  • (1) Translate to the origin,
  • (2) Rotate by about the origin,
  • (3) Translate the origin back to ,
  • The combined transformation is

35
Matrices for Off-Origin Rotation
36
Exercise Composite Reflection
  • Write down but do not multiply out the composite
    transformation that reflects a point in an
    arbitrary line passing through point and
    , where
  • Hint you will need to use translation, rotation
    and reflection

37
Solution Composite Reflection
  • Translate to the origin,
  • Rotate the vector onto the -axis,
    , by the angle between and
  • Reflect in the -axis,
  • Reverse the rotation,
  • Reverse the translation,

38
Composite Reflection Matrices

39
3D Transformations
  • Employ 3D homogenous co-ordinates
  • Transformation matrices
  • translation scaling
    reflection

40
3D Rotations
  • Rotation (counterclockwise around the positive
    axis)
  • about about about

41
Transformation Pipeline
Modelling Transform
Object in object co-ordinates
Object in world co-ordinates
Viewing Transform
Object in viewing co-ordinates
Object in 2D screen co-ordinates
Perspective Projection
42
Modelling Transforms
  • Transformation of an object from a local
    co-ordinate frame to the world co-ordinate frame.
  • The local system ( ) is expressed relative to
    the world system ( ) as three vectors ,
    and at an origin
  • From to

43
Viewing Transforms
  • Need to transform an arbitrary co-ordinate system
    to the default viewing co-ordinate system (with
    the eye at the origin and the screen
    perpendicular to ).
  • The camera is specified in world co-ordinates as
  • A camera position at
    .
  • A look point (screen centre) at
    .
  • An up vector (which orients the camera).
  • Transformations
  • Translate the camera to the origin.
  • Scale by so that the camera to screen
    distance is .
  • Align the vector through rotation with
    the axis.
  • Rotate around so that is aligned with
    the axis.

44
Rotation about an Arbitrary Vector
  • Task
  • Rotate around the vector from to by
    an angle
  • Solution
  • Translate to the origin
  • Rotate around by so that is
    aligned with the plane
  • Rotate around by to align with
    the axis
  • Rotate around by
  • Reverse rotations 2,3
  • Reverse translation 1

45
OpenGL Transformations
  • Current Transformation Matrix
  • The transformation state of the system
  • A concatenated matrix applied to all subsequent
    vertices
  • Transformations in OpenGL
  • In OpenGL CTM is a product of the Projection
    (GL_PROJECTION) and Model-View (GL_MODELVIEW)
    matrices
  • Functions to change matrix state, set and
    concatenate matrices
  • Functions to rotate, translate and scale

46
Example OpenGL Transformations
  • Task halve the x-length of an object centred at
    and rotate it by
    about the vector
  • glMatrixMode(GL_MODELVIEW)
  • glLoadIdentity()
  • glTranslatef(4.0, 5.0, 6.0)
  • glRotatef(45.0, 1.0, 2.0, 3.0)
  • glScalef(0.5, 1.0, 1.0)
  • glTranslatef(-4.0, -5.0, -6.0)
  • Access the Model View matrix
  • Load the identity transformation
  • OpenGL tansformations added in reverse order
  • Translate the origin to
  • Rotate by about
  • Scale by
  • Translate to the origin

47
Controlling OpenGL Matrices
  • Order of Transformations
  • The transformation specified most recently is the
    one applied first
  • Conceptually analogous to pushing matrices onto a
    stack matrices are applied in the reverse of
    their specification
  • Matrices can be loaded or concatenated directly
  • glLoadMatrix(tflat) set current state to T
  • glMultMatrix(tflat) postmult T with current
    state
  • Glfloat tflat16 is an expansion of T44
    arranged in columns ( i.e tflat2 tmat02 )
  • The state of a matrix can be saved
  • glPushMatrix() saves the current matrix
  • glPopMatrix() restores the last saved state

48
Euler Angles (Azimuth, Elevation, Roll)
  • Historically popular but flawed
    parametrization of orientation
  • A general rotation is constructed as a
    sequence of rotations about 3 mutually
    orthogonal axes rolls about , and
  • The order of the rolls is significant
  • Arbitrarily choose the ordering
    A roll about by ,
    followed with a roll about
    by , and finally a roll about by
  • Euler angle interpolation is not very stable.
    Especially with a small rotation in one axis and
    large rotation in another

49
Gimbal Lock
  • A gimbal mechanism consists of three concentric
    rings on pivots which support a compass or
    gyroscope.
  • Gimbal lock occurs when two of the rings are
    accidentally aligned.
  • Euler angles are also susceptible. If one axis is
    rolled into alignment with another then a degree
    of rotation freedom is lost.
  • Unlike translations, rotations relative to
    separate axes are not independent.
  • Example a -roll of rotates the
    -axis onto the -axis so that rolls about
    and are indistinguishable.

50
Lerping Euler Angles
  • Two Euler rotations
    and can be linearly
    interpolated to obtain inbetween rotations
  • Problems
  • This does not produce a natural steady rotation
    about a single vector but may instead cause weird
    oscillations. Reason the rolls about
    are not independent.
  • The resulting interpolation differs depending on
    the ordering of the Euler angles. Reason the
    rolls about are not commutative.

51
Example Poor Euler Angle Interpolation
  • The interpolations
    and
    have the same start and end orientations but
    different intermediate orientations.

52
Quaternions
  • Aim to
  • Guarantee a direct and steady rotation between
    any two key orientations
  • Be independent of any particular co-ordinate
    system
  • Quaternions were invented by Sir William
    Hamilton, after 10 years of work, on 16 October
    1843. In his elation he carved the formulae into
    the nearby Broome Bridge in Dublin
  • They represent an orientation by a
    counter-clockwise rotation angle ( ) about an
    arbitrary vector ( )
  • Advantages
  • combining quaternions more efficient than matrix
    multiplication
  • simple to convert between angle-axis, quaternion
    and transformation matrix representations of
    rotation

53
Form of a Quaternion

  • such that
  • are imaginary axes (
    are imaginary numbers) and
    is a real axis
  • and are co-ordinates relative to
    these four axes
  • In 3D a point
    s.t. with
    co-ordinates and axes
    lies on a sphere of radius
  • Similarly, for quaternions the rotation with

    lies on a 4D hypersphere of radius

54
Lerping vs. Slerping Quaternions
  • Inbetweening key Quaternions and
    by linearly interpolating their
    components does not
  • Produce equal changes in the quaternion
    for equal steps in . They speed up in
    the middle.
  • Ensure vectors remain on the hypersphere.
  • Rather use spherical linear interpolation
    (Slerping) which step through a constant
    angle.

55
Evaluating Quaternions
  • Advantages
  • Flexible.
  • No parametrization singularities.
  • Smooth consistent interpolation of orientations.
  • Simple and efficient composition of rotations.
  • Disadvantages
  • Each orientation is represented by two
    quaternions.
  • Represent orientations not rotations (
    about is the same quaternion as about
    ).
  • Complex!
Write a Comment
User Comments (0)
About PowerShow.com