MATLAB Answers

how to calculate direction in rotated coordinate system

22 views (last 30 days)
UWM
UWM on 11 Jan 2020
Commented: UWM on 15 Jan 2020
I have a direction defined by azimuth and evation (e.g. Azi, Elev).
I would like to calculate values of these Azi i Elev after coordinate system
rotation: first around Z axis (angle e.g.: Zrot) and then around rotated (in first rotation
around Z axis) Y axis (angle e.g.: Yrot).
So: I rotate coordinate system around Z axis, then around "rotated" Y axis and I would like to
calculate Azi and Elev in rotated coordinate system.
How can be it done?

  1 Comment

Sign in to comment.

Accepted Answer

David Goodmanson
David Goodmanson on 12 Jan 2020
Edited: David Goodmanson on 12 Jan 2020
Hi UWM,
Assuming the correct rotation has already been made, then calling the resulting vector u, and making sure it is normalized by using u/norm(u), suppose the three components of u are given in the order (north,east, up) in an appropriate coordinate system. Assuming elevation is measured up from the horizon and azimuth is measured clockwise from north (as with a compass rose), u has the form
cos(el)*cos(az)
cos(el)*sin(az)
sin(el)
then you can divide the second expression by the first to arrive at
el = asin(u(3))
az = atan2(u(2)/u(1)
There are a lot of variations on this theme depending on how the vector components and the angles are defined, but the basic idea will be the same.

  3 Comments

UWM
UWM on 14 Jan 2020
Hi David,
thank you for help. I am not understood everything well so
below is my code. But it looks like something's wrong - e.g.
rotation around Y axis is done not after rotated axis (in first rotation
around Z axis) but around 'old' coordinate system axis.
Maybe you can help me.
clc
clear
% Direction
% geodetic elevation and azimuth (Esvo - elevation is the elevation in deg from the x-y plane (-90 90), Asvo azimuth is the clockwise angle in the x-y plane measured in deg from the positive x-axis (0 360).
Esvo = 50;
Asvo = 40;
% elevation and azimuth in MatLab
Esv = Esvo;
if Asvo < 180; Asv=-Asvo;
else Asv = 360-Asvo;
end
% coordinate system rotation angles (Aro - around Z axis, Ero - around Y axis)
% Aro possible range (0 360); Ero possible range (0 90)
Aro = 5
Ero = 1:90
Ar = -Aro;
Er = 90-Ero;
r=1;
dtr = pi/180;
dts = 180/pi;
Es=Esv*dtr; % deg to rad
As=Asv*dtr; % deg to rad
% Direction position in MatLab
[x0,y0,z0] = sph2cart(As,Es,r);
poz0 = [x0 y0 z0];
for j=1:length(Aro)
for i=1:length(Ero)
% coordinate system rotation
ROTZ = [ cosd(Ar(j)) -sind(Ar(j)) 0;
sind(Ar(j)) cosd(Ar(j)) 0;
0 0 1];
ROTY = [ cosd(Er(i)) 0 sind(Er(i));
0 1 0;
-sind(Er(i)) 0 cosd(Er(i))];
% Direction position after rotation (in Matlab)
poz1 = poz0*ROTZ*ROTY;
x1 = poz1(1);
y1 = poz1(2);
z1 = poz1(3);
% Direction azimuth and elevation after rotation (in Matlab)
[az,el,r] = cart2sph(x1,y1,z1);
% rad to deg
AZYa=az*dts;
ELVa=el*dts;
% Direction azimuth and elevation after rotation (in geodetic system)
if AZYa <0; AZY=abs(AZYa);
else AZY=360-AZYa;
end
ELV = ELVa;
Results(1,i,j) = AZY;
Results(2,i,j) = ELV;
end
end
David Goodmanson
David Goodmanson on 15 Jan 2020
Hi UWM,
Although there is more than one convention for how to do this, I am guessing that you are doing an active rotation, i.e. there is an overall fixed coordinate system S and you are rotating a vector object within that system. After a series of rotations, the final result is expressed as coordinates in S.
You are expressing the vector as a row vector and multiplying by rotation matrices on the right. If you have not done so already, it's a good idea to run some test cases on rotz,roty and also rotx at, say, 45 degrees to verify that they are doing what you think.
Now you wish to first rotate about the z axis, which rotates the object and also rotates the y and x axes to xnew and ynew. That's followed by a rotation about ynew.
Abbreviating rotz as Rz etc, a rotation of v about the z axis followed by a rotation about the old y axis would have been
vrot = v*Rz*Ry [1]
the matrix Rynew, a rotation about ynew, is related to the original Ry by
Rynew = Rz^(-1)*Ry*Rz
and so
vrot = v*Rz*Rz^(-1)*Ry*Rz = v*Ry*Rz
This uses rotations involving the original coordinate system, only with the order reversed compared to [1]. Hope this helps.

Sign in to comment.

More Answers (1)

Matt J
Matt J on 14 Jan 2020
Edited: Matt J on 14 Jan 2020
Using AxelRot (Download), and assuming all angles are given in radians,
[x,y,z] = sph2cart(Azi_Old,Elev_Old,1);
P=AxelRot( [x,y,z;0,1,0].' , Zrot*180/pi, [0,0,1], []);
Q=AxelRot( P(:,1), Yrot*180/pi, P(:,2), []);
[Azi_New,Elev_New]=cart2sph( Q(1),Q(2),Q(3) );

  1 Comment

UWM
UWM on 15 Jan 2020
Thank you for help, I checek also your approach and it also works very well:)

Sign in to comment.

Sign in to answer this question.


Translated by