finding the angle between a line and oblique axis

6 ビュー (過去 30 日間)
Suzuki
Suzuki 2021 年 9 月 22 日
回答済み: Dev 2025 年 5 月 30 日
is there any way to find the angle between a line (vector) and its coressponding axis. I don't want to rotate to x-axis and work from there.
please refer to the attached image.

回答 (1 件)

Dev
Dev 2025 年 5 月 30 日
We can compute the angle between a vector and an axis (X, Y or Z) directly without rotating any of the axes, using the dot product formula.
Given a vector v = [vx, vy] or [vx, vy, vz], and an axis unit vector:
  • X-axis: u = [1, 0] or [1, 0, 0]
  • Y-axis: u = [0, 1] or [0, 1, 0]
  • Z-axis: u = [0, 0, 1] (for 3D)
The angle between vector ‘v’ and axis ‘u’ can be calculate as follows-
Θ = cos1(v*u/v*u∥ ​)
We can compute the same using the “dot” and “acos” functions available in MATLAB. I have attached a reference code snippet below which achieves the same.
% Compute angle
cosTheta = dot(v, u) / (norm(v) * norm(u));
angleRad = acos(cosTheta);
angleDeg = rad2deg(angleRad); % since acos returns angle in Radians
For more information regarding these functions, please refer to the documentation links using the below commands in your MATLAB terminal-
>> doc dot
>> doc acos
I hope the above explanation helps.

カテゴリ

Help Center および File ExchangeGeometric Transformation and Image Registration についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by