finding the angle between a line and oblique axis

4 vues (au cours des 30 derniers jours)
Suzuki
Suzuki le 22 Sep 2021
Réponse apportée : Dev le 30 Mai 2025
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.

Réponses (1)

Dev
Dev le 30 Mai 2025
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.

Catégories

En savoir plus sur Geometric Transformation and Image Registration dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by