Transformations (Transformations v0.1.0) View Source

Transformations is an Elixir library for translating, rotating, reflecting, scaling, shearing, projecting, orthogonalizing, and superimposing arrays of 3D homogeneous coordinates as well as for converting between rotation matrices, Euler angles, and quaternions. Also includes an Arcball control object and functions to decompose transformation matrices.

Link to this section Summary

Functions

Create a new matrix.

Mirror a shape around the yz plane or the x-axis.

Mirror a shape around the xz plane or the y-axis.

Mirror a shape around the xy plane or the z-axis.

Project a shape down to the yz plane.

Project a shape down to the xz plane.

Project a shape down to the xy plane.

Rotate a shape by angle about the x axis.

Rotate a shape by angle about the y axis.

Rotate a shape by angle about the z axis.

Scale a shape by xs, ys and zs along the x, y and z axes.

Shear a shape by a factor of sy, sz along the y and z axes about the x axis.

Shear a shape by a factor of sx, sz along the x and z axes about the y axis.

Shear a shape by a factor of sx, sy along the x and y axes about the z axis.

Transition (shift) a shape by xt, yt and zt along the x, y and z axes.

Link to this section Functions

Create a new matrix.

Examples

    iex(1)> point = Transformations.matrix([[1],[1],[1],[1]])
    #Matrex[4×1]
         
     1.0 
     1.0 
     1.0 
     1.0 
         

Mirror a shape around the yz plane or the x-axis.

Examples

    iex(1)> shape = Transformations.matrix([
                      [0,1,1,0,0,1,1,0],
                      [0,0,0,0,1,1,1,1],
                      [0,0,1,1,0,0,1,1],
                      [1,1,1,1,1,1,1,1]
                    ])
            shape |> Transformations.mirrorx()
    #Matrex[4×8]
                                                                  
      0.0    -1.0    -1.0     0.0     0.0    -1.0    -1.0     0.0 
      0.0     0.0     0.0     0.0     1.0     1.0     1.0     1.0 
      0.0     0.0     1.0     1.0     0.0     0.0     1.0     1.0 
      1.0     1.0     1.0     1.0     1.0     1.0     1.0     1.0 
                                                                  

Mirror a shape around the xz plane or the y-axis.

Examples

    iex(1)> shape = Transformations.matrix([
                      [0,1,1,0,0,1,1,0],
                      [0,0,0,0,1,1,1,1],
                      [0,0,1,1,0,0,1,1],
                      [1,1,1,1,1,1,1,1]
                    ])
            shape |> Transformations.mirrory()
    #Matrex[4×8]
                                                                  
      0.0     1.0     1.0     0.0     0.0     1.0     1.0     0.0 
      0.0     0.0     0.0     0.0    -1.0    -1.0    -1.0    -1.0 
      0.0     0.0     1.0     1.0     0.0     0.0     1.0     1.0 
      1.0     1.0     1.0     1.0     1.0     1.0     1.0     1.0 
                                                                  

Mirror a shape around the xy plane or the z-axis.

Examples

    iex(1)> shape = Transformations.matrix([
                      [0,1,1,0,0,1,1,0],
                      [0,0,0,0,1,1,1,1],
                      [0,0,1,1,0,0,1,1],
                      [1,1,1,1,1,1,1,1]
                    ])
            shape |> Transformations.mirrorz()
    #Matrex[4×8]
                                                                  
      0.0     1.0     1.0     0.0     0.0     1.0     1.0     0.0 
      0.0     0.0     0.0     0.0     1.0     1.0     1.0     1.0 
      0.0     0.0    -1.0    -1.0     0.0     0.0    -1.0    -1.0 
      1.0     1.0     1.0     1.0     1.0     1.0     1.0     1.0 
                                                                  

Project a shape down to the yz plane.

Examples

    iex(1)> shape = Transformations.matrix([
                      [0,1,1,0,0,1,1,0],
                      [0,0,0,0,1,1,1,1],
                      [0,0,1,1,0,0,1,1],
                      [1,1,1,1,1,1,1,1]
                    ])
            shape |> Transformations.projectx()
    #Matrex[4×8]
                                                                  
      0.0     0.0     0.0     0.0     0.0     0.0     0.0     0.0 
      0.0     0.0     0.0     0.0     1.0     1.0     1.0     1.0 
      0.0     0.0     1.0     1.0     0.0     0.0     1.0     1.0 
      1.0     1.0     1.0     1.0     1.0     1.0     1.0     1.0 
                                                                  

Project a shape down to the xz plane.

Examples

    iex(1)> shape = Transformations.matrix([
                      [0,1,1,0,0,1,1,0],
                      [0,0,0,0,1,1,1,1],
                      [0,0,1,1,0,0,1,1],
                      [1,1,1,1,1,1,1,1]
                    ])
            shape |> Transformations.projecty()
    #Matrex[4×8]
                                                                  
      0.0     1.0     1.0     0.0     0.0     1.0     1.0     0.0 
      0.0     0.0     0.0     0.0     0.0     0.0     0.0     0.0 
      0.0     0.0     1.0     1.0     0.0     0.0     1.0     1.0 
      1.0     1.0     1.0     1.0     1.0     1.0     1.0     1.0 
                                                                  

Project a shape down to the xy plane.

Examples

    iex(1)> shape = Transformations.matrix([
                      [0,1,1,0,0,1,1,0],
                      [0,0,0,0,1,1,1,1],
                      [0,0,1,1,0,0,1,1],
                      [1,1,1,1,1,1,1,1]
                    ])
            shape |> Transformations.projectz()
    #Matrex[4×8]
                                                                  
      0.0     1.0     1.0     0.0     0.0     1.0     1.0     0.0 
      0.0     0.0     0.0     0.0     1.0     1.0     1.0     1.0 
      0.0     0.0     0.0     0.0     0.0     0.0     0.0     0.0 
      1.0     1.0     1.0     1.0     1.0     1.0     1.0     1.0 
                                                                  

Rotate a shape by angle about the x axis.

Examples

    iex(1)> shape = Transformations.matrix([
                      [0,1,1,0,0,1,1,0],
                      [0,0,0,0,1,1,1,1],
                      [0,0,1,1,0,0,1,1],
                      [1,1,1,1,1,1,1,1]
                    ])
            shape |> Transformations.rotatex(45)
    #Matrex[4×8]
                                                                  
      0.0     1.0     1.0     0.0     0.0     1.0     1.0     0.0 
      0.0     0.0 -0.8509 -0.8509 0.52532 0.52532-0.32558-0.32558 
      0.0     0.0 0.52532 0.52532  0.8509  0.8509 1.37623 1.37623 
      1.0     1.0     1.0     1.0     1.0     1.0     1.0     1.0 
                                                                  

Rotate a shape by angle about the y axis.

Examples

    iex(1)> shape = Transformations.matrix([
                      [0,1,1,0,0,1,1,0],
                      [0,0,0,0,1,1,1,1],
                      [0,0,1,1,0,0,1,1],
                      [1,1,1,1,1,1,1,1]
                    ])
            shape |> Transformations.rotatey(45)
    #Matrex[4×8]
                                                                  
      0.0 0.52532 1.37623  0.8509     0.0 0.52532 1.37623  0.8509 
      0.0     0.0     0.0     0.0     1.0     1.0     1.0     1.0 
      0.0 -0.8509-0.32558 0.52532     0.0 -0.8509-0.32558 0.52532 
      1.0     1.0     1.0     1.0     1.0     1.0     1.0     1.0 
                                                                  

Rotate a shape by angle about the z axis.

Examples

    iex(1)> shape = Transformations.matrix([
                      [0,1,1,0,0,1,1,0],
                      [0,0,0,0,1,1,1,1],
                      [0,0,1,1,0,0,1,1],
                      [1,1,1,1,1,1,1,1]
                    ])
            shape |> Transformations.rotatez(45)
    #Matrex[4×8]
                                                                  
      0.0 0.52532 0.52532     0.0 -0.8509-0.32558-0.32558 -0.8509 
      0.0  0.8509  0.8509     0.0 0.52532 1.37623 1.37623 0.52532 
      0.0     0.0     1.0     1.0     0.0     0.0     1.0     1.0 
      1.0     1.0     1.0     1.0     1.0     1.0     1.0     1.0 
                                                                  

Scale a shape by xs, ys and zs along the x, y and z axes.

Examples

    iex(1)> shape = Transformations.matrix([
                      [0,1,1,0,0,1,1,0],
                      [0,0,0,0,1,1,1,1],
                      [0,0,1,1,0,0,1,1],
                      [1,1,1,1,1,1,1,1]
                    ])
            shape |> Transformations.scale(1,2,3)
    #Matrex[4×8]
                                                                  
      0.0     1.0     1.0     0.0     0.0     1.0     1.0     0.0 
      0.0     0.0     0.0     0.0     2.0     2.0     2.0     2.0 
      0.0     0.0     3.0     3.0     0.0     0.0     3.0     3.0 
      1.0     1.0     1.0     1.0     1.0     1.0     1.0     1.0 
                                                                  

Shear a shape by a factor of sy, sz along the y and z axes about the x axis.

Examples

    iex(1)> shape = Transformations.matrix([
                      [0,1,1,0,0,1,1,0],
                      [0,0,0,0,1,1,1,1],
                      [0,0,1,1,0,0,1,1],
                      [1,1,1,1,1,1,1,1]
                    ])
            shape |> Transformations.shearx(2,3)
    #Matrex[4×8]
                                                                  
      0.0     1.0     1.0     0.0     0.0     1.0     1.0     0.0 
      0.0     2.0     2.0     0.0     1.0     3.0     3.0     1.0 
      0.0     3.0     4.0     1.0     0.0     3.0     4.0     1.0 
      1.0     1.0     1.0     1.0     1.0     1.0     1.0     1.0 
                                                                  

Shear a shape by a factor of sx, sz along the x and z axes about the y axis.

Examples

    iex(1)> shape = Transformations.matrix([
                      [0,1,1,0,0,1,1,0],
                      [0,0,0,0,1,1,1,1],
                      [0,0,1,1,0,0,1,1],
                      [1,1,1,1,1,1,1,1]
                    ])
            shape |> Transformations.sheary(2,3)
    #Matrex[4×8]
                                                                  
      0.0     1.0     1.0     0.0     2.0     3.0     3.0     2.0 
      0.0     0.0     0.0     0.0     1.0     1.0     1.0     1.0 
      0.0     0.0     1.0     1.0     3.0     3.0     4.0     4.0 
      1.0     1.0     1.0     1.0     1.0     1.0     1.0     1.0 
                                                                  

Shear a shape by a factor of sx, sy along the x and y axes about the z axis.

Examples

    iex(1)> shape = Transformations.matrix([
                      [0,1,1,0,0,1,1,0],
                      [0,0,0,0,1,1,1,1],
                      [0,0,1,1,0,0,1,1],
                      [1,1,1,1,1,1,1,1]
                    ])
            shape |> Transformations.shearz(2,3)
    #Matrex[4×8]
                                                                  
      0.0     1.0     3.0     2.0     0.0     1.0     3.0     2.0 
      0.0     0.0     3.0     3.0     1.0     1.0     4.0     4.0 
      0.0     0.0     1.0     1.0     0.0     0.0     1.0     1.0 
      1.0     1.0     1.0     1.0     1.0     1.0     1.0     1.0 
                                                                  
Link to this function

transition(mtx, xt, yt, zt)

View Source

Transition (shift) a shape by xt, yt and zt along the x, y and z axes.

Examples

    iex(1)> shape = Transformations.matrix([
                      [0,1,1,0,0,1,1,0],
                      [0,0,0,0,1,1,1,1],
                      [0,0,1,1,0,0,1,1],
                      [1,1,1,1,1,1,1,1]
                    ])
            shape |> Transformations.transition(1,2,3)
    #Matrex[4×8]
                                                                  
      1.0     2.0     2.0     1.0     1.0     2.0     2.0     1.0 
      2.0     2.0     2.0     2.0     3.0     3.0     3.0     3.0 
      3.0     3.0     4.0     4.0     3.0     3.0     4.0     4.0 
      1.0     1.0     1.0     1.0     1.0     1.0     1.0     1.0