how to find cosine angle known the end points of 2 linesegments
2 次查看(过去 30 天)
显示 更早的评论
There are 2 line segments, known their end points, how can i find angle between them
采纳的回答
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)
0 个评论
更多回答(1 个)
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Function Creation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!