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!