Download presentation
Presentation is loading. Please wait.
1
Interactive Computer Graphics Transformations
James Gain and Edwin Blake Department of Computer Science University of Cape Town July 2002 Collaborative Visual Computing Laboratory
2
Interactive Computer Graphics Contents
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 24/02/2019 Interactive Computer Graphics Contents
3
Interactive Computer Graphics Contents
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 24/02/2019 Interactive Computer Graphics Contents
4
Interactive Computer Graphics Contents
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 24/02/2019 Interactive Computer Graphics Contents
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. 24/02/2019 Interactive Computer Graphics Contents
6
Interactive Computer Graphics Contents
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 24/02/2019 Interactive Computer Graphics Contents
7
Interactive Computer Graphics Contents
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) 24/02/2019 Interactive Computer Graphics Contents
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; }; 24/02/2019 Interactive Computer Graphics Contents
9
Interactive Computer Graphics Contents
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 24/02/2019 Interactive Computer Graphics Contents
10
Implementing an Affine Space
class Point { double x,y,z; inline void sub(Point q, Vector * v) { v->i = q.x - p.x; v->j = q.y - p.y; v->k = 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; }; 24/02/2019 Interactive Computer Graphics Contents
11
Addition and Multiplication of Points
undefined vector BUT midpoint calculation point Recast in terms of legal operations: point point iff 24/02/2019 Interactive Computer Graphics Contents
12
Interactive Computer Graphics Contents
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 = 24/02/2019 Interactive Computer Graphics Contents
13
Interactive Computer Graphics Contents
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: 24/02/2019 Interactive Computer Graphics Contents
14
Interactive Computer Graphics Contents
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. 24/02/2019 Interactive Computer Graphics Contents
15
Interactive Computer Graphics Contents
Cross Product Variously known as the outer, cross or vector product. and Implementation: Vector::cross(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. 24/02/2019 Interactive Computer Graphics Contents
16
Interactive Computer Graphics Contents
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) Parametric ( parameter) 24/02/2019 Interactive Computer Graphics Contents
17
Interactive Computer Graphics Contents
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 24/02/2019 Interactive Computer Graphics Contents
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 24/02/2019 Interactive Computer Graphics Contents
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 24/02/2019 Interactive Computer Graphics Contents
20
Solution: Backface Culling
IF THEN RETURN ‘undefined’ IF THEN RETURN ‘side-on’ IF THEN RETURN ‘back-facing’ ELSE RETURN ‘front-facing’ 24/02/2019 Interactive Computer Graphics Contents
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 24/02/2019 Interactive Computer Graphics Contents
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: 24/02/2019 Interactive Computer Graphics Contents
23
Interactive Computer Graphics Contents
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/02/2019 Interactive Computer Graphics Contents
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. 24/02/2019 Interactive Computer Graphics Contents
25
Further 2D Transformations
Shear Parallel to an axis. By an angle . Rotate About the origin. Counter-clockwise by an angle . 24/02/2019 Interactive Computer Graphics Contents
26
Derivation of Rotation
24/02/2019 Interactive Computer Graphics Contents
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. 24/02/2019 Interactive Computer Graphics Contents
28
Transformation Matrices
Scale (by factors and ) Shear (parallel to by ) Reflect (in ) Rotate (by angle ) 24/02/2019 Interactive Computer Graphics Contents
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 24/02/2019 Interactive Computer Graphics Contents
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: 24/02/2019 Interactive Computer Graphics Contents
31
Matrices for Homogenous Co-ordinates
where is a standard transformation Translation: 24/02/2019 Interactive Computer Graphics Contents
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 24/02/2019 Interactive Computer Graphics Contents
33
Interactive Computer Graphics Contents
Order is Important Matrix multiplication is not commutative The order in which transformations are combined affects the outcome. 24/02/2019 Interactive Computer Graphics Contents
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 24/02/2019 Interactive Computer Graphics Contents
35
Matrices for Off-Origin Rotation
24/02/2019 Interactive Computer Graphics Contents
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 24/02/2019 Interactive Computer Graphics Contents
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, 24/02/2019 Interactive Computer Graphics Contents
38
Composite Reflection Matrices
24/02/2019 Interactive Computer Graphics Contents
39
Interactive Computer Graphics Contents
3D Transformations Employ 3D homogenous co-ordinates Transformation matrices: translation scaling reflection 24/02/2019 Interactive Computer Graphics Contents
40
Interactive Computer Graphics Contents
3D Rotations Rotation: (counterclockwise around the positive axis) about about about 24/02/2019 Interactive Computer Graphics Contents
41
Transformation Pipeline
Modelling Transform Object in object co-ordinates Object in world co-ordinates Viewing Transform Object in 2D screen co-ordinates Perspective Projection Object in viewing co-ordinates 24/02/2019 Interactive Computer Graphics Contents
42
Interactive Computer Graphics Contents
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 : 24/02/2019 Interactive Computer Graphics Contents
43
Interactive Computer Graphics Contents
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. 24/02/2019 Interactive Computer Graphics Contents
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 24/02/2019 Interactive Computer Graphics Contents
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 24/02/2019 Interactive Computer Graphics Contents
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, ); 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 24/02/2019 Interactive Computer Graphics Contents
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 tflat[16] is an expansion of T[4][4] arranged in columns ( i.e tflat[2] = tmat[0][2] ) The state of a matrix can be saved: glPushMatrix() saves the current matrix glPopMatrix() restores the last saved state 24/02/2019 Interactive Computer Graphics Contents
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 24/02/2019 Interactive Computer Graphics Contents
49
Interactive Computer Graphics Contents
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. 24/02/2019 Interactive Computer Graphics Contents
50
Interactive Computer Graphics Contents
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. 24/02/2019 Interactive Computer Graphics Contents
51
Example: Poor Euler Angle Interpolation
The interpolations and have the same start and end orientations but different intermediate orientations. 24/02/2019 Interactive Computer Graphics Contents
52
Interactive Computer Graphics Contents
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 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 24/02/2019 Interactive Computer Graphics Contents
53
Interactive Computer Graphics Contents
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 24/02/2019 Interactive Computer Graphics Contents
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. 24/02/2019 Interactive Computer Graphics Contents
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! 24/02/2019 Interactive Computer Graphics Contents
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.