How can I calculate and plot a 3D pointing vector from a 2D azimuth and elevation angle?

16 次查看(过去 30 天)
I have a list of azimuths and starting locations, which I use to compute an end location, then I plot the line as a pointing vector.
For every azimuth, I also have an elevation angle from 0 to 180 degrees (0 is straight down and 180 is straight up).
I essentially want to have my 2D pointing vector, and change it's 3D angle based on the elevation angle so that I end up with a 3D pointing vector.
I have this code that I wrote to get a 2D vector from the initial x and y starting points, as well as the initial 2D azimuth. This draws line of length 5 at 90 degrees clockwise from the north, now I want this line to be in 3D and 20 degrees up from vertical down. I can't figure out how to integrate the elevation angle to compute a 3D vector.
%test 2D to 3D pointing vectors
x1=2; %initial x position
y1=2; %initial y position
az2d=90; %degrees clockwise from 0 north
az_elevation=20; %degrees up from Z-down
L=5; %line length
x2=x1+(L*cosd(90-az2d)); %end x position calculated from initial and azimuth; matlab plotting angles is 90-angle (e.g. 90-degrees clockwise from north needs 90-90 as input)
y2=y1+(L*sind(90-az2d)); %end y position calculated from initial and azimuth; matlab plotting angles is 90-angle (e.g. 90-degrees clockwise from north needs 90-90 as input)
%plot
figure
plot([x1 x2], [y1 y2])

采纳的回答

Matt J
Matt J 2022-8-9
编辑:Matt J 2022-8-9
x1=2; %initial x position
y1=2; %initial y position
z1=0;
elev=20;
[az,r]=cart2pol(x1,y1);
[x2,y2,z2]=sph2cart(az,elev*pi/180,r);
line([0 x1],[0,y1],[0,z1]);
line([0 x2],[0,y2],[0,z2]);
xlabel X; ylabel Y; zlabel Z
grid on; view(15,40); axis equal
  2 个评论
Jeremy Salerno
Jeremy Salerno 2022-8-9
@Matt J This is great!! One question: Does cart2pol expect the origin to be at (0,0)? If I have a vector x1 and y1 points, and a vector of origins x0 y0, is there any way to compute the [az,r] based on those origins that aren't (0,0)?
Matt J
Matt J 2022-8-9
编辑:Matt J 2022-8-9
cart2pol and sph2cart and similar functions all assume the origin to be at (0,0,0). However, you can do things like,
[az,r]=cart2pol(x1-x0,y1-y0);

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by