Borrar filtros
Borrar filtros

Rotate an array of lines

3 visualizaciones (últimos 30 días)
Xeio De Sono
Xeio De Sono el 6 de Mayo de 2012
I need to rotate a line (and posteriorly an array of lines) on a given alpha from a variable coordinate origin ( x,y ). I need to use the command line() and I already tried command rotate() with no luck.
Can some one please help me out? :)
Thanks in advance
  2 comentarios
Walter Roberson
Walter Roberson el 6 de Mayo de 2012
What does it mean to rotate a line "on a given alpha" ?
Xeio De Sono
Xeio De Sono el 6 de Mayo de 2012
Means that the angle varies in a iterative function:
for i=1:1:45
set(h3,'Visible','off')
h3=line(XXX,YYY) %its a matrix containing all lines I need
rotate(h3,[0 0 1],i); % 'i' is an angle variation, the so called "alpha"
set(h3,'Visible','on')
end

Iniciar sesión para comentar.

Respuestas (4)

Jakob Sørensen
Jakob Sørensen el 7 de Mayo de 2012
If you for some reason can't get the built in functions to do as you want, you could always try it the old school way (doing the math yourself)...

bym
bym el 6 de Mayo de 2012
h = line([2,5],[2,2]);
rotate(h,[0,0,1],45)
  2 comentarios
Xeio De Sono
Xeio De Sono el 6 de Mayo de 2012
As I said, I tried rotate() without the result I needed, is there any other way to perform such rotation?
Jan
Jan el 6 de Mayo de 2012
As long as you describe the problems only by "with no luck" and "without the result I needed", it is hard to guess, what you are looking for. It is much more efficient to invest time in answering question, than in guessing, what the question is. So please post more details - by editing the original question, and not as answer or comment. Thanks.

Iniciar sesión para comentar.


Xeio De Sono
Xeio De Sono el 7 de Mayo de 2012
Thank you Jan Simon for reminding me this is a tool not a toy. Thank you Jakob Sorensen for reminding me of the old ways. I now have the code that I needed. Its an array of lines that follows a given (x,y,teta) coordinate system. If you see a chance for code improvement please let me know.
TWR = [ cos(param(3)) -sin(param(3)) param(1);
sin(param(3)) cos(param(3)) param(2);
0 0 1 ]; %tranformation to the world for following (x,y,teta)
TSR1=[ 1 0 0;
0 1 15;
0 0 1 ];
TSR2=[ 0.8660 -0.5 -10;
0.5 0.8660 10;
0 0 1 ];
TSR3=[ 0.8660 0.5 10;
-0.5 0.8660 10;
0 0 1 ];
%transformation for each sonar
Sonar1=[0 -8 0 8; 0 alcance(1) alcance(1) alcance(1); 1 1 1 1];
Sonar2=[0 -8 0 8; 0 alcance(2) alcance(2) alcance(2); 1 1 1 1];
Sonar3=[0 -8 0 8; 0 alcance(3) alcance(3) alcance(3); 1 1 1 1];
%cone representing each sonar
Sf1=TWR*TSR1*Sonar1;
Sf2=TWR*TSR2*Sonar2;
Sf3=TWR*TSR3*Sonar3;
% execution of the transformations
Sonares=[ Sf1(1,1) Sf1(1,2) Sf1(2,1) Sf1(2,2); %
Sf1(1,1) Sf1(1,3) Sf1(2,1) Sf1(2,3); % 3 raios sonar 1
Sf1(1,1) Sf1(1,4) Sf1(2,1) Sf1(2,4); %
Sf2(1,1) Sf2(1,2) Sf2(2,1) Sf2(2,2); %%
Sf2(1,1) Sf2(1,3) Sf2(2,1) Sf2(2,3); %%3 raios sonar 2
Sf2(1,1) Sf2(1,4) Sf2(2,1) Sf2(2,4); %%
Sf3(1,1) Sf3(1,2) Sf3(2,1) Sf3(2,2); %%%
Sf3(1,1) Sf3(1,3) Sf3(2,1) Sf3(2,3); %%%3 raios sonar 3
Sf3(1,1) Sf3(1,4) Sf3(2,1) Sf3(2,4);
Sf1(1,1) (Sf1(1,3)+Sf1(1,4))/2 Sf1(2,1) (Sf1(2,3)+Sf1(2,4))/2;
Sf1(1,1) (Sf1(1,2)+Sf1(1,3))/2 Sf1(2,1) (Sf1(2,2)+Sf1(2,3))/2;
Sf2(1,1) (Sf2(1,3)+Sf2(1,4))/2 Sf2(2,1) (Sf2(2,3)+Sf2(2,4))/2;
Sf2(1,1) (Sf2(1,2)+Sf2(1,3))/2 Sf2(2,1) (Sf2(2,2)+Sf2(2,3))/2;
Sf3(1,1) (Sf3(1,3)+Sf3(1,4))/2 Sf3(2,1) (Sf3(2,3)+Sf3(2,4))/2;
Sf3(1,1) (Sf3(1,2)+Sf3(1,3))/2 Sf3(2,1) (Sf3(2,2)+Sf3(2,3))/2]; %%%array of lines
line([Sonares(1,1) Sonares(1,2)],[Sonares(1,3) Sonares(1,4)])
line([Sonares(2,1) Sonares(2,2)],[Sonares(2,3) Sonares(2,4)])
line([Sonares(3,1) Sonares(3,2)],[Sonares(3,3) Sonares(3,4)])
line([Sonares(4,1) Sonares(4,2)],[Sonares(4,3) Sonares(4,4)])
line([Sonares(5,1) Sonares(5,2)],[Sonares(5,3) Sonares(5,4)])
line([Sonares(6,1) Sonares(6,2)],[Sonares(6,3) Sonares(6,4)])
line([Sonares(7,1) Sonares(7,2)],[Sonares(7,3) Sonares(7,4)])
line([Sonares(8,1) Sonares(8,2)],[Sonares(8,3) Sonares(8,4)])
line([Sonares(9,1) Sonares(9,2)],[Sonares(9,3) Sonares(9,4)])
line([Sonares(10,1) Sonares(10,2)],[Sonares(10,3) Sonares(10,4)])
line([Sonares(11,1) Sonares(11,2)],[Sonares(11,3) Sonares(11,4)])
line([Sonares(12,1) Sonares(12,2)],[Sonares(12,3) Sonares(12,4)])
line([Sonares(13,1) Sonares(13,2)],[Sonares(13,3) Sonares(13,4)])
line([Sonares(14,1) Sonares(14,2)],[Sonares(14,3) Sonares(14,4)])
line([Sonares(15,1) Sonares(15,2)],[Sonares(15,3) Sonares(15,4)])

Sean de Wolski
Sean de Wolski el 7 de Mayo de 2012
doc hgtransform
doc makehgtform
and

Categorías

Más información sobre Motion Modeling and Coordinate Systems en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by