Rotating a Vector

106 visualizaciones (últimos 30 días)
A
A el 8 de Jul. de 2011
Comentada: James Tursa el 16 de Abr. de 2020
Hello! I am wondering if anyone has an elegant way to rotate a vector by a specified degree.
For example, I have a vector that goes from (0,0) to (-1,-12). I want to rotate this vector by 5 degrees, incrementally until it reaches the x-axis.
Obviously this can be done from the math, but I wonder if anyone has a nicer way of doing this.
Thank you in advance!
Amina

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 8 de Jul. de 2011
complex
vR = v*[1;1i]*exp(-1i*theta*pi/180)
  2 comentarios
A
A el 20 de Jul. de 2011
Very nice, thanks!
The only problem that I am having is using vR as it is a 1x1 element and therefore not in usual vector form. Is there a way that I can mash this into that form?
James Tursa
James Tursa el 16 de Abr. de 2020
real(vR) are the x components of the vectors, and imag(vR) are the y components of the vectors.

Iniciar sesión para comentar.

Más respuestas (3)

Sean de Wolski
Sean de Wolski el 8 de Jul. de 2011
Unless I'm missing something just use the rotation matrix:
v = [-1 -12];
theta = 5;
R = [cosd(theta) -sind(theta); sind(theta) cosd(theta)];
vR = v*R;
quiver(0,0,v(1),v(2))
hold on
quiver(0,0,vR(1),vR(2))
  1 comentario
A
A el 20 de Jul. de 2011
This works great! Thank you :)

Iniciar sesión para comentar.


Sayyed Ahmad Khadem
Sayyed Ahmad Khadem el 26 de Dic. de 2018
Hi all,
I read this blog, and I have similar problem. I would be thankful to kindly give me some clues if you know.
Suppose that we have a vector field in y-x plane, let's consider following example:
Vector Field : Vf = [u, v]
u=x
v=y
Untitled.png
Now, I need to revolve the given vector field around the center of plot (i.e. [0 0]). Does anyone can provide some nice solution?
Thanks in advance,
  1 comentario
Adam Danz
Adam Danz el 16 de Abr. de 2020
You can use quiverRotate() from the file exchange.
You can flip the direction of the quiver arrows by using the quiver handle or by flipping the vector component prior to producing the quiver plot.
h = quiver(x,y,u,v);
quiverRotate(h)
% or
[Ur,Vr] = quiverRotate(u,v);
quiver(x,y,Ur,Vr)

Iniciar sesión para comentar.


wenhao li
wenhao li el 11 de En. de 2019
Have you solved this problem? I met this problem, too.
  1 comentario
Sayyed Ahmad Khadem
Sayyed Ahmad Khadem el 11 de En. de 2019
Hi Wenhao,
No one has suggested a viable approach yet ! :-( I am still struggling !

Iniciar sesión para comentar.

Categorías

Más información sobre 2-D and 3-D Plots 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