Saltar al contenido principal
LibreTexts Español

14.2: Transformaciones afín

  • Page ID
    115233
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    En esta sección, vamos a explorar diferentes tipos de matrices de transformación. El siguiente código está diseñado para demostrar las propiedades de algunas matrices de transformación diferentes.

    Hacer esto

    Revisa el siguiente código.

    #Some python packages we will be using
    %matplotlib inline
    import numpy as np
    import matplotlib.pylab as plt
    from mpl_toolkits.mplot3d import Axes3D #Lets us make 3D plots
    import numpy as np
    import sympy as sym
    sym.init_printing(use_unicode=True) # Trick to make matrixes look nice in jupyter
    # Define some points
    x = [0.0,  0.0,  2.0,  8.0, 10.0, 10.0, 8.0, 4.0, 3.0, 3.0, 4.0, 6.0, 7.0, 7.0, 10.0, 
         10.0,  8.0,  2.0, 0.0, 0.0, 2.0, 6.0, 7.0,  7.0,  6.0,  4.0,  3.0, 3.0, 0.0]
    y = [0.0, -2.0, -4.0, -4.0, -2.0,  2.0, 4.0, 4.0, 5.0, 7.0, 8.0, 8.0, 7.0, 6.0,  6.0,
         8.0, 10.0, 10.0, 8.0, 4.0, 2.0, 2.0, 1.0, -1.0, -2.0, -2.0, -1.0, 0.0, 0.0]
    con = [ 1.0 for i in range(len(x))] 
    
    p = np.matrix([x,y,con])
    
    
    mp = p.copy()
    
    #Plot Points
    plt.plot(mp[0,:].tolist()[0],mp[1,:].tolist()[0], color='green');
    plt.axis('scaled');
    plt.axis([-10,20,-15,15]);
    plt.title('Start Location');

    Ejemplo de matriz de escalado

    #Example Scaling Matrix
    
    #Define Matrix
    scale = 0.5  #The amount that coordinates are scaled.
    S = np.matrix([[scale,0,0], [0,scale,0], [0,0,1]])
    
    #Apply matrix
    
    mp = p.copy()
    mp = S*mp
    
    #Plot points after transform
    plt.plot(mp[0,:].tolist()[0],mp[1,:].tolist()[0], color='green')
    plt.axis('scaled')
    plt.axis([-10,20,-15,15])
    plt.title('After Scaling')
    
    #Uncomment the next line if you want to see the original.
    # plt.plot(p[0,:].tolist()[0],p[1,:].tolist()[0], color='blue',alpha=0.3);
    
    sym.Matrix(S)

    Ejemplo de Matriz de Traducción

    #Example Translation Matrix
    
    #Define Matrix
    dx = 1  #The amount shifted in the x-direction
    dy = 1  #The amount shifted in the y-direction
    T = np.matrix([[1,0,dx], [0,1,dy], [0,0,1]])
    
    #Apply matrix
    
    mp = p.copy()
    
    mp = T*mp
    
    #Plot points after transform
    plt.plot(mp[0,:].tolist()[0],mp[1,:].tolist()[0], color='green')
    plt.axis('scaled')
    plt.axis([-10,20,-15,15])
    plt.title('After Translation')
    
    #Uncomment the next line if you want to see the original.
    # plt.plot(p[0,:].tolist()[0],p[1,:].tolist()[0], color='blue',alpha=0.3);
    
    sym.Matrix(T)

    Ejemplo de matriz de reflexión

    #Example Reflection Matrix
    
    #Define Matrix
    Re = np.matrix([[1,0,0],[0,-1,0],[0,0,1]]) ## Makes all y-values opposite so it reflects over the x-axis.
    
    #Apply matrix
    
    mp = p.copy()
    
    mp = Re*mp
    
    #Plot points after transform
    plt.plot(mp[0,:].tolist()[0],mp[1,:].tolist()[0], color='green')
    plt.axis('scaled')
    plt.axis([-10,20,-15,15])
    
    #Uncomment the next line if you want to see the original.
    # plt.plot(p[0,:].tolist()[0],p[1,:].tolist()[0], color='blue',alpha=0.3);
    
    sym.Matrix(Re)

    Ejemplo de matriz de rotación

    #Example Rotation Matrix
    
    #Define Matrix
    degrees = 30
    theta = degrees * np.pi / 180  ##Make sure to always convert from degrees to radians. 
    
    # Rotates the points 30 degrees counterclockwise.
    R = np.matrix([[np.cos(theta),-np.sin(theta),0],[np.sin(theta), np.cos(theta),0],[0,0,1]]) 
    
    #Apply matrix
    mp = p.copy()
    
    mp = R*mp
    
    #Plot points after transform
    plt.plot(mp[0,:].tolist()[0],mp[1,:].tolist()[0], color='green')
    plt.axis('scaled')
    plt.axis([-10,20,-15,15])
    
    #Uncomment the next line if you want to see the original.
    # plt.plot(p[0,:].tolist()[0],p[1,:].tolist()[0], color='blue',alpha=0.3);
    
    sym.Matrix(R)

    Ejemplo de matriz de cizallamiento

    Combinar Transformas

    Tenemos cinco transformaciones\(R\),\(S\)\(T\),\(Re\), y\(SH\)

    Hacer esto

    Construir una (\(3 \times 3\)) Matriz de transformación (llamada\(M\)) que combina estas cinco transformaciones en una sola matriz. Puedes elegir diferentes órdenes para estas cinco matrices, luego comparar tu resultado con otros alumnos.

    #Put your code here
    #Plot combined transformed points
    mp = p.copy()
    mp = M*mp
    plt.plot(mp[0,:].tolist()[0],mp[1,:].tolist()[0], color='green');
    plt.axis('scaled');
    plt.axis([-10,20,-15,15]);
    plt.title('Start Location');
    Preguntas

    ¿Se pudo obtener el mismo resultado con otros? Se puede comparar la matriz\(M\) para ver la diferencia. Si no, ¿puedes explicar por qué sucede?

    Ejemplo Interactivo

    from ipywidgets import interact,interact_manual
    
    def affine_image(angle=0,scale=1.0,dx=0,dy=0, shx=0, shy=0):
        theta = -angle/180  * np.pi
        
        plt.plot(p[0,:].tolist()[0],p[1,:].tolist()[0], color='green')
        
        S = np.matrix([[scale,0,0], [0,scale,0], [0,0,1]])
        SH = np.matrix([[1,shx,0], [shy,1,0], [0,0,1]])
        T = np.matrix([[1,0,dx], [0,1,dy], [0,0,1]])
        R = np.matrix([[np.cos(theta),-np.sin(theta),0],[np.sin(theta), np.cos(theta),0],[0,0,1]])
        
        #Full Transform
        FT = T*SH*R*S;
        #Apply Transforms
        p2 =  FT*p;
        
        #Plot Output
        plt.plot(p2[0,:].tolist()[0],p2[1,:].tolist()[0], color='black')
        plt.axis('scaled')
        plt.axis([-10,20,-15,15])
        return sym.Matrix(FT)
    ##TODO: Modify this line of code
    interact(affine_image, angle=(-180,180), scale_manual=(0.01,2), 
             dx=(-5,15,0.5), dy=(-15,15,0.5), shx = (-1,1,0.1), shy = (-1,1,0.1));

    También se puede usar el siguiente comando pero puede ser lento en las computadoras de algunas personas.

    ##TODO: Modify this line of code
    #interact(affine_image, angle=(-180,180), scale=(0.01,2),
    #			dx=(-5,15,0.5), dy=(-15,15,0.5), shx = (-1,1,0.1), shy = (-1,1,0.1));
    Hacer esto

    Usando el ambiente interactivo anterior para ver si puedes averiguar la matriz de transformación para hacer la siguiente imagen:

    Un ejemplo de transformación.
    Pregunta

    ¿Cuáles son los valores de entrada?


    This page titled 14.2: Transformaciones afín is shared under a CC BY-NC 4.0 license and was authored, remixed, and/or curated by Dirk Colbry via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.