Clear Filters
Clear Filters

How to detect number of rotations in a trajectory?

3 views (last 30 days)
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 Comment
Les Beckham
Les Beckham on 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.

Sign in to comment.

Answers (1)

Supraja
Supraja on 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)]);

Categories

Find more on 3-D Scene Control 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!