Entry and exit points / trajectories through a rectangle (orbits)
조회 수: 3 (최근 30일)
이전 댓글 표시
Hi, I have a set of (x,y) points that are continuous orbit trajectories crossing a certain rectangle at specific times. The (x,y) points are always consecutive, meaning they are not scattered points but they follow a certain path with time. At some point they will enter the rectangle and eventually will leave it through another side. This will occur several times. I assume I need to find the (x,y) points that are inside the rectangle and then compute a diff to identify the boundaries. But I need to know the 'entry' and 'exit' points, and I don't always manage. If I identify them wrongly (entry and exit are switched) then the error is very large. Any idea on how to do that?
Attached a mat file with the (x,y) points = (satlon, satlat) that define the trajectories for which I want to find entry and exit points to the rectangle. Currently I'm using this code but it does not always work ok, only sometimes. Script for using the code also attached.
Thanks!
댓글 수: 0
답변 (2개)
Image Analyst
2023년 11월 5일
Basically if you have the x and y of the trajectory, and the x and y of the sides, then you simply need to use interp1 to find where it crosses the rectangle lines.
댓글 수: 7
Image Analyst
2023년 11월 5일
Make it easy for me to help you in a few minutes. Give the code to read in that mat file into your variables. I'll check back later.
Star Strider
2023년 11월 5일
편집: Star Strider
2023년 11월 6일
This should be a relatively straightforward interpolation problem in that the only calculations necessary should be to first find the approximate indices of the respective latitude and longitude crossings and then use those to interpolate to get more precise values for the crossings. That part works well enough and produces what may be appropriate times (I created a time vector for this, use the correct one). However to check the calculations, I also interpolated the crossing longitudes for the target latitudes and the crossing latitudes for the crossing longitudes. That did not go as well as I would have liked, and they are not plotting correctly.
Getting the correct latitudes and longitudes for the interpolatioon also required checking to avoid ‘end effects’ where the coordinates abruptly reversed sign, for example from -179 to +179, since my code interpreted that as crossing the target latitudes or longitudes (correct, however returning spurious data), so a correction for that had to be included.
The problems may be in my understanding of your data and of the coordinate system (I am not used to dealing with geographical coordinates) rather than an inherent problem in my code itself, so I’m posting this anyway.
type('entry_exit.m')
cycle = load('full_test.mat')
slat = cycle.satlat
slon = cycle.satlon
L = numel(slat); % Length Of Data Array
Fs = 2; % Sampling Events / Time Unit
tv = linspace(0, numel(slat), numel(slat)).'/Fs; % Sampling Times
latlim = [-20 10]; % Get Times & Longitudes For Each Latitude
for k = 1:numel(latlim)
zx = find(diff(sign(slat - latlim(k))));
latzx{k} = zx(abs(slat(zx) - latlim(k)) < 5);
end
latzx
tlatx = NaN(numel(latlim), max(numel(latzx{:})));
lonlatx = tlatx;
for k1 = 1:numel(latzx)
for k2 = 1:numel(latzx{k1})
idxrng = max(1, latzx{k1}(k2)-1) : min(latzx{k1}(k2)+1,L);
% CheckData = [slat(idxrng) slon(idxrng) tv(idxrng)]
tlatx(k1,k2) = interp1(slat(idxrng), tv(idxrng), latlim(k1)); % Crossing Time For This Latitude
lonlatx(k1,k2) = interp1(slat(idxrng), slon(idxrng), latlim(k1)); % Crossing Longitude For This Latitude
latlatx(k1,k2) = interp1(slon(idxrng), slat(idxrng), lonlatx(k1,k2)); % Crossing Latitude For This Latitude
end
end
% latlatx.'
Latitude = table(tlatx(1,:).',lonlatx(1,:).',tlatx(2,:).',lonlatx(2,:).', 'VariableNames',["Time"+latlim(1), "Lon"+latlim(1), "Time"+latlim(2), "Lon"+latlim(2)])
lonlim = [70 90]; % Get Times & Latitudes For Each Longitude
for k = 1:numel(lonlim)
zx = find(diff(sign(slon - lonlim(k))));
lonzx{k} = zx(abs(slon(zx) - lonlim(k)) < 5);
end
lonzx
tlonx = NaN(numel(lonzx), max(numel(lonzx{:})));
latlonx = tlonx;
for k1 = 1:numel(lonzx)
for k2 = 1:numel(lonzx{k1})
idxrng = max(1, lonzx{k1}(k2)-1) : min(lonzx{k1}(k2)+1,L);
% CheckData = [slat(idxrng) slon(idxrng) tv(idxrng)]
tlonx(k1,k2) = interp1(slon(idxrng), tv(idxrng), lonlim(k1)); % Crossing Time For This Longitude
latlonx(k1,k2) = interp1(slon(idxrng), slat(idxrng), lonlim(k1)); % Crossing Latitude For This Longitude
lonlonx(k1,k2) = interp1(slat(idxrng), slon(idxrng), latlonx(k1,k2)); % Crossing Longitude For This Longitude
end
end
% lonlonx.'
Longitude = table(tlonx(1,:).',latlonx(1,:).',tlonx(2,:).',latlonx(2,:).', 'VariableNames',["Time"+lonlim(1), "Lat"+lonlim(1), "Time"+lonlim(2), "Lat"+lonlim(2)])
figure
plot(slon, slat, '.-')
hold on
for k = 1:2
plot(lonlatx(k,:), latlatx(k,:), 'pr', 'MarkerFaceColor','r')
plot(lonlonx(k,:), latlonx(k,:), 'pg', 'MarkerFaceColor','g')
end
hold off
grid
% axis('equal')
xlim([70 90])
ylim([-20 10])
xlabel('Longitude')
ylabel('Latitude')
EDIT — (6 Nov 2023 at 05:24)
Revised code to plot the latitude and longitude intersections with the limits correctly. (It now works as I intend it to work.) The entry and exit times (when the actual time vector is supplied) should also now be verifiably correct. (Many of the intersections are close to the sampling points, so the sampling times nearest those intersections can be used if the exact intersection times themselves are not needed.)
.
댓글 수: 2
Star Strider
2023년 11월 5일
Thank you!
If you only want the nearest indices to the entry and exit ponts, then use the ‘latzx’ and ‘lonzx’ values, respectively. Those should be the closest indices.
참고 항목
카테고리
Help Center 및 File Exchange에서 Detection에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!