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?

74 views (last 30 days)
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,

Accepted Answer

Cris LaPierre
Cris LaPierre on 23 Dec 2024 at 21:00
Edited: Cris LaPierre on 24 Dec 2024 at 17:11
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 Comments
Cris LaPierre
Cris LaPierre on 24 Dec 2024 at 14:27
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 on 24 Dec 2024 at 15:39
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!

Sign in to comment.

More Answers (0)

Categories

Find more on Vector Fields in Help Center and File Exchange

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!