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:
- Plot the vector using quiver; it'll emanate from the object and point away from the object;
- Negate the vector, so it emanates from the object, but now it points in the opposite direction; and
- 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
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
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
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
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 Exchange 中查找有关 Vector Fields 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!