Learn R Programming

vectools (version 0.2.0)

60_pre-multiplication_transformation_matrices: Pre-Multiplication Transformation Matrices

Description

Constructors for constructing one or more transformation matrices.

Usage

atrl2 (x=0, y=0)
ascl2 (x, y=x)
arot2 (theta)

atrl3 (x=0, y=0, z=0) ascl3 (x, y=x, z=x)

arot3x (theta) arot3y (theta) arot3z (theta)

Arguments

x, y, z

Numeric vectors, x, y and z transformation parameters.

theta

Numeric vector, the angle in radians.

Value

A matrix or a 1d MatrixArray.

2d transformations are 3x3 matrices and 3d transformations are 4x4 matrices.

Details

These matrices are designed for pre-multiplication. They go before the data matrix. (Note that data, should have points as columns).

Pre and post scaling matrices are the same.

In 2d rotation matrices, positive theta values rotate counter-clockwise.

3d rotation matrices, are the same as the 2d matrices, except for having an extra row and column. (Whether they're clockwise or counter-clockwise, depends on one's coordinate system).

See Also

MatrixArray

Binary Operators This describes how to perform operations on MatrixArray objects.

Post-Multiplication Transformation Matrices

polyplot, cubplot

Examples

Run this code
# NOT RUN {
########################################
#2d static examples
########################################
#centered hexagon
ps <- eq.arot2 (6, start = pi / 6) %*|% c (0, 1)
polyplot (ps, transpose=TRUE)

#four hexagons, different sizes
vm <- ascl2 (seq (1.3, 0.7,, 4) ) %*[% ps
polyplot (vm, transpose=TRUE)

#scaled, translated, then rotated (cartesian)
vm.c <-
    eq.arot2 (8) %{*}%
    (   atrl2 (,3.75) %*%
        ascl2 (seq (1.3, 0.7,, 4) )
    ) %*[%
    ps
polyplot (vm.c, transpose=TRUE)

#scaled, translated, then rotated (standard, but rev)
vm.s <-
    eq.brot2 (8) %{*}%
    atrl2 (,3.75) %*%
    ascl2 (seq (1.3, 0.7,, 4) ) %*[%
    ps
polyplot (vm.s, transpose=TRUE)

########################################
#3d dynamic example
########################################
sim3d <- function (N=200, DELAY=0)
{   start <- runif (3, -4, 0)
    end <- runif (3, 0, 4)
    xpos <- seq (start [1], end [1],, N)
    ypos <- seq (start [2], end [2],, N)
    zpos <- seq (start [3], end [3],, N)

    nrots <- runif (3, 1, 4)
    start <- runif (3, 0, 2 * pi)
    end <- start + 2 * pi * nrots
    xtheta <- seq (start [1], end [1],, N)
    ytheta <- seq (start [2], end [2],, N)
    ztheta <- seq (start [3], end [3],, N)
	
    for (k in 1:N)
    {   ps <-
            arot3z (ztheta [k]) %*%
            arot3y (ytheta [k]) %*%
            arot3x (xtheta [k]) %*%
            atrl3 (xpos [k], ypos [k], zpos [k]) %*[%
            t (cubps)
        cubplot (ps, transpose=TRUE)
        if (DELAY > 0)
            Sys.sleep (DELAY)
    }
}

if (interactive () )
    sim3d (200, 0)
# }

Run the code above in your browser using DataLab