Find the angle between two vectors, then move away...
이전 댓글 표시
Hi all,
I am trying to do the following - find the angle between a vector and a point, then turn the vector to face 180 degrees the opposite direction from the direction of the point. However, I am struggling to find the correct angle.
Here is my approach so far...
x=[-1,1]; %new bot coordinate
xold=[-2,2]; %old bot coordinate
y=[0,0]; %obstacle
a=x-xold;
b=atan2(a(1),a(2));
c=atan2(y(1)-x(1),y(2)-x(1));
d=(b-c)-pi;
Any advice would be very greatfully recieved! Many thanks as always.
채택된 답변
추가 답변 (1개)
John D'Errico
2015년 1월 14일
편집: John D'Errico
2015년 1월 14일
0 개 추천
Way too much work for a simple problem. There is NO need for trig here, so I'm not even going to try to figure out what you have in that undocumented mess of code. (Even if you were talking about reflection from a surface, that too can be done trig-less.)
If the vector X = [x,y] points in the direction you are currently moving, then the vector -X points in the opposite direction.
댓글 수: 3
Alex
2015년 1월 14일
John D'Errico
2015년 1월 14일
Still not clear, but better.
Given a vector [x,y], the angle at which it points is
atan2(y,x)
So if you have a direction vector, you trivially have the angle at which you would move.
As for the object, do you want to know a direction normal (orthogonal) to the surface of that object? If you do, then you have not given me that information, only the direction you are moving.
I'm not sure what you think you have with this:
y=[0,0]; %obstacle
But that appears to be simply a location, NOT a normal vector in any form, or anything that would yield that information.
Alex
2015년 1월 14일
카테고리
도움말 센터 및 File Exchange에서 Graphics Object Properties에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!