Detect abrupt change in trajectory (coordinates)

14 ビュー (過去 30 日間)
Butterflyfish
Butterflyfish 2020 年 5 月 10 日
コメント済み: Butterflyfish 2020 年 5 月 12 日
I have a trajectory (cartesian) on a timeline (frames) and I need to find abrupt changes in trajectory, i.e. almost 180º. I found this: https://uk.mathworks.com/matlabcentral/answers/177523-detecting-path-trajectory-turns-in-tracking-data
but that script example doesn't seem to work very well for me (select frames in a straight line...) and I don't understand it well enough to fix it.
I have attached a example dataset with 3 columns: x, y (coordinates), frame nb (time). On this example, the first abrupt chang of trajectory should be found at around frame # 37.
I would be very grateful for any help!
Many thanks
  2 件のコメント
darova
darova 2020 年 5 月 10 日
I plotted your data
But i don't see any abrupt data like 180 degree
Butterflyfish
Butterflyfish 2020 年 5 月 11 日
Did you plot (x,y)? This is how the trajectory should look:
d = load('sampletrajectory.mat');
plot(d.trajectories1.pos_x, d.trajectories1.pos_y)

サインインしてコメントする。

採用された回答

darova
darova 2020 年 5 月 11 日
What about this? Just diff and atan2d
load sampletrajectory.mat
tr = table2array(trajectories1); % convert to array
x = tr(:,2); % x coord
y = tr(:,3); % y coord
t = atan2d(diff(y),diff(x)); % angle of each line
dt = wrapTo180(diff(t)); % angle between lines
ix = find(abs(dt)>150); % find angle
cla
plot(x(ix+1),y(ix+1),'or') % plot the angle
line(x,y) % plot the data
hold on
for i = 1:length(ix)
text(x(ix(i)+1),y(ix(i)+1),num2str(dt(ix(i))))
end
hold off
  3 件のコメント
darova
darova 2020 年 5 月 11 日
  • what atan2d and wrapTo180 do in this context?
Those functions do exactly as i wrote in comments:
t = atan2d(diff(y),diff(x)); % angle of each line
dt = wrapTo180(diff(t)); % angle between lines
aran2d calculates angle ( )
diff calculates difference between angles
wrapTo180 wraps angle to 0.. 180 degree range (if angle is 350 degree the function returns 10)
Butterflyfish
Butterflyfish 2020 年 5 月 12 日
Great, many thanks!

サインインしてコメントする。

その他の回答 (0 件)

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by