Intersection between unknown functions
Show older comments
I have different plots that have no function. One type of plot is from a csv.file that I got 34 plots and the other 2 are lines of 2 points. So I want to find the intersection between each line of plot(x,y) inside the loop and those 2 other lines (see the picture).
clc
clear
data = readtable('Group 4 (Trajectories).csv');
Trajectory_index = data(:,1);
MMSI = data(:,2);
Longitude = data(:,4);
Latitude = data(:,5);
figure(); hold on
for i = 1:1:34
idx = data.Trajectory_index == i;
newTable = data(idx,:);
x = newTable.Latitude;
y = newTable.Longitude;
axis([36.4 42 -10.5 -9]);
plot(x,y);
end
x1 = ([38.7091 38.715]);
y1 = ([-10.1466 -10.0655]);
plot(x1, y1);
x2 = ([37.8602 37.8927]);
y2 = ([-10.0353 -9.8046]);
plot(x2, y2);
hold off
shg

Answers (1)
Walter Roberson
on 6 Nov 2022
x = newTable.Latitude;
y = newTable.Longitude;
At that point, use https://www.mathworks.com/matlabcentral/fileexchange/93470-intersections-of-multiple-2d-lines-or-line-segments
Originally I was going to suggest using interp1() but then I noticed the line segments are slightly sloped.
Categories
Find more on Graphics Objects 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!