1 / 44

Transformaciones geométricas

Transformaciones geométricas. 2D y 3D. ¿ Cómo usamos las transformaciones geométricas ?. Los objetos de una escena son colecciones de puntos … Estos objetos tiene posición , orientación , tamaño

esma
Download Presentation

Transformaciones geométricas

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Transformacionesgeométricas 2D y 3D

  2. ¿Cómousamoslastransformacionesgeométricas? Los objetos de unaescena son colecciones de puntos… Estosobjetostieneposición, orientación, tamaño Corresponde a lastransformaciones, Translación (), Rotación (), y Escalamiento ()

  3. ¿Cómousamoslastransformacionesgeométricas? (2/2) Unaescenatieneunacámara/punto de vista desde el cual se renderiza la escena. La cámaratieneunaposición y orientación en el espacio 3D… Éstoscorresponden a lastransformaciones de Traslación y Rotación Se necesitanotrostipos de transformaciones de vista también – lasveremosahora

  4. Algunosconceptos de álgebra lineal… • Geometría de coordenadas 3D • Vectores en espacios 2D y 3D • Productopunto y productocruz – definiciones y usos • Notación y álgebravectorial y matricial • Matrizidentidad • Asociatividadmultiplicativa • Ej. A(BC) = (AB)C • Traspuesta e inversa de matriz – definición, uso y cálculo • Coordenadashomogéneas () • ¡Necesitaránentenderestosconceptos! • Una “ayudaíta” (en inglés) -> http://cs.brown.edu/courses/cs123/resources/Linear_Algebra.pdf

  5. Transformacioneslineales (1/3) b a = a + b • Representamos los vectorescomoletras en bold-itálica() y escalarescomoletras en itálicasolamente(c) • Cualquier vector en el planopuedeserdefinidocomo la suma de dos vectores base no co-lineares en el plano • Recordemosqueuna base es un conjunto de vectoresquecumplen dos propiedades: • Los vectores son linealmenteindependientes • Cualquier vector en el espaciovectorialpuedesergeneradoporunacombinación lineal de la base • Las constantesescalarespuedenserusadasparaajustarmagnitud y dirección del vector resultante

  6. Transformacioneslineales (2/3) • Definición de unafunción lineal, f: • fdonde el dominio y co-dominio de fson idénticos • La función de unaadición de vectoresesequivalente a la adición de la funciónaplicada a cadauno de los vectores • La función de unamultiplicaciónescalar con un vector es un escalarmultiplicadopor la funciónaplicada al vector • Ambas de estaspropiedadesdebensersatisfechasparaquef sea un operador lineal

  7. Transformacioneslineales (3/3) • Usográfico: transformaciones de puntosalrededor del origen (dejandoinvariante al origen) • Estoincluye al escalamiento y a lasrotaciones (pero no a la translación), • La translación no esunafunción lineal (mueve el origen) • Cualquiertransformación lineal de un puntoresultará en otropunto en el mismosistema de coordenadas, transformadosobre el origen

  8. Transformacioneslinealescomo matrices (1/2) Las TransformacionesLinealespuedenserrepresentadascomo matrices no singulares (invertibles) Comencemos con lastransformaciones 2D: = La matrizpuedesertambiénescritacomo: , donde = , = Donde y son los vectoresunitariosestandarsobre los vectores x e y: = = ¿Porquéesimportanteesto? Estosignificaquepodemoscomputarlascolumnas de la matriz de transformaciónunaporunadeterminandocomonuestratransformaciónafectacadauno de los vectoresunitariosestándar. Por lo que “ mandaa = “ Use estaestrategiaparaderivarlas matrices de transformación

  9. Transformacioneslinealescomo matrices (2/2) • Unatransformación de un vector columnaarbitrariotiene la forma: = • Sustituyamospor = • La transformaciónaplicada a es la primeracolumna de • Ahorasustituyamospor = • La transformaciónaplicacada a es la segundacolumna de

  10. Escalando en 2D (1/2) Efecto lateral: la casa cambia suposiciónrelativa al origen • Escalemos por 3, por 2 (Sx = 3, Sy = 2) • = (vértice original); = (nuevovértice) • Derivemosdeterminandocómoy deberíansertransformadas • =  * = (Escalar en X por) , la primeracolumna de • = * = (Escalar en Y por), la segundacolumna de • Por lo tantoobtenemos:

  11. Escalando en 2D (2/2) • Otras propiedades del escalamiento: • No conserva longitudes en los objetos • No conserva los ángulos entre partes de los objetos, a menosque el escalamiento sea uniforme,) • Si el objeto no está en suorigen, traslada la casa relativa al origen – algocomúnmente no deseado… • esunamatriz diagonal – se puedeconfirmar la derivaciónsimplementemirandolaspropiedades de las matrices diagonales: • = • En dondeesunamatriz diagonal • La posición de = (posición sobre la diagonal deposición de ) • multiplicacadacoordenada de unapor los factores de escalamiento() especificadosporlasposicionessobre la diagonal, como se espera • = , =

  12. Rotación en 2D (1/2) • Rotar poralrededor del origen • donde • = (vértice original) • = (vérticenuevo) • Derivemosdeterminandocómoy deberíantransformarse • =  , primeracolumna de • = , segundacolumna de • Y asíobtenemos:

  13. Rotación en 2D(2/2) • Intentemos multiplicarlas matrices • = = ’ • Otraspropiedades de la rotación: • Conserva longitudes y ángulos entre partes de los objetos • La rotaciónes de cuerporígido • Para objetosque no están en el origen, nuevamenteunatraslaciónpuede no serdeseada (i.e. estorotaalrededor del origen, no alrededor del centro de rotación de la casa)

  14. ¿Qué hay sobre la traslación? • Si tratamostodaslastransformaciones de unamaneraconsistente, esdecir, con representación de matrices, entoncespodríamoscombinarlastrnasformaciones al componersus matrices • Usemosnuevamenteunamatriz • ¿Cómo? Con coordenadashomogéneas: agregaunadimensiónadicional, el eje w, y unacoordenada extra, el componente w. • Y así2D -> 3D (efectivamente el hiperespacioparacolocar el espacio 2D) • La traslación no esunatransformaciónlinea (no centradaalrededor del origen) • No puedeserrepresentadacomounamatriz 2x2 invertible… • Pregunta: ¿Hay algunaotrasolución? • Respuesta: Sí, , donde • Sumarparatrasladar, estoesinconsistente.

  15. Coordenadashomogéneas(1/3) • Permite la expresión de todaslastransformaciones 2D como matrices 3x3 • Comenzamos con el punto en el plano y aplicamos un mapeoparallevarloal plano-w en el hiperespacio • Las coordenadasresultantes(’, ’) en nuestronuevopuntoson diferentes del original (, ) , donde’ = , ’ =

  16. Coordenadashomogéneas(2/3) • Una vezquetenemosestepuntopodemosaplicarunaversiónhomogeneizada de nuestras matrices de transformación (próximasláminas) parallevarlo a un nuevopunto en el hiperespacio • Finalmente, queremosobtener el puntoresultante en el espacio 2D nuevamente, asíquehacemos un reverso del mapeo anterior (dividimostodaslasentradaspor) • Estoconviertenuestropunto en el hiperespacio al puntocorrespondiente en el epsacio 2D • El vérticeahora es representado como

  17. Coordenadashomogéneas(3/3) • Hacerquelastransformacionesmapeenpuntos en el hiperplano a otropunto en el hiperplano. Las transformacionesaplicadas a un punto en el hiperplanosiempresacar un resultadotambién en el mismohiperplano (clausuramatemática) • La transformaciónaplicada a se corresponde con • ¿Cómoaplicamosesto a nuestras matrices de transformación? • Para transformacioneslineales, mantenemosuna sub-matriz 2x2, expandimos la matrizcomoaparece a continuación, dondeparalastransformaciones 2D, la submatriz superior izquierdaes la queincluye el escalamiento o la matriz de rotaciónderivadaanteriormente:

  18. De vuelta a la traslación Nuestramatriz de traslación() puedeahoraserrepresentada al incluir el vector de traslación en la columnaderecha en el tope como: Pruébalo, multiplícalopor el vérticehomogenizado = = = ’ Las coordenadastrasladadas, ’siguenhomogéneas

  19. Transformacioneshomogenizadas La traslaciónusaunamatriz 3x3, pero el escalamiento y la rotación son matrices 2x2 ¡Homogenicemos! Esto no afecta la propiedad lineal del escalamiento y la rotación Nuetrasnuevas matrices de transformación se veránasí… Nota: estas 3 transformaciones se le llamantransformacionesafines.

  20. Ejemplos Escalado: Escalarpor 15 en la dirección, 17 en la Rotación: Rotarpor1 Traslación: Trasladarpor-16 en el eje, +18 en el

  21. ¡Antes de continuar! Vectores vs. Puntos Hasta ahora, sólohemosusar la noción de un punto en nuestroespacio 2D. Ahoradebemospresentarunadistinción entre vectores y puntos. Usamoslascoordenadashomogéneaspararepresentarmásconvenientemente la traslación; luego los puntos se representancomo(x, y, 1)T Un vector puedeserrotado o escalado, pero no trasladado (porquesiemprecomienza en el origen), no uses la coordenadahomogénea(x, y, 0)T Porahora, enfoquémonossolamente en los puntos(típicamentevértices)

  22. Inversas How do we find the inverse of a transformation? Take the inverse of the transformation matrix (thanks to homogenization, they’re all invertible!):

  23. More with Homogeneous Coordinates Some uses we’ll be seeing later • Placing sub-objects in parent’s coordinate system to construct hierarchical scene graph • transforming primitives their own coordinate systems • View volume normalization • mapping arbitrary view volume into canonical view volume along -axis • Parallel (orthographic, oblique) and perspective projection • Perspective transformation (turn viewing pyramid into a cuboid to turn perspective projection into parallel projection)

  24. A moment of appreciation for linear algebra • The inverse of a rotation matrix is just its transpose, That’s really convenient, so let’s understand how it works… • Take a rotation matrix = • First note these properties of • Columns are orthogonal to each other: vi•vj = 0 (ij) • Columns represent unit length vectors: ||vi|| = 1 • Let’s see what happens when we multiply • = • Using the properties we defined we can see that the result is the identity matrix , thus , and by definition of matrix inverse, matrix must be inverse of

  25. Composition of Transformations (2D) (1/2) We now have a number of tools at our disposal, we can combine them! An object in a scene uses many transformations in sequence, how do we represent this in terms of functions? Transformation is a function; by associativity we can compose functions: ( This is the same as first applying to some input and then applying : ( Consider our functions as matrices ( and respectively) and our input as a vector () Our composition is equivalent to

  26. Composition of Transformations (2D) (2/2) We can now form compositions of transformation matrices to form a more complex transformation For example,, which scales point, then rotates, then translates: Note that we apply the matrices in sequence right to left, but practically, given associativity, we can compose them and apply the composite to all the vertices in, say, a mesh. Important: Order Matters! Matrix Multiplication is not commutative. Be sure to check out the Transformation Game at http://www.cs.brown.edu/exploratories/freeSoftware/repository/edu/brown/cs/exploratories/applets/transformationGame/transformation_game_guide.html Let’s see an example…

  27. 6 6 5 5 4 4 Y 3 3 2 2 1 1 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 X Not commutative Translate by =6, =0 then rotate by 45º Rotate by 45º then translate by =6, =0

  28. Composition (an example) (2D) (1/2) Rotate 90 Uniform Scale 3x Both around object’s center, not the origin • Start: Goal: • Important concept: Make the problem simpler • Translate object to origin first, scale , rotate, and translate back: • Apply to all vertices

  29. Composition (an example) (2D) (2/2) • But what if we mixed up the order? Let’s try • Oops! We managed to scale it properly but when we rotated it we rotated the object about the origin, not its own center, shifting its position…Order Matters!

  30. 6 5 4 Y 3 2 1 0 1 2 3 4 5 6 7 8 9 10 X Aside: Skewing/shearing • “Skew” an object to the side, like shearing a card deck by displacing each card relative to the previous one • What physical situations mirror this behavior?!? • Squares become parallelograms - coordinates skew to right, stays same • Notice that base of house (at =1) remains horizontal, but shifts right - why? 2D non-Homogeneous 2D Homogeneous

  31. Inverses Revisited What is the inverse of a sequence of transformations? Inverse of a sequence of transformations is the composition of the inverses of each transformation in reverse order Say we want to do the opposite transform of the example on Slide 27, what will our sequence look like? We still translate to origin first, then translate back at the end!

  32. Aside: Windowing Transformations Windowing transformation maps contents of a 2D clip rectangle ("window") to a rectangle on the screen, e.g., interior canvas of a window manager's window ("viewport"), so also known as window-to-viewport transformation Sends rectangle with bounding coordinatesto

  33. Aside: Transforming Coordinate Axes Translation Rotation Scaling We understand linear transformations as changing the position of vertices relative to the standard axes Can also think of transforming the coordinate axes themselves Just as in matrix composition, be careful of which order you modify your coordinate system

  34. Dimension++ (3D!) How should we treat geometric transformations in 3D? Just add one more coordinate/axis! A point is represented as A matrix for a linear transformation can be represented as where corresponds to the z-coordinate, But remember to use homogeneous coordinates! Thus embed the scale and rotation matrices upper left submatrix, translation vector upper right column

  35. Transformations in 3D

  36. Rodrigues’s Formula… Note: This is an arbitrary unit vector in space • Rotation by angle around v = • Here’s a not so friendly rotation matrix: • This is called the coordinate form of Rodrigues’s formula • Let’s try a different way…

  37. Rotating axis by axis (1/2) • Every rotation can be represented as the composition of 3 different angles of counter-clockwise rotation around 3 axes, namely • -axis in the plane by • -axis in the plane by • -axis in the plane by • Also known as Euler angles, makes problem of rotation much easier • : rotation around axis, : rotation about axis, : rotation about axis • Note these differ only in where the 3x3 submatrix is embedded in the homogeneous matrix • You can compose these matrices to form a composite rotation matrix

  38. Rotating axis by axis (2/2) It would still be difficult to find the 3 angles to rotate by, given arbitrary axis and specified angle Solution? Make the problem easier by mapping uto one of the principal axes Step 1: Find a to rotate around axis to put in the plane Step 2: Then find a to rotate around the axis to align with the axis Step 3: Rotate by around axis = coincident axis Step 4: Finally, undo the alignment rotations (inverse) Rotation Matrix:

  39. Inverses and Composition in 3D! • Inverses are once again parallel to their 2D versions… • Composition works exactly the same way…

  40. Example in 3D! Let’s take some 3D object, say a cube, centered at (2,2,2) Rotate in object’s space by 30 around axis, 60 around and 90around Scale in object space by 1 in the , 2 in the , 3 in the Translate by (2,2,4) in world space Transformation Sequence: , where translates to

  41. Scene Graph ROBOT upper body lower body base stanchion head trunk arm Transformations and the scene graph (1/4) arm • Objects can be complex: • 3D scenes are often stored in a directed acyclic graph (DAG) called a scene graph • WPF • Open Scene Graph (used in the Cave) • Sun’s Java3D™ • X3D ™ (VRML ™ was a precursor to X3D) • Typical scene graph format: • objects (cubes, sphere, cone, polyhedra etc.): stored as nodes (default: unit size at origin) • attributes (color, texture map, etc.) stored as separate nodes • transformations are also nodes

  42. Transformations and the scene graph (2/4) • For your assignments use simplified format: • Attributes stored as a components of each object node (no separate attribute node) • Transform node affects its subtree • Only leaf nodes are graphical objects • All internal nodes that are not transform nodes are group nodes Step 1: Various transformations are applied to each of the leaves (object primitives—head, base, etc.) Step 2: Transformations are then applied to groups of these objects as a whole (upper body, lower body) Together this hierarchy of transformations forms the “robot” scene as a whole Represents a transformation

  43. Transformations and the scene graph (3/4) object nodes (geometry) transformation nodes group nodes • Notion of a cumulative transformation matrix that builds as you move up the tree (), appending higher level transformation matrices to the front of your sequence • Example: • For o1, • For o2, • For o3, • For a vertex v in o3, position in world (root) coordinate system is:

  44. group3 root group1 obj4 obj3 obj1 group3 group2 obj2 group3 Transformations and the scene graph (4/4) You can reuse groups of objects (sub-trees) if they have been defined Group 3 has been used twice here Transformations defined within group 3 itself are the same Different s for each use of group 3as a whole

More Related