2D body transformation and rotation in Matlab

I defined the following rectangle in Matlab:

A = [-4,-4,4,4,-4;-2,2,2,-2,-2;]

And I defined the transformation matrix (Special Euclidean (2)) as follows:

function T = se2(x, y, theta)
T = [cosd(theta), -sind(theta), x;
     sind(theta), cosd(theta), y;
      0,        0,           1];

Now I want to rotate my figure 45 degrees counterclockwise around its center and move it relative to the new coordinate frame by 2 units in the new y.

First problem : when doing the following: ...

B = se2(0,2,45)*[A;1 1 1 1 1]

... it will rotate correctly, but move my figure incorrectly.
Here is my rectangle (blue), the wrong transform (red) and the correct transform (green): The image

: , 6 y. -30 , , , . enter image description here

Matlab? ?

:

A =

    -4    -4     4     4    -4
    -2     2     2    -2    -2
plot(A(1,:),A(2,:),'blue')
+4
1

:

, A , . , , . "" , , . . . .

% Define A
A = [-2,-2,6,6,-2; -2,2,2,-2,-2; 1 1 1 1 1];

% Define Translation Matrix
trans = @(x,y,z) repmat([x; y; z],[1 5]);

% Define Rotation Matrix
se2 = @(x, y, theta) [
    cosd(theta), -sind(theta), x;
    sind(theta), cosd(theta), y;
    0,        0,           1];

% Calculate Rotated Rect
B = se2(0,0,45) * (A - trans(2,0,0) ) + trans(2,0,0);

% Plot Rectangles
figure; plot(A(1,:),A(2,:),'b')
hold on;
plot(B(1,:),B(2,:),'r')
hold off;
axis equal

trans .

:

>> A
A =
    -2    -2     6     6    -2
    -2     2     2    -2    -2
     1     1     1     1     1
>> B
B =
    0.5858   -2.2426    3.4142    6.2426    0.5858
   -4.2426   -1.4142    4.2426    1.4142   -4.2426
    1.0000    1.0000    1.0000    1.0000    1.0000

A/B, .

enter image description here

A/B .

enter image description here

:

, , -30 B.

+3

Source: https://habr.com/ru/post/1583846/


All Articles