Effacer les filtres
Effacer les filtres

How to detect number of rotations in a trajectory?

3 vues (au cours des 30 derniers jours)
Diana
Diana le 15 Juil 2023
Réponse apportée : Supraja le 26 Juil 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 commentaire
Les Beckham
Les Beckham le 20 Juil 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.

Connectez-vous pour commenter.

Réponses (1)

Supraja
Supraja le 26 Juil 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)]);

Catégories

En savoir plus sur 3-D Scene Control dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by