How to detect number of rotations in a trajectory?

7 次查看(过去 30 天)
Hello!
I have the x and y coordinates of a fish trajectory (nose tracking) within a tank, obtained from a video of 2 min. I am searching for an algorithm to detect the number of rotations of the fish within that period of time (being a rotation a change in direction of 360 degrees).
Do you have any suggestions about the best way to approach this?
  1 个评论
Les Beckham
Les Beckham 2023-7-20
If you provide a sample of the data (save it to a .mat file and attach it here using the paperclip icon in the INSERT section of the question/comment editor) you will be more likely to get an answer.

请先登录,再进行评论。

回答(1 个)

Supraja
Supraja 2023-7-26
I understand that you want to count the number of rotations based on the x and y coordinates.
You can use functions “cross” and “circshift” to calculate the number of rotations.
Here are the documentation links for the same:
https://www.mathworks.com/help/matlab/ref/circshift.html?s_tid=doc_ta
Sample code is attached below:
% Example x and y coordinates
x = [0, 1, 2, 3, 4, 3, 2, 1, 9, -1, -2, -1, 0];
y = [0, 1, 2, 18, 4, 3, 2, 1, 0, -1, -2, -1, 0];
% Create vectors from consecutive points
v = [x(2:end) - x(1:end-1); y(2:end) - y(1:end-1)];
% Calculate cross product between consecutive vectors
cross_product = v(1, :) .* circshift(v(2, :), -1) - v(2, :) .* circshift(v(1, :), -1);
% Count the number of sign changes
num_rotations = sum(cross_product(1:end-1) .* cross_product(2:end) < 0);
disp(['Number of rotations: ', num2str(num_rotations)]);

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by