Find the angle between two vectors, then move away...
Mostrar comentarios más antiguos
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 comentario
Respuesta aceptada
Más respuestas (1)
John D'Errico
el 14 de En. de 2015
Editada: John D'Errico
el 14 de En. de 2015
0 votos
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 comentarios
Alex
el 14 de En. de 2015
John D'Errico
el 14 de En. de 2015
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
el 14 de En. de 2015
Categorías
Más información sobre Graphics Object Properties en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!