C 335 Graphics and Multimedia D Graphics Primitives and Transformation
Basic Mathematical Concepts Review Coordinate Reference Frames D Cartesian Reference Frames (a) (b) creen Cartesian reference sstems : (a) coordinate origin at the lower-left screen corner and (b) coordinate origin in the upper-left corner
Polar Coordinates in the plane A coordinate position is specified with a radial distance r from the coordinate origin, and an angular displacement from the horizontal. r A polar coordinate reference frame, formed with concentric circles and radial lines.
Conversion between polar and Cartesian coordinates -ais r cos, r sin P Relationship between polar and Cartesian coordinate -ais The inverse transformation from Cartesian to polar coordinates is: r, tan
Definition of angle in radian In computer graphics applications, we usuall use radian, instead of degree, to measure angle. P r s s r An angle subtended b a circular arc of length s and r. Total angular distance around point πr P r π
D Points and vectors P ector in plane of Cartesian reference frame. P ( P P direction, α tan ) (, ) A vector encodes two pieces of information:. magnitude v if v we sa it is a unit vector or normalized vector. direction α
ector Math Add cale Dot product ( ) z z,, ),, ( z a a a a cos cos where is the angle between the two vectors 3 3 ) ( onl if and if z z
ector Product (cross product) Multiplication of two vectors to produce another vector. sin u u Where u is a unit vector that is perpendicular to both and cross product gives a vector in a direction perpendicular to the two original vectors (u) and with a magnitude equal to the area of the shaded parallelogram ),, ( z z z z z z z z Nice applet demo at: http://phsics.sr.edu/courses/java-suite/crosspro.html (ector Notation)
Properties of ector Cross Product Cross product of parallel vectors Anti-commutative Not associative ( ) ( ) ( ) 3 3 Distributive with respect to vector addition r iff parallelto ( ) ( ) ( ) 3 3
Basis ectors We can specif the coordinate aes in an reference frame with a set of vectors, one for each ais. For eamples, D Cartesian sstem : U (,), U (,) 3D Cartesian sstem : U (,,), U (,,), U z (,,) Orthonormal basis if : U k. U k for all k U j. U k for all j k
imple Primitives Point Cartesian Polar ( r, ) r
Lines Given and we can define the line l l t( ) This is a parametric vector equation: l l t( ) t( )
Parametric Lines l l t( ) t( ) Let the parameter t var to generate all points on the line: < t < alues of t at and give the endpoints of the line segment from to
Representing Lines lope-intercept form: m b Polar-coordinates: r cos r sin Perpendicular distance: cos sin p Implicit form: F (, ) a b c
Attributes Representations are enhanced with attached attributes: Lines: Tet: Thickness, stle (dotted, dashed) Brightness Color Join geometr Color Font tle ize
Eample: Java Attributes (Fig. 9.3) import java.awt.font;... private Font f;... f new Font ( Monospaced, Font.ITALIC Font.BOLD, 4);... g.setfont(f); int stle f.gettle(); int size f.getize();... if (stle Font.PLAIN) g.drawtring( Font stle is s,, 4); g.drawtring( Font famil is f.getfamil(),, 6);
Rendering Output Primitives: Lines Rendering, also known as rasterization, is the process of converting a mathematical representation into a visible image Representation: m b Check the tetbook (Hearn and Baker) for various rasteraiztion algorithms for lines
D Coordinate Transforms Basic Problem : Objects are tpicall defined in ideal coordinate sstem, e.g. ideal coordinate sstem for a circle is the origin coincides with the circle center. To draw object,. Transform from ideal to world coords. Transform from world coords ro device coords D Coordinate Transforms are used to transform to arbitrar - POITION Translation - CALE caling - ORIENTATION Rotation
Translation Move points of an object to new place. T (,) T, T T T Man points { ( i, i ) }b adding same constant T, T i i i i
Prosperities. No fied point under translation. - all points move.. Multiple translations are order-independent T T T T T T T T T T " "
Homogeneous coordinates T T ),, ( h h h h h h h Designed to combine multiplicative and translational operation in matri notation. Its etension to 3D also helps to combine perspective projection. (discussed later) h (usuall) in D case. Matri formulation (using homogeneous coordinate)
caling Changes size of ideal object, Properties : Origin fied : if! Order independent :
Matri formulation of cale cale in X direction: cale in Y direction: If we have a uniform scale
cale about an arbitrar fied origin (a) First translate, so that (, ) becomes origin (b) then scale (c) finall translate back ( ( ) ) (c) (b) (a)
Rotation Change angle : imple Proof r φ r cos φ r sin φ
rotate : r (, ) r cos( φ) r cosφ cos rsinφ sin r φ r (,) rsin( φ) rsinφ cos r cosφ sin Or: Want to rotate (,) to (, ) b angle cos sin sin cos
Matri formulation cos sin sin cos
Origin dependent but Choose origin (the fied point) ( ) ( ) cos sin ( ) sin ( ) cos (a) First translate, so that (, ) becomes origin (b) then rotate, (c) finall translate back
Other Transformations Reflection OR -, -, -
Be careful: Reflection is not equivalent to rotation Onl reflect about &, i.e. -, -, is a rotation. -, -
hear X hear h Y hear h We see origin is a fied point (not affected b shear)
Matri formulation h h hear Applet: http://www.cosc.canterbur.ac.nz/people/mukundan/cogr/heard.html
Order dependent!! αβ β β α α " " shear then shear β β αβ α α " " shear then shear
Undo the D Transformation INERE of the matri
Undo the D Transformation if If? is what " bc ad a c b d bc ad M d c b a M R p p R R p p R p
Proof a c b d d c b a bc ad MM d c b a a c b d bc ad M M For simplicit, we show matri formulation Not include the translation o how can we handle translation? er simple. impl appl -T if T is the translational matri
Eamples!! ) ( cos sin sin cos sin cos (Rotation) cos sin sin cos (caling) M M M M M
Order-dependenc of Transformations e.g. Two shears BA AB " " " αβ β α α β β α αβ β α matrices are order dependent!!
Another eample of order-dependenc e.g. NOT THE AME! Analtic Proof c s c s s c s c c s s c RT c s s c c s s c TR TR: R T RT: T R
Composite Transformations Represent a sequence of transformations as a product of 33 matrices (concatenation or composition): M M M 3 3 3 3 3 3 k K All transformation matrices can be multiplied together to be composed into a single 33 matri: M 3 3 composite
Efficienc It is more efficient to compute the single composite matri and then appl it to a large number of points rather than appling each transformation to all points in series For a single point: M M k M k M composite M M M LM composite k Number of multiplications for transformation of n points: 9kn 7 ( k ) 9n
The Transformation Pipeline n (points) n (points) k 9 8 8 36 7 54 36 7 45 9 k 9 36 8 45 7 54 36 63 45 7 7 54 8 8 35 63 7 8 9 35 36 7 8 44 8 9 99 8 7 6 45 9 35 8 5 7 6 35 44 53 9kn 7 ( k ) 9n
More Powerful Basic transformations are limited Combination of transformations allows more general geometric manipulations scaling: scale onl in and direction scale with respect to origin as fied point rotation: pivot point is origin onl
Composite Transformations Combined effect of two translations: 4 3 T T 7 3 T composite
Translation (, ) t (,) t
Composing cales s s m m m s m s
caling (, ) (,) (shown w.r.t. origin)
Composing Rotations R R φ cos sin sin cos cos sin sin cos φ φ φ φ
Rotation (, ) φ (,) (rotation w.r.t. origin)
General Fied-Point caling original position T translation of desired fied point to origin T scale T T translation of desired pivot point back to original position
Eample: cale about (F, F) ) ( ) ( F F F F F F F F F F F F F F F F F F F F imilarl, we could derive fied pt. equation for rotation, shear,...
General Pivot Point Rotation original position T translation of desired pivot point to origin R T rotation T R T translation of desired pivot point back to original position
General Pivot Point Rotation translation of desired pivot point to origin original position rotation translation of desired pivot point back to original position
General caling Directions Desired scaling direction T Translate fied point to origin R T Align scaling direction with ais original position R T R R T Translate back cale along ais Rotate back T R R T
Composition Order Matri multiplication is associative: ABC (AB)C A(BC) Transformation products ma not be commutative: AB BA Order is important!
ummar Mathematical Review Points, ectors, Dot Product, Crossproduct (important) Line Representation Translation, Rotation, cale, hear Matri Notation Homogeneous Coordinates Matri Concatenation for transform Order of concatenation ver important!