How to accurately find angle between these two vectors ? (Data Provided).
5 views (last 30 days)
Show older comments
Cenker Canbulut on 24 Jul 2020
I am struggling so hard to accurately find angle between two vectors. I don't know where I am doing mistake but the angle result of cos(theta) from formula gives incorrect angle.
If you will be asking where I know that it is incorrrect, I know it because I am using rotation matrix to rotate one of them along Z-axis to fit one vector to another.
I basically want to rotate vector1 x,y,z with the angle found between vector1 and vector2.
Here is the angle I am trying to find.
and actually finding it with formula.
Angle Formula :
Rotation Formula along z-Axis (CLOCKWISE) :
|x cos(-θ) − y sin(-θ)| |x'|
|x sin(-θ) + y cos(-θ)| = |y'|
| z | |z'|
Graph rotates respectively and without deformation but much more than the found cousine value.
All answers are welcomed
function [theta, Nrm]=vecrot(vstart,vend)
%Find rotation carrying one vector toward another about their common perpendicular
% vstart: Initial vector, 3D
% vend: Final vector, 3D
% theta: the rotation angle in degrees
% Nrm: the rotation axis, directed so that rotation is clock-wise by theta about Nrm
theta = atan2d(sqrt(1-b^2),b);
Since theta is in degrees, you should be using sind and cosd. Also, the rotation formula that you are using assumes inappropriately that Vector1 and Vector2 both lie in the xy-plane, and therefore that the rotation is about the z-axis. This is clearly not true:
The actual rotation axis is returned in the Nrm output argument from the code I gave you. You can perform the rotation about this axis (or any other), using my AxelRot utility on the File Exchange
The alignment is not as good as my other answer, because the single-angle calibration model is not good (or so it seems). It ignores origin shift between the two data sets.
More Answers (1)
I don't know what your ultimate purpose is with this rotation you are trying to perform. If the goal is to make the two loci overlap as much as possible, I think you should be doing more than just a one degree-of-freedom angle match-up. I think you should be doing a full 6 degree-of-freedom rigid registration. You can do this with absor from the File Exchange, which for me gives pretty good overlap:
Find more on Orange in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!