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?

1 回表示 (過去 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,
  1 件のコメント
dpb
dpb 2024 年 12 月 23 日
As always, it would be helpful if you would attach enough code/data to give us a working starting-off point...

サインインしてコメントする。

採用された回答

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 Center および File ExchangeVector Fields についてさらに検索

製品


リリース

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by