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

33 visualizaciones (últimos 30 días)
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])

Respuesta aceptada

Matt J
Matt J el 9 de Ag. de 2022
Editada: Matt J el 9 de Ag. de 2022
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 comentarios
Jeremy Salerno
Jeremy Salerno el 9 de Ag. de 2022
@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 el 9 de Ag. de 2022
Editada: Matt J el 9 de Ag. de 2022
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);

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Polar Plots en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by