필터 지우기
필터 지우기

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에서 Polar Plots에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by