Finding cosine of angle formed by two adjacent points of a curve and horizontal line
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Vahid Esmaeili
il 21 Lug 2020
Commentato: Vahid Esmaeili
il 24 Lug 2020
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,
0 Commenti
Risposta accettata
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);
Thanks
Kiran
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!