Problems about "rotate" function

Hi!!
I'm experiencing the following problem.
k=2;
for i=2:length(t_inf_sgross)
b(k)=subtract(D(k-1),C2(k-1));
D(k)=rotate(b(k),Delta_phi(i));
k=k+1;
end
ruotato=rotate(b(end),-35)
plot(ruotato)
I'm creating a vector called "b" containing a series of polyshapes that results from the subtraction/rotation of geometries contained in "C" vector.
The problem is that when i call the final geometry resulted in "b" vector, then called "ruotato" and i rotate it of a certain angle (here -35°), Matlab seems to rotate only the perimeter but not the area of this geometry, giving the result i post below:
Why this happen?
Thank you!

 Respuesta aceptada

Matt J
Matt J el 15 de Nov. de 2020
Editada: Matt J el 15 de Nov. de 2020

0 votos

Presumably because b(end) is the perimeter, i.e., it is a polyshape containing almost no internal area.

12 comentarios

Francesco
Francesco el 15 de Nov. de 2020
I don’t understand. When i subtract two polyshapes and Matlab creates another polyshape, how can it be “empty” ? Is there a way to solve this problem?
Matt J
Matt J el 15 de Nov. de 2020
Editada: Matt J el 15 de Nov. de 2020
It isn't "empty". You've subtracted so much of the interior that all that is left is a thin border. This is all we can deduce from what you've posted. If you could attach additional code and/or a .mat file of input variables so that we can run the loop ourselves, we could analyze the results more directly.
Francesco
Francesco el 15 de Nov. de 2020
The code is very long. I try to be as exhaustive as possibile.
  1. I create a matrix in which every column and the next one represent the X and Y coordinates of the points of the perimeter of a tool composed by 23 teeth at diferent instant of time. So, column 1 and 2 are X & Y at instant n°1, column 3 and 4 are X & Y at instant n°2, and so on. Now i need to make polyshapes of these teeth, because the tool has to be subtracted from the raw material as the time passes.
  2. By a for loop i create a polyshape of every tooth of the tool. The result is a matrix composed by 23 x (n° instant of time) polyshapes. Now i have the tool composed by 23 teeth at various working times.
  3. By another for loop and "unite" function (usually very time expensive due to high number of instants) i unite teeth to have 1x(n°instant of working time) vector called C2, containing polyshapes that represent the tool positions. Now i am ready to subtract from raw material.
By a for loop i subtract C2 position of the tool to the D(k) raw material. Then, i need to rotate D(k) before doing the next subtraction because the raw rotates in reality together with the tool. The raw is a ring, i subtract only a little part of it represented by the 23 teeth of the tool.
The result is correct, but the D rotation gives the problem i posted above.
k=2;
for i=2:length(t_inf_sgross)
b(k)=subtract(D(k-1),C2(k-1));
D(k)=rotate(b(k),Delta_phi(i));
k=k+1;
end
ruotato=rotate(b(end),-35)
plot(ruotato)
Matt J
Matt J el 15 de Nov. de 2020
Well, attach a .mat file containing the resulting polyshape array b, then. That way, we can try just the rotation part ourselves.
Francesco
Francesco el 15 de Nov. de 2020
Here you are.
I attached the last element of "b" because the entire vector was too heavy :D
The next problem will be how to lighten the code, it works but it lasts like the entire working process :D
Matt J
Matt J el 15 de Nov. de 2020
Editada: Matt J el 15 de Nov. de 2020
Well, this is what I did with the file,
S=load('b_file');
b=S.test;
plot(b)
axis equal
hold on
ruotato=rotate(b(end),-35);
plot(ruotato)
hold off
and what I got looks fine. I recommend you redo the plot in a fresh figure window and see if that doesn't fix things. Maybe a previous hold command messed things up.
Francesco
Francesco el 15 de Nov. de 2020
It keeps going wrong to me. Try to rotate only “b(end)”, maybe if you superpose the rotated and not rotated you don’t see the error.
Matt J
Matt J el 15 de Nov. de 2020
Editada: Matt J el 15 de Nov. de 2020
Did you try executing my code? Clear all figures and your entire workspace and just try to repeat what I have done using b_file.mat only. Also, what Matlab version are you using?
Francesco
Francesco el 15 de Nov. de 2020
Editada: Francesco el 15 de Nov. de 2020
It seems to work if i plot it out of the main code, as you said! If i try to make the same in the main code, it gives the problem.
How is it possible?
Matlab R2018
Matt J
Matt J el 16 de Nov. de 2020
Editada: Matt J el 16 de Nov. de 2020
How is it possible?
No way to know since you're not showing us your complete plot commands. There are several objects in your posted plot, but you show the command that was issued for only one of them. I recommend, in any case, that you do not modify you plots at many different stages throughout your long code. Just plot everything in one place at the very end of the code.
Francesco
Francesco el 16 de Nov. de 2020
Editada: Francesco el 16 de Nov. de 2020
I can’t post the entire plot because it’s a 785 MB file. I can’t plot only the last position because the final geometry is the result of multiple positions of the tool as function of time. As you said I’ll load the result in a separate window and there i’ll make my operations. The next topic will be how to lighten the code. It lasts 1 hour.. i will post it in another topic :)
Matt J
Matt J el 16 de Nov. de 2020
The next topic will be how to lighten the code. It lasts 1 hour.. i will post it in another topic :)
OK, but if we are done with this topic, please Accept-click the answer.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Preguntada:

el 14 de Nov. de 2020

Comentada:

el 16 de Nov. de 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by