how to make a cross section of lines and connect cross sections?

i have trajectory data(longitude, latitude, altitude).
I want to make a cross section of lines, which consist of data(longitude, latitude, altitude data). and connect i th boundray's vertices to i+1 th boundary's vertices, so i can make something like a tube.
the cross section(i will call it boundary) will be made using 'percentile'.
for example, if percentile is 100, the boundary includes every trajectory.
(In my case, the percentile will be 97.5.)
i know the process of this. but i have no idea of doing this by Matlab.
i will upload images of the process.
1) make a cross section at k th point of mean trajectory(red)
2) using percentile, make a boundary
3) connect k th boundray's vertices to k+1 th boundary's vertices
first image is the cross section of lines. red point is mean point of trajectory. and this boundary is made using 'specific percentile', so some trajectory data is out of boundary.

 Accepted Answer

I do not have your data, however consider something like this —
It would appear that the ‘y’ value is fixed in any specific location, so that it is only necessary to draw the percentile boxes with respecty to the ‘x’ and ‘z’ axes.
Example —
x = rand(1,5000)*10+125;
y = randn(1,5000)*50+250;
z = randn(1,5000)*150+300;
t = linspace(0, 1, 5000);
x = x + sin(2.5*pi*t)*125;
y = y + cos(1.5*pi*t)*125;
yv = linspace(min(y), max(y), 7); % Set 'Y' Values For The Box Locations
figure
scatter3(x,y,z,'.')
hold on
for k = 1:numel(yv)
yrng = find(y>=0.8*yv(k) & y <=1.2*yv(k));
xpctl = prctile(x(yrng),[2.5 97.5]);
zpctl = prctile(z(yrng),[2.5 97.5]);
xl(k,:) = xpctl;
zl(k,:) = zpctl;
patch([xpctl flip(xpctl)], [0 1 1 0]+yv(k), [[1 1]*zpctl(1) [1 1]*zpctl(2)], 'r', 'FaceAlpha',0.25)
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)
hold off
xlabel('X')
ylabel('Y')
zlabel('Z')
% xlim([120 140])
% ylim([100 400])
view(45,30)
Make appropriate changes in my code to work with your data.
EDIT — (26 May 2022 at 00:50)
Added lines connecting the patch corners. (Away for most of the day today so did not get the opportunity to do this until now.)
.

7 Comments

First, my data is longitude, latitude and altitude data for aircrafts. so, if I plot the data, there are server lines just like first image.
First image is what I want to plot.(I already plotted the lines.)
and i have trobule understanding this code.
In this part,
xl(k,:) = xpctl;
zl(k,:) = zpctl;
patch([xpctl flip(xpctl)], [0 1 1 0]+yv(k), [[1 1]*zpctl(1) [1 1]*zpctl(2)], 'r', 'FaceAlpha',0.25)
end
and did you use patch corners to connect the vertices? I've tried to find this fuction. but i couldn't find this fuction.
if you don’t mind, could you explain more specifically? Please
Thanks again, Strider
btw, don't we need mean point of boundary to make a boundary using percentile?
for i = 1:length(Dep_33L) % Plot a Trajectory Data
plot3(Dep_33L(i).Longitude, Dep_33L(i).Latitude, Dep_33L(i).BAlt)
hold on
end
for i = 1:length(Dep_33L)
x = Dep_33L(i).Longitude;
y = Dep_33L(i).Latitude;
z = Dep_33L(i).BAlt; % BAlt is altitude
yv = linspace(min(y), max(y), 7); % Does 7 mean number of boundaries?
for k = 1:numel(yv)
yrng = find(y>=0.8*yv(k) & y <=1.2*yv(k)); % Where did this 0.8 and 1.2 come from? and what does it mean?
xpctl = prctile(x,[2.5 97.5]);
zpctl = prctile(z,[2.5 97.5]);
xl(k,:) = xpctl;
zl(k,:) = zpctl;
patch([xpctl flip(xpctl)], [0 1 1 0]+yv(k), [[1 1]*zpctl(1) [1 1]*zpctl(2)], 'r', 'FaceAlpha',0.25)
% I want to know why you used 'flip' and what do [0 1 1 0]+yv(k), [[1 1]*zpctl(1)
% [1 1]*zpctl(2)] mean
end
end
plot3(xl(:,1), yl(:), zl(:,1), '-k', 'LineWidth',2) % I don't understand why you coded xl(:,1) and x1(:,2)
plot3(xl(:,1), yl(:), zl(:,2), '-k', 'LineWidth',2) % Could you explain? thanks.
plot3(xl(:,2), yl(:), zl(:,1), '-k', 'LineWidth',2)
plot3(xl(:,2), yl(:), zl(:,2), '-k', 'LineWidth',2)
hold off
xlabel('X')
ylabel('Y')
zlabel('Z')
% xlim([120 140])
% ylim([100 400]) % May I delete this code?
view(45,30)
thanks!
With respect to your first Comment, I have no idea what you are referring to. My code creates the percentile limits as a function of the ‘x’ and ‘z’ values at specific points along the ‘y’ variable (and then plots the results) since the earlier drawing specified that approach.
With respect to your second Comment:
The ‘xl’ and ‘zl’ assignments store the percentile vectors as matrices. This is for the plot of the lines coinnecting the corners of the patches.
The patch call creates the filled patches, since that appears to be required. The patch function fills closed surfaces that must be described as a continuous outline of those surfaces around the surface bounds. My code here draws patches with respect to the percentile values at specific points along the y-axis. The first and third arguments to it draw the patches and the second argument locates them as a funciton of ‘y’. Note that it draws them going from a ‘y’ value of 0, then goes anti-clockwise to 1, up to 1, and back to 0. (The funciton closes the patch by itself.) All the patch coordinates must follow the same coordinate-order convention for the patch to be created successfully. (This also applies to your third Comment. See the patch documentation and experiment with the function to understand my calls to it. The plot3 calls after the loop draw the lines connecting the corners of the patches.)
‘btw, don't we need mean point of boundary to make a boundary using percentile?’
No. The prctile function does not require that.
I leave it to you to adapt my code to your data.
.
Thanks Strider. I'm adapting your code to my data.
but I still don't understand why did you use this code
yrng = find(y>=0.8*yv(k) & y <=1.2*yv(k));
what do 0.8 and 1.2 mean in this code?
As always, thanks.
Have a nice day!
As always, my pleasure!
That line is from my original code:
for k = 1:numel(yv)
yrng = find(y>=0.8*yv(k) & y <=1.2*yv(k));
xpctl = prctile(x(yrng),[2.5 97.5]);
zpctl = prctile(z(yrng),[2.5 97.5]);
xl(k,:) = xpctl;
zl(k,:) = zpctl;
patch([xpctl flip(xpctl)], [0 1 1 0]+yv(k), [[1 1]*zpctl(1) [1 1]*zpctl(2)], 'r', 'FaceAlpha',0.25)
end
It is used to find the points in the region around ‘yv(k)’ in order to calculate the percentiles, since it is unlikely that there are any points exactly at ‘y(k)’ in my simulated data. The limits of 0.8 and 1.2 are arbitrary based on experimenting with my simulated data. I chose them to be reasonably representative and so as to not collide or overlap with the regions around the neighbouring values of ‘yv(k)’. If your data are such that the ranges are not needed and that there are sufficient points at ‘yv(k)’ to calculate the percentiles, then that assignment is not necessary, and it and references to ‘yrng’ can be eliminated. (I want to make my code as robust as possible.)
.
Thanks, Strider. I understood
But I found that 'y' valuse is not fixed in one cross section, because the trajectory is tiltied, as you can see in first image.
and i have big trouble using your code for my output. but the result is not what i intended to make.
the second and third image is the result.
for i = 1:length(Dep_33L)
x = Dep_33L(i).Longitude;
y = Dep_33L(i).Latitude;
z = Dep_33L(i).BAlt;
t = linspace(0, 1, 30);
yv = linspace(min(y), max(y), 30); % Set 'Y' Values For The Box Locations
scatter3(x,y,z,'.')
hold on
end
for k = 1:length(yv)
for i = 1:length(Dep_33L)
x(i) = Dep_33L(i).Longitude(k);
z(i) = Dep_33L(i).BAlt(k);
end
xpctl = prctile(x,[2.5 97.5]);
zpctl = prctile(z,[2.5 97.5]);
xl(k,:) = xpctl;
zl(k,:) = zpctl;
patch([xpctl flip(xpctl)], [0 1 1 0]+yv(k), [[1 1]*zpctl(1) [1 1]*zpctl(2)], 'r', 'FaceAlpha',0.25)
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)
hold off
xlabel('X')
ylabel('Y')
zlabel('Z')
% xlim([120 140])
% ylim([100 400])
I am not certain how to fix those problems.
My code is based on the information originally provided and the diagrams describing the desired result.
Perhaps adjusting the prctile limits will work, since the ‘xpctl’ value appears to be the problem.

Sign in to comment.

More Answers (0)

Asked:

on 25 May 2022

Commented:

on 27 May 2022

Community Treasure Hunt

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

Start Hunting!