필터 지우기
필터 지우기

how to plot an arrow given yaw/pitch/roll

조회 수: 26 (최근 30일)
Art
Art 2015년 8월 4일
댓글: zhaozhong chen 2018년 5월 25일
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)?

채택된 답변

Mike Garrity
Mike Garrity 2015년 8월 5일
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.
  댓글 수: 1
Art
Art 2015년 8월 12일
Mike, I have a follow up question you may be able to answer:
If I were plotting this arrow on Matlab's Globe model, I would need to find the local U/V/Wdata at the lat/long/alt of the arrow starting point (I think?). Then I would use this as the arrow's starting "dir" in your above example, prior to doing the desired theta/phi/psi rotations.
In other words, the X/Y/Z positions I have are in ECEF coord, and I'd need to first rotate the initial arrow vector to point due north in the local NED frame, then rotate again per your example.
I can convert the X/Y/Z to Lat/Long/Alt, but how can find initial north pointing U/V/Wdata at any point on the earth given lat/long/alt?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Art
Art 2015년 8월 6일
Thanks everyone for the suggestions! And thanks Mike Garrity for the clear, concise and exampled description, always a plus for me. After playing around with all suggestions, yours was exactly what I needed.
  댓글 수: 2
Joel Sande
Joel Sande 2016년 4월 12일
Hi, How to do this from 1 point pointing in 3 different directions ?
zhaozhong chen
zhaozhong chen 2018년 5월 25일
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])

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Discrete Data Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by