Is it possible to plot a vector arrow using quiver( ), then, negate the vector so it points in the opposite direction, but then add arrowhead in original direction?

8 次查看(过去 30 天)
Hi there!
This is somewhat embarassing, but I've been trying this little thing for a while now, so I figured it's a good time to ask now:
I would like to plot a velocity vector, e.g. representing a fluid flow, pointing at / acting on an object (let's say, a thin rectangle).
But if I use quiver( ) to plot the vector, the vector would emanate from the object, and consequently point away from the object, not towards it.
So, my little hack was this:
  1. Plot the vector using quiver; it'll emanate from the object and point away from the object;
  2. Negate the vector, so it emanates from the object, but now it points in the opposite direction; and
  3. Remove the arrowahead from the vector.
Removing the arrowhead from the vector makes the line potentially look like it's pointing toward the object, which is what I want.
But now, here's the hard part, Matlab doesn't appear to be able to add an arrowhead, so that the vector can point in the original direction, which is what I want, so that the vector looks like it's pointing at the object. Matlab appears to be able to only add an arrowhead in the direction that the vector values indicate.
Basically, how can I add an arrowhead at the tail of the vector, but have it point in the opposite direction?
Is there a better alternative?
Thanks in advance,

采纳的回答

Cris LaPierre
Cris LaPierre 2024-12-23
编辑:Cris LaPierre 2024-12-24
Perhaps you could share a working example?
When I negate U and V, the arrows point the opposite direction. I also modified the Alignment property so the arrows are generally in the same place.
tiledlayout(1,2)
nexttile
[X,Y] = meshgrid(0:6,0:6);
U = 0.25*X;
V = 0.5*Y;
quiver(X,Y,U,V,0)
title('Normal')
nexttile
[X,Y] = meshgrid(0:6,0:6);
U = 0.25*X;
V = 0.5*Y;
quiver(X,Y,-U,-V,0,'alignment','Head')
title('Negated')
  11 个评论
Cris LaPierre
Cris LaPierre 2024-12-24
Each quiver arrow is connected to an (X,Y) point. You provide those points as the first 2 inputs to the quiver function. Alignment determines which part of the arrow is touching that point. It can be 'Tail', which is the default, 'Center' or 'Head'
dpb
dpb 2024-12-24
Indeed...an extremely useful enhancement that solves the problem internally...one wonders why it wasn't an initial feature, but adding the enhancement certainly makes the function far more versatile...congrats to TMW!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Vector Fields 的更多信息

产品


版本

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by