How to Adjust Elevation and Azimuth Relative to the Original Route in 2D/3D Plot (lat, long, alt) in MATLAB?

5 views (last 30 days)

Hi, I have a route represented by latitude, longitude, and altitude values, and I would like to adjust this route based on specific azimuth and elevation angles relative to the original route.

The inputs are:

• A route consisting of latitude, longitude, and altitude. • Desired azimuth and elevation angles relative to the original route.

I attempted to convert the route points to Cartesian coordinates and apply a rotation matrix, but I couldn’t achieve the correct transformation. Does anyone have advice on how to transform the points correctly and plot the adjusted route in both 2D and 3D using MATLAB?

Thanks in advance!

Answers (1)

Zinea
Zinea on 8 Oct 2024
Hi Lidor,
To adjust the route based on specified azimuth and elevated angles (given as inputs), the method of converting the latitude, longitude, and altitude data into Cartesian coordinates, applying a rotation matrix, and then converting back to geographic coordinates is the way to go.
You can refer to the steps below for reference implementation:
  1. Get all the inputs (latitudes, longitudes, altitudes, azimuthal and elevation angles):
% Define the original route (latitude, longitude, altitude)
lat = [34.0522, 34.0525, 34.0528]; % Example latitudes
lon = [-118.2437, -118.2434, -118.2431]; % Example longitudes
alt = [100, 110, 120]; % Example altitudes in meters
% Convert to Cartesian coordinates
% Assuming Earth radius + altitude for simplicity
R = 6371000; % Earth's radius in meters
x = (R + alt) .* cosd(lat) .* cosd(lon);
y = (R + alt) .* cosd(lat) .* sind(lon);
z = (R + alt) .* sind(lat);
% Desired azimuth and elevation angles in degrees
azimuth = 30; % Example azimuth angle
elevation = 10; % Example elevation angle
% Convert angles to radians
azimuth_rad = deg2rad(azimuth);
elevation_rad = deg2rad(elevation);
2. Perform rotation using rotation matrices:
% Create rotation matrices
Rz = [cos(azimuth_rad), -sin(azimuth_rad), 0;
sin(azimuth_rad), cos(azimuth_rad), 0;
0, 0, 1];
Ry = [cos(elevation_rad), 0, sin(elevation_rad);
0, 1, 0;
-sin(elevation_rad), 0, cos(elevation_rad)];
% Apply rotations
rotation_matrix = Rz * Ry;
adjusted_coords = rotation_matrix * [x; y; z];
% Extract adjusted coordinates
x_adj = adjusted_coords(1, :);
y_adj = adjusted_coords(2, :);
z_adj = adjusted_coords(3, :);
3. Convert the adjusted coordinates back to latitude, longitude and altitude:
% Convert back to latitude, longitude, altitude
lat_adj = asind(z_adj / R);
lon_adj = atan2d(y_adj, x_adj);
alt_adj = sqrt(x_adj.^2 + y_adj.^2 + z_adj.^2) - R;
4. Plot the original and adjusted routes in 2D and 3D:
figure;
subplot(1,2,1);
plot3(lon, lat, alt, 'b-o', 'DisplayName', 'Original Route');
hold on;
plot3(lon_adj, lat_adj, alt_adj, 'r-o', 'DisplayName', 'Adjusted Route');
xlabel('Longitude');
ylabel('Latitude');
zlabel('Altitude (m)');
title('3D Route');
legend;
grid on;
subplot(1,2,2);
plot(lon, lat, 'b-o', 'DisplayName', 'Original Route');
hold on;
plot(lon_adj, lat_adj, 'r-o', 'DisplayName', 'Adjusted Route');
xlabel('Longitude');
ylabel('Latitude');
title('2D Route');
legend;
grid on;
Here is the output figure:
The following link can be referred for more information on ‘Matrix rotations and transformations’:
Hope this helps!
  1 Comment
Lidor
Lidor on 8 Oct 2024
What I was actually trying to rotate the route around the final point so around the final point we can have axis and Trying to rotate around it

Sign in to comment.

Categories

Find more on Cartesian Coordinate System Conversion in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!