필터 지우기
필터 지우기

Rotate an array of lines

조회 수: 3 (최근 30일)
Xeio De Sono
Xeio De Sono 2012년 5월 6일
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
Walter Roberson
Walter Roberson 2012년 5월 6일
What does it mean to rotate a line "on a given alpha" ?
Xeio De Sono
Xeio De Sono 2012년 5월 6일
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

댓글을 달려면 로그인하십시오.

답변 (4개)

Jakob Sørensen
Jakob Sørensen 2012년 5월 7일
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 2012년 5월 6일
h = line([2,5],[2,2]);
rotate(h,[0,0,1],45)
  댓글 수: 2
Xeio De Sono
Xeio De Sono 2012년 5월 6일
As I said, I tried rotate() without the result I needed, is there any other way to perform such rotation?
Jan
Jan 2012년 5월 6일
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.

댓글을 달려면 로그인하십시오.


Xeio De Sono
Xeio De Sono 2012년 5월 7일
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 2012년 5월 7일
doc hgtransform
doc makehgtform
and

카테고리

Help CenterFile Exchange에서 Motion Modeling and Coordinate Systems에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by