how to find cosine angle known the end points of 2 linesegments

There are 2 line segments, known their end points, how can i find angle between them

댓글 수: 1

Note: you calculate the dot product of two vectors with dot and the norm with norm.

댓글을 달려면 로그인하십시오.

 채택된 답변

Guillaume
Guillaume 2015년 4월 29일
The arguments you pass to dot and norm must be vectors not scalars
v1 = [1 1]
v2 = [0 3]
D = [v1;v2]; %possibly you have something like this
costheta = dot(D(1, :), D(2, :)) / (norm(D(1, :)) * norm(D(2, :)));
thetaindegrees = acosd(costheta)

추가 답변 (1개)

Roger Stafford
Roger Stafford 2015년 4월 29일
편집: Roger Stafford 2015년 4월 29일
Using 'atan2' or 'atan2d' and cross product is more accurate for angles that are near zero or near pi (180 degrees.)
a = atan2(norm(cross(D1,D2)),dot(D1,D2)); % Angle in radians
or
a = atan2d(norm(cross(D1,D2)),dot(D1,D2)); % Angle in degrees

댓글 수: 1

I've around 60 such values in excel sheet and I need to calculate angle between all these points. How can I put the same in a loop for calculating it for 60 values?
D = xlsread('45_A.xls');
for i=1:60
CosTheta = dot(D(i,:),D(i+1,:))/(norm(D(i,:))*norm(D(i+1,:)));
ThetaInDegrees = acosd(CosTheta);
end
xslwrite('result',ThetaInDegrees);
but there is some error in the values. can u please help me

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Simulink에 대해 자세히 알아보기

질문:

2015년 4월 28일

댓글:

2015년 5월 5일

Community Treasure Hunt

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

Start Hunting!

Translated by