how to make patch which is perpendicular to the line?

1 次查看(过去 30 天)
I have longitude, latitude, altitude data which is aircraft data.
I made patches which contain trajectory(consisting of lon,lat,alt data) and connect i th patch's vertices to i+1 th patch's vertcies.
(I used percentile to make a patch. ex) if percentile is 100, the patch contains every trajectory. In my case, I used 97.5 percentile.)
but the patch is slightly titled when viewing from the top.
(maybe it is because I fixed the 'y' values(longitude) to make a patch. but I don't know how to modify my code.)
So I want to make a patch which is perpendicular to mean trajectory(the line).
I will attach the images and the code.
first image is what i did.
second and third is what i want to plot.
Let me know how to solve this problem.
Thanks!
for i = 1:length(33R)
plot3(33R(i).Longitude, 33R(i).Latitude, 33R(i).BAlt)
hold on
end
hold on
xlabel('X')
ylabel('Y')
zlabel('Z')
yv = [];
yv = [yv;mean_trajectory.Latitude];
for i = 1:length(trajectory)
xptcl = prctile(trajectory(i).Longitude,[2.5 97.5]);
zptcl = prctile(trajectory(i).Altitude,[2.5 97.5]);
xl(i,:) = xptcl;
zl(i,:) = zptcl;
patch([xptcl flip(xptcl)], [0 0 0 0]+yv(i), [[1 1]*zptcl(1) [1 1]*zptcl(2)],'r', 'FaceAlpha',0.5)
end
plot3(xl(:,1), yv(:), zl(:,1), '-k', 'LineWidth',2)
plot3(xl(:,1), yv(:), zl(:,2), '-k', 'LineWidth',2)
plot3(xl(:,2), yv(:), zl(:,1), '-k', 'LineWidth',2)
plot3(xl(:,2), yv(:), zl(:,2), '-k', 'LineWidth',2)
grid on

回答(1 个)

Abhinaya Kennedy
Abhinaya Kennedy 2023-12-8
Hi Sierra,
It seems like you want to adjust your code to make the patch perpendicular to the mean trajectory. To achieve this, you can modify your code to calculate the mean trajectory and then adjust the patch creation process. Below is a modified version of your code to achieve this:
% Calculate mean trajectory
mean_lon = mean([33R.Longitude], 2);
mean_lat = mean([33R.Latitude], 2);
mean_alt = mean([33R.BAlt], 2);
% Plot the trajectory
for i = 1:length(33R)
plot3(33R(i).Longitude, 33R(i).Latitude, 33R(i).BAlt)
hold on
end
% Create the mean trajectory line
plot3(mean_lon, mean_lat, mean_alt, '-k', 'LineWidth', 2)
% Calculate the perpendicular direction
direction = cross([mean_lon(2:end) - mean_lon(1:end-1), mean_lat(2:end) - mean_lat(1:end-1), mean_alt(2:end) - mean_alt(1:end-1)], [0, 0, 1]);
direction = direction ./ vecnorm(direction, 2, 2);
% Create patches perpendicular to the mean trajectory
for i = 1:length(trajectory)
xptcl = prctile(trajectory(i).Longitude, [2.5 97.5]);
zptcl = prctile(trajectory(i).Altitude, [2.5 97.5]);
yv = mean_trajectory.Latitude(i);
patch([xptcl(1), xptcl(2), xptcl(2), xptcl(1)], ...
[yv, yv, yv, yv], ...
[zptcl(1), zptcl(1), zptcl(2), zptcl(2)], 'r', 'FaceAlpha', 0.5)
% Project the patch onto the perpendicular direction
patch_projection = dot([xptcl(1) - mean_lon(i), yv - mean_lat(i), zptcl(1) - mean_alt(i)], direction(i, :)) * direction(i, :);
patch([mean_lon(i), mean_lon(i) + patch_projection(1)], ...
[mean_lat(i), mean_lat(i) + patch_projection(2)], ...
[mean_alt(i), mean_alt(i) + patch_projection(3)], '-k', 'LineWidth', 2)
end
xlabel('X')
ylabel('Y')
zlabel('Z')
grid on
This modified code calculates the mean trajectory and then projects the patches onto a direction perpendicular to the mean trajectory. It also adds the mean trajectory line to the plot.
Hope this helps!

类别

Help CenterFile Exchange 中查找有关 Polygons 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by