Finding cosine of angle formed by two adjacent points of a curve and horizontal line

3 visualizzazioni (ultimi 30 giorni)
Hello,
I am wondering how to calculate the cosine of the angle formed by two very close points and the horizontal line in MATLAB? I want to find the cosine between every pair of adjacent points in a matrix. Please find a matrix ( of 1761 rows and 1 column in the attached EXCEL file).
Thank you so much,

Risposta accettata

Kiran Felix Robert
Kiran Felix Robert il 24 Lug 2020
Hi Vahid,
It is my understanding that you attempt to find the angle between the line formed by joining two adjacent points and the x-axis. Also use that to find angle between lines formed by every pair of adjacent points. The angle with the x-axis or the horizontal can be calculated as shown below, assuming B is the input Vector,
angle = zeros(length(B)-1,1); % Pre-allocating angles vector
for i = 1:(length(B)-1)
x = [i i+1];
y = [B(i) B(i+1)];
slope = (y(2) - y(1))/(x(2)-x(1));
angle(i) = atand(slope); % Angle in degrees
end
Angle between the lines can be calculated by simply subtracting the values in the angle vector.
angle1 = angle(2) - angle(1);
To find cosine use the cosd function as the angle is in degrees.
Thanks
Kiran
  1 Commento
Vahid Esmaeili
Vahid Esmaeili il 24 Lug 2020
Hi Kiran,
Thank you so much for your answer to my question.
It was an effort to find an answer to a very important question (related to normal and pathologic gait analysis) that I asked and we are still trying to find an answer. Please find the question in the following link:
In fact (as a beginner), I thought maybe comparing the angle between two adjacent points is a practical way to find a solution for that question. Compared to traditional methods, human gait analysis by MATLAB using the data of the position of two markers attached to forefoot and heel in 3D space is a fast way. I guess you are busy with different projects but I hope you can help me with the question.
I appreciate your kind attention to my request.
Vahid,

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by