how to plot an arrow given yaw/pitch/roll
36 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Art
am 4 Aug. 2015
Kommentiert: zhaozhong chen
am 25 Mai 2018
What's the easiest way to plot a simple arrow of arbitrary dimensions given a starting position (x,y,z) and euler angles (roll,pitch,yaw)?
0 Kommentare
Akzeptierte Antwort
Mike Garrity
am 5 Aug. 2015
Consider the following simple example:
pt = [0 0 0];
dir = [1 0 0 1];
h = quiver3(pt(1),pt(2),pt(3), dir(1),dir(2),dir(3));
xlim([-1 1])
ylim([-1 1])
zlim([-1 1])
If we look at h, we'll see that it has properties named UData, VData, and WData.
h =
Quiver with properties:
Color: [0 0.4470 0.7410]
LineStyle: '-'
LineWidth: 0.5000
XData: 0
YData: 0
ZData: 0
UData: 1
VData: 0
WData: 0
This are the components of the vector. To change the direction, we want to transform those. The makehgtform command will give us a transform matrix for a set of rotations. We can use that to calculate new values for the UData, VData, and WData properties.
We can use it like this:
xfm = makehgtform('xrotate',pi/3,'yrotate',pi/5,'zrotate',pi/2);
newdir = xfm * dir';
h.UData = newdir(1);
h.VData = newdir(2);
h.WData = newdir(3);
You may have noticed something odd here. The vector dir is a 1x4 vector even though we've only got 3 directions. The reason is that makehgtform returns a 4x4 matrix. It does that so that it can support translations. You don't care about translations in this case, so we can ignore that.
To animate this, we'd do it in a loop and add a drawnow:
for theta = linspace(0,pi,64)
for phi = linspace(-pi,pi,64)
for psi = linspace(0,2*pi,64)
xfm = makehgtform('xrotate',theta,'yrotate',phi,'zrotate',psi);
newdir = xfm * dir';
h.UData = newdir(1);
h.VData = newdir(2);
h.WData = newdir(3);
drawnow
end
end
end
You may need to fiddle with the order in which you give the rotations to makehgtform. You'll see various orderings referred to as "Euler angles". The help for makehgtform will show you some other things you can do with it, such as the axisrotate option.
Weitere Antworten (1)
Art
am 6 Aug. 2015
2 Kommentare
zhaozhong chen
am 25 Mai 2018
a late answer. Just type
h = quiver3(pt(1),pt(2),pt(3), dir(1),dir(2),dir(3));
%from the first answer and then
%then create two dir, dir 2 and dir 3
hold on
h2 = quiver3(pt(1),pt(2),pt(3), dir2(1),dir2(2),dir2(3))
h3 = quiver3(pt(1),pt(2),pt(3), dir3(1),dir3(2),dir3(3))
hold off %so you'll have 3 directions from the same points
xlim([-1 1])
ylim([-1 1])
zlim([-1 1])
Siehe auch
Kategorien
Mehr zu Specifying Target for Graphics Output finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!