# Problem description

First of thank you for this great tool.
I am running into the problem, and I have tried many different ways to solve it.
The problem is a simple translation of a shape into the origo after rotation and translation back to its original place.

I have tried with matrix multiplication, but I have error always, and I decided to cut the problem apart.

But I am running into the same problem.
The first translation to origo looks good.
The rotation into the origo looks good as well.
And my problem starts with the translation back to the original place.

I have tested many other ways.
After several weird results, the best that I could achieve is to get back the shape at a double distance from origo. (far over the original shape)

I have tried to upload some code, but it is not allowed yet.

Can anybody help me what are the typical pitfalls with this problem?
Or can somebody put here some concrete solid example?

# My system

• OS: Windows 10 (version 1909)
• Octave version: e.g. Version 4.2.1
• ** corporate central installation via FlexLm**

It is difficult to guess what went wrong without seeing what you tried.
Could you please boil down your code to a minimal example that fails and show it here?

Ok,

Let’s see the code.
This is very redundant, but I tried to tear donw the problem,

There is 2 “for” cycle.
The first is to apply the matrix on the original data. (To test the one step method with multiplied transformation matrices.

The second “for” cycle is to “accumulate” the results.

The best what I could achieve is that if I can use the step by step method I finally reached the target. (the rotated shape is into the original position. (but this is not the target)

I getting sick because the one-step method does not work, even if I use the same matrices that are good into the STEP-BY-STEP method.

So the multiplication portion has a problem.

Any help is appreciated. I think I spent too much time on this. And I am blind on the solution. I am pretty sure to solution will be easy.

page_screen_output(0);
page_output_immediately(1);

format short;

function Init_Project
base_data =[ 10,10,10;
20,10,10;
20,20,10;
10,20,10;
10,10,10;
15,15,10];

figure(1),clf;
axis equal;
axis square;
xlabel(“x”);
ylabel(“y”);
zlabel(“z”);

axis equal;
plot3([base_data(:,1)],[base_data(:,2)],[base_data(:,3)],’:k’,‘LineWidth’,7);

transl_x = (max(base_data(:,1))+ min(base_data (:,1)))/2 ;
transl_y = (max(base_data(:,2))+ min(base_data (:,2)))/2 ;
angle_inc = pi/16;

transl_forw_Matrice = [1,0,0,-transl_x;
0,1,0,-transl_y;
0,0,1,0;
0,0,0,1];

rot_Matrice = [cos(angle_inc),-sin(angle_inc),0,0;
sin(angle_inc),cos(angle_inc),0,0;
0,0,1,0;
0,0,0,1];

transl_backw_Matrice = [1,0,0,transl_x,;
0,1,0,transl_y;
0,0,1,0;
0,0,0,1];

one_shot = [base_data(:, , ones(size(base_data(:,:))(1,1),1)];
endfunction;

Init_Project;

%comb_Matrice = transl_forw_Matrice;
comb_Matrice = rot_Matrice * transl_forw_Matrice ;
comb_Matrice = transl_forw_Matrice * rot_Matrice ;
%comb_Matrice = rot_Matrice ;
comb_Matrice = (transl_forw_Matrice * rot_Matrice) * transl_backw_Matrice ;
%comb_Matrice = transl_backw_Matrice ;

for jjk= 1:size(base_data(:,1))(1,1)
one_shot(jjk, = (comb_Matrice * [base_data(jjk,:),1]’)’;
endfor

axis equal;
hold on;
plot3([one_shot(:,1)],[one_shot(:,2)],[one_shot(:,3)],’:b’,‘LineWidth’,7);

% apply the matrice on shape
for ddf= 1:size(base_data(:,1))(1,1)
one_shot(ddf, = (comb_Matrice * [one_shot(ddf,:)]’)’;
endfor
axis equal;
hold on;
plot3([one_shot(:,1)],[one_shot(:,2)],[one_shot(:,3)],’:r’,‘LineWidth’,7);

I’m not exactly sure if I understood correctly.
But it might be that you got your matrix multiplication backwards.
Try this:

``````base_data = [10,10,10;
20,10,10;
20,20,10;
10,20,10;
10,10,10;
15,15,10];

figure(1),clf;
axis equal;
axis square;
xlabel("x");
ylabel("y");
zlabel("z");

axis equal;
plot3([base_data(:,1)],[base_data(:,2)],[base_data(:,3)],':k','LineWidth',7);

transl_x = (max(base_data(:,1))+ min(base_data (:,1)))/2 ;
transl_y = (max(base_data(:,2))+ min(base_data (:,2)))/2 ;
angle_inc = pi/16;

transl_forw_Matrice = [1,0,0,-transl_x;
0,1,0,-transl_y;
0,0,1,0;
0,0,0,1];

rot_Matrice = [cos(angle_inc),-sin(angle_inc),0,0;
sin(angle_inc),cos(angle_inc),0,0;
0,0,1,0;
0,0,0,1];

transl_backw_Matrice = [1,0,0,transl_x,;
0,1,0,transl_y;
0,0,1,0;
0,0,0,1];

one_shot = [base_data(:,:) , ones(size(base_data(:,:))(1,1),1)];

## The coordinates are multiplicated to the right.
## So the right-most transformation applies first.
comb_Matrice = transl_backw_Matrice * rot_Matrice * transl_forw_Matrice;

for jjk= 1:size(base_data(:,1))(1,1)
one_shot(jjk,:) = (comb_Matrice * [base_data(jjk,:),1]')';
endfor

axis equal;
hold on;
plot3([one_shot(:,1)],[one_shot(:,2)],[one_shot(:,3)],':b','LineWidth',7);

% apply the matrice on shape
for ddf= 1:size(base_data(:,1))(1,1)
one_shot(ddf,:) = (comb_Matrice * [one_shot(ddf,:)]')';
endfor
axis equal;
hold on;
plot3([one_shot(:,1)],[one_shot(:,2)],[one_shot(:,3)],':r','LineWidth',7);
``````

As a side note: use three grave accents ("```") to indicate code blocks, or discourse might mess up the markup.

Mmutzel,

See this identity: `(A * B)' = B' * A'`