How to detect number of rotations in a trajectory?

1 Ansicht (letzte 30 Tage)
Diana
Diana am 15 Jul. 2023
Beantwortet: Supraja am 26 Jul. 2023
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 Kommentar
Les Beckham
Les Beckham am 20 Jul. 2023
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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Supraja
Supraja am 26 Jul. 2023
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)]);

Kategorien

Mehr zu General Applications finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by