How to accurately find angle between these two vectors ? (Data Provided).
Show older comments
Hi Everyone,
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.
AFTER ROTATION:

Data
All answers are welcomed
5 Comments
J. Alex Lee
on 25 Jul 2020
can you post your code used to generate that result?
J. Alex Lee
on 25 Jul 2020
by the way, i don't know how much the paths are expected to match, but i don't think a simple rotation about z will cut it...if you look at the straight part, it looks like you also need at least a shift.
Cenker Canbulut
on 26 Jul 2020
Edited: Cenker Canbulut
on 26 Jul 2020
Image Analyst
on 26 Jul 2020
Why can't you attach your data here? Also, if you could make it easy for us to help you, not hard, then provide the code to make those plots and also to extract the linear parts of the curves into their own arrays, without all the other curving stuff. That would make it easy for us to compute a transform that will rotate and shift the one set to align and overlap with the other.
Cenker Canbulut
on 26 Jul 2020
Edited: Cenker Canbulut
on 26 Jul 2020
Accepted Answer
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:
load('MyData.mat')
Old=[VRDataX,VRDataY,VRDataZ].';
New=[NewMocapX,NewMocapY,NewMocapZ].';
[reg,OldRotated,err]=absor(Old,New);
hold on
scatter3(New(1,:),New(2,:),New(3,:),'MarkerFaceColor','r')
scatter3(OldRotated(1,:),OldRotated(2,:),OldRotated(3,:),'MarkerFaceColor','b')
hold off
legend('New','Old (Rotated)')

6 Comments
Cenker Canbulut
on 26 Jul 2020
Matt J
on 26 Jul 2020
But your data don't seem to share a comon z-axis or xyz origin as you appear to be assuming. absor will calibrate the orientation of all 3 axes as well as the origin translation between them.
Cenker Canbulut
on 26 Jul 2020
Edited: Cenker Canbulut
on 26 Jul 2020
Matt J
on 26 Jul 2020
What you are saying, in effect, is that you do not need a very accurate axes calibration. But then there is no reason not to use the calibration that absor gives you. It is at least as accurate as the calibration that you were already planning to use. The only difference is that instead of doing a single-theta rotation to transform points, you would use the transform parameters reg that absor gives you:
NewPoints=reg.R*OldPoints+reg.t
Cenker Canbulut
on 26 Jul 2020
Categories
Find more on Quaternion Math 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!
