ACSC330 - Computer Graphics

advertisement
ACSC330 - Computer Graphics
Chapter 4, Part A – Geometric Objects and Transformations
How to represent basic geometric types
How to convert between various representations
What statements to make about geometric objects, independent of a particular
representation.
Some mathematical background is necessary; cause of the desire to manipulate a few
basic geometric data types – vector spaces, geometry and linear algebra.
Scalars, Points and Vectors
Point – the fundamental geometric object – a location in the space.
Scalars – objects that obey a set of rules that are abstractions of the operations of ordinary
arithmetic.
Vector – to allow the working with directions.
In computer graphics, connect points with directed line segments. A line segment has both
magnitude – its length – and direction – its orientation – and thus it is a vector.
Vector = directed line segment
additions of two vectors, multiplication of a vector by a scalar
point-vector addition: a directed line segment to move from a point to another.
point-point subtraction: any two points define a line segment or vector between them.
Start with coordinate-free geometry
Vector space: vectors and scalars (scalar-vector multiplication, vector-vector addition).
Affine space: an extension of the vector space that includes the point.
Abstract data types (ADTs): a set of operations on data; the operations are defined
independently of how the data are represented internally or of how the operations are
implemented.
A plane in an affine space can be defined as a direct extension of the parametric line (three
points, not on the same line, determine a unique plane).
Three-Dimensional Primitives
In 3D world, a far greater variety of geometric objects than in 2D.
Objects are no longer restricted to lie in the same plane (curves in space, surfaces in space,
objects with volumes e.g. parallelepipeds and ellipsoids) – much more complex
mathematical definitions.
Dr. Stephania Loizidou Himona – Chapter 4 - ACSC330 Computer Graphics
Three features characterise objects that fit well with existing graphics hardware and
software because most modern graphics systems render triangular, or other flat,
polygons:
1. The objects are described by their surfaces and can be thought of as being hollow.
2. The objects can be specified through a set of vertices in 3D.
3. The objects either are composed of or can be approximated by flat convex
polygons.
Constructive solid geometry (CSG) – build objects from a small set of volumetric objects
through set operations (union, intersection).
.
.
.
Transformations
A transformation is a function that takes a point (or vector) and maps that point (or vector)
to another point (or vector) i.e. combined mathematical operations.
Geometric transformation: the object moves relatively to a fixed coordinate system, or a
fixed background.
Coordinate transformation: the object is fixed and the coordinate system is moved
relatively to the object.
Object: set of points
Translation, Rotation and Scaling
Translation is an operation that displaces points by a fixed distance in a given direction (a
straight-line movement of an object from one position to another).
To specify a translation, only a displacement vector needs to be specified.
e.g. translate a point from coordinate position (x, y) to a new position (x’, y’) by adding
translation distances, Tx and Ty, to the original coordinates:
x’ = x + Tx;
y’ = y + Ty
(Tx, Ty) is also called a translation vector or shift vector. Translation distances can be
specified as any real numbers (positive, negative, or zero).
Scaling is a transformation that alters the size of an object. This operation can be carried
out for polygons by multiplying the coordinate values (x, y) for each boundary vertex by
scaling factors Sx and Sy to produce transformed coordinates (x’, y’):
x’ = x . Sx
y’ = y . Sy
i.e. scaling factors Sx scales objects in the x direction, while Sy scales in the y direction.
Any positive numeric values can be assigned to the scaling factors Sx and Sy. Values less
than 1 reduce the size of objects; values greater than 1 produce an enlargement
2
Dr. Stephania Loizidou Himona – Chapter 4 - ACSC330 Computer Graphics
(specifying a value of 1 for both Sx and Sy leaves the size of objects unchanged). When
Sx and Sy are assigned the same value, a uniform scaling is produced, which maintains
relative proportions of the scaled object. Unequal values for Sx and Sy are often used in
design applications, where pictures are constructed from a few basic shapes that can be
modified by scaling transformations.
Rotation is the transformation of object points along circular paths. This is specified with
a rotation angle, which determines the amount of rotation for each vertex of a polygon.
x’ = r cos θ
y’ = r sin θ
where r is the distance of the point from the origin.
Positive values of θ in these equations indicate a counterclockwise rotation, and negative
values for θ rotate objects in a clockwise direction.
Matrix Representations and Homogeneous Coordinates
There are many applications that make use of the basic transformations in various
combinations. A picture, built up from a set of defined shapes, typically requires each
shape to be scaled, rotated, and translated to fit into the proper picture position. This
sequence of transformations could be carried out one step at a time. First, the coordinates
defining the object could be scaled, then these scaled coordinates could be rotated, and
finally, the rotated coordinates could be translated to the required location. A more
efficient approach is to calculate the final coordinates directly from the initial coordinates
using matrix methods, with each of the basic transformations expressed in matrix form.
Transformation equations could be written in a consistent matrix form by first expressing
points as homogeneous coordinates. This means that we represent a two-dimensional
coordinate position (x, y) as the triple [xh, yh, w], where
Xh = x . w
yh = y . w
The parameter w is assigned a nonzero value in accordance with the class of
transformations to be represented (called the dummy coordinate). In the above
transformations w was set to 1, i.e. [x, y, 1].
With coordinate positions expressed in homogeneous form, the basic transformation
equations can be represented as matrix multiplications employing 3x3 transformation
matrices. For example, for translation,
[x’ y’ 1] = [x y 1]
1
0
0
1
Tx Ty
0
0
1
Similarly, the scaling equations can now be written as
[x’ y’ 1] = [x y 1]
Sx 0
0 Sy
0
0
0
0
1
3
Dr. Stephania Loizidou Himona – Chapter 4 - ACSC330 Computer Graphics
Equations for rotation are written in matrix form as
[x’ y’ 1] = [x y 1]
cosθ sinθ 0
-sinθ cosθ 0
0
0 1
Matrix representations are standard methods for implementing the basic transformations in
graphics systems. In many systems, the scaling and rotation transformations are always
stated relative to the coordinate origin. Rotations and scalings relative to other points are
handled as a sequence of transformations. An alternative approach is to state the
transformation matrix for scaling in terms of the fixed-point coordinates and to specify
the transformation matrix for rotation in terms of the pivot-point coordinates.
Composite Transformations
Any sequence of transformations can be represented as a composite transformation matrix
by calculating the product of the individual transformation matrices. Forming products by
transformation matrices is usually referred to as a concatenation, or composition, of
matrices.
Translations
Two successive translations of an object can be carried out by first concatenating the
translations matrices, then applying the composite matrix to the coordinate points.
Specifying the two successive translation distances as (Tx1, Ty1) and (Tx2, Ty2), we
calculate the composite matrix as
1
0 0
0
1 0
Tx1 Ty2 1
1
0
0
1
Tx2 Ty2
0
0
1
=
1
0
0
0
1
0
Tx1+Tx2 Ty1+Ty2 1
which demonstrates that two successive translations are additive.
Scalings
Concatenating transformation matrices for two successive scaling operations produces the
following composite scaling matrix:
S(Sx1, Sy1) . S(Sx2, Sy2) = S(Sx1.Sx2, Sy1.Sy2)
The resulting matrix in this case indicates that successive scaling operations are
multiplicative. That is, if we were to triple the size of an object twice in succession, the
final size would be nine times that of the original.
4
Dr. Stephania Loizidou Himona – Chapter 4 - ACSC330 Computer Graphics
Rotations
The composite matrix for two successive rotations is calculated as
R(θ1) . R(θ2) = R(θ1 + θ2)
As is the case with translations, successive rotations are additive.
Scaling relative to a fixed point
For scaling with respect to a fixed point consider a sequence of three transformations. First,
all the coordinates are translated so that the fixed point is moved to the coordinate origin.
Second, the coordinates are scaled with respect to the origin. Third, the coordinates are
translated so that the fixed point is returned to its original position. The matrix
multiplication for this sequence yield
1
0
-xf
0
1
-yf
0
0
1
Sx
0
0
0
Sy
0
0
0
1
1
0
xf
0
1
yf
0
0
1
Sx
0
0
0
Sy
0
(1-Sx)xf (1-Sy)yf 1
Rotation about a Pivot Point
i.e. rotation about a specific pivot point (xr, yr). First, the object is translated so that the
pivot point coincides with the coordinate origin. Second, the object is rotated about the
origin. Third, the object is translated so that the pivot point returns to its original position.
This sequence is represented by the matrix product:
1
0
-xr
0
1
-yr
0
0
1
cosθ sinθ
-sinθ cosθ
0
0
0
0
1
1
0
xr
0
1
yr
0
0
1
=
cosθ
-sinθ
(1-cosθ)xr+yr.sinθ
sinθ
cosθ
(1-cosθ)yr-xr.sinθ
0
0
1
Arbitrary Scaling Directions
Scaling parameters Sx and Sy affect only the x and y directions. Objects can be scaled in
other directions by performing a combination of rotation and scaling transformations.
Note: Matrix multiplication is associative. That is, for any three matrices, A, B and C, the
matrix product A . B. C can be performed by first multiplying A and B or by first
multiplying B and C:
A . B . C = (A . B) . C = A . (B . C)
Therefore, we can evaluate composite matrices in either order.
5
Dr. Stephania Loizidou Himona – Chapter 4 - ACSC330 Computer Graphics
On the other hand, composite transformations may not be commutative: The matrix product
A . B is not equal to B . A, in general. This means that if we want to translate and rotate
an object, we must be careful about the order in which the composite matrix is evaluated.
For some special cases, the multiplication of transformation matrices is commutative.
Two successive transformations of the same kind are commutative. For example, two
successive rotations could be performed in either order and the final position would be
the same. This commutative property holds also for two successive translations or two
successive scalings. Another commutative pair of operations is a uniform scaling (Sx =
Sy) and a rotation.
General Transformation Equations
Any special transformation, representing a combination of translations, scalings, and
rotations can be expressed as
a
b
c
[x’ y’ 1] = [x y 1]
d
e
f
0
0
1
Explicit equations for calculating the transformed coordinates are then
x’ = ax + by + c
y’ = dx + ey +f
Other transformations
Reflection
A reflection is a transformation that produces a mirror image of an object. The mirror
image is generated relative to an axis of reflection.
Objects can be reflected about the x axis using the following transformation matrix
1
0
0
0
-1
0
0
0
1
This transformation keeps x values the same, but ‘flips’ the y values. Similarly, a reflection
about the y axis flips the x coordinates while keeping y coordinates the same:
-1
0
0
0
1
0
0
0
1
6
Download