In [1]:
%load_ext octavemagic

Homogeneous rotation

General definitions


In [22]:
%%octave -o matIdentity -o transAffineSpace -o matTranslationProjective

% Identity matrix
matIdentity = [
    1, 0;
    0, 1
]

% Affine space transformation
transAffineSpace = [
    -1;
    -2
]

% Projective space matrix
matTranslationProjective = [
    matIdentity, transAffineSpace;
    zeros(1, 2), 1
]


matIdentity =

        1        0
        0        1

transAffineSpace =

       -1
       -2

matTranslationProjective =

        1        0       -1
        0        1       -2
        0        0        1

Rotation


In [25]:
%%octave -o phi -o matRotation -o matRotationProjective

%% Rotation

phi = pi / 3

% Linear space
matRotation = [
    cos(phi),   -sin(phi);
    sin(phi),    cos(phi)
]

% Projective space
matRotationProjective = [
    matRotation,    zeros(2, 1);
    zeros(1, 2),    1
]


phi =  1.0472
matRotation =

  0.50000  -0.86603
  0.86603  0.50000

matRotationProjective =

  0.50000  -0.86603  0.00000
  0.86603  0.50000  0.00000
  0.00000  0.00000  1.00000

Transformations


In [26]:
%%octave -o matElementZeroX -o matElementZeroY -o matElementZeroHomogenous -o matElementZeroProjective -o matElementOneX -o matElementOneY

%% Define elements
matElementZeroX = ones(3, 1) * [3:6]
matElementZeroY = [3:5]' * ones(1, 4)

% Homogenous coordinates
matElementZeroHomogenous = [
    reshape(matElementZeroX, 1, 12);
    reshape(matElementZeroY, 1, 12);
    ones(1, 12)
]

% Projective transform
matElementZeroProjective = matTranslationProjective * matRotationProjective * inv(matTranslationProjective) * matElementZeroHomogenous

% Affine coordinates for X and Y
matElementOneX = reshape(matElementZeroProjective(1, :), 3, 4)
matElementOneY = reshape(matElementZeroProjective(2, :), 3, 4)


matElementZeroX =

        3        4        5        6
        3        4        5        6
        3        4        5        6

matElementZeroY =

        3        3        3        3
        4        4        4        4
        5        5        5        5

matElementZeroHomogenous =

 Columns 1 through 8:

        3        3        3        4        4        4        5        5
        3        4        5        3        4        5        3        4
        1        1        1        1        1        1        1        1

 Columns 9 through 12:

        5        6        6        6
        5        3        4        5
        1        1        1        1

matElementZeroProjective =

 Columns 1 through 8:

  -3.33013  -4.19615  -5.06218  -2.83013  -3.69615  -4.56218  -2.33013  -3.19615
  3.96410  4.46410  4.96410  4.83013  5.33013  5.83013  5.69615  6.19615
  1.00000  1.00000  1.00000  1.00000  1.00000  1.00000  1.00000  1.00000

 Columns 9 through 12:

  -4.06218  -1.83013  -2.69615  -3.56218
  6.69615  6.56218  7.06218  7.56218
  1.00000  1.00000  1.00000  1.00000

matElementOneX =

  -3.33013  -2.83013  -2.33013  -1.83013
  -4.19615  -3.69615  -3.19615  -2.69615
  -5.06218  -4.56218  -4.06218  -3.56218

matElementOneY =

  3.96410  4.83013  5.69615  6.56218
  4.46410  5.33013  6.19615  7.06218
  4.96410  5.83013  6.69615  7.56218

Angles


In [27]:
%%octave -o theta -o angle -o radius

%% Rotation arc
theta = atan2(matElementZeroY(1, 1) - transAffineSpace(2), matElementZeroX(1, 1) - transAffineSpace(1))
angle = linspace(theta, theta + phi);
radius = sqrt((matElementZeroY(1, 1) - transAffineSpace(2))^2 + (matElementZeroX(1, 1) - transAffineSpace(1))^2)


theta =  0.89606
radius =  6.4031

Plotting


In [29]:
%%octave -f png -s 800,600

%% Graphics

% Axes
plot(transAffineSpace(1), transAffineSpace(2), 'ko', [-5, 6], [0, 0], 'k', [0, 0], [-2, 9], 'k')
hold on

% Element zero
plot(matElementZeroX, matElementZeroY, 'ro', matElementZeroX, matElementZeroY, 'r', matElementZeroX', matElementZeroY', 'r')
% Element one
plot(matElementOneX, matElementOneY, 'bo', matElementOneX, matElementOneY, 'b', matElementOneX', matElementOneY', 'b')

% Transformation line
plot(radius * cos(angle) + transAffineSpace(1), radius * sin(angle) + transAffineSpace(2), 'g')

% Axis
axis('square', [-8, 8, -4, 12])

hold off



In [ ]: