필터 지우기
필터 지우기

How to detect number of rotations in a trajectory?

조회 수: 4 (최근 30일)
Diana
Diana 2023년 7월 15일
답변: Supraja 2023년 7월 26일
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에서 3-D Scene Control에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by