matrix - Finding rotation between vectors in Matlab, from matrices of x and y components -


this question has answer here:

i trying find angle of rotation between 2 sets of vectors, each plotted using quiver() command. smaller angle between vectors.

for each set of vectors, passing 4 654x470 matrices quiver(), first 2 matrices x , y map positions, , second 2 matrices x-component , y-component magnitudes, respectively.

so have work x-component , y-component matrices each set of vectors. ultimately, resulting 654x470 matrix angle of rotation between 2 vectors @ each point.

i believe need solve theta in following:

cosθ = (u⃗ · v⃗) / (||u⃗|| ||v ⃗ ||)

but unsure how implement dot product, using 654x470 matrices of x , y components u , v.

this question unique in vectors 2d, , need computed x , y components.

if want angle between points, can implement angle formula in vectorized form.

% toy example data = rand(654,470); b = rand(654,470); c = rand(654,470); d = rand(654,470);  % create vector of vectors u = [a(:); b(:)]; v = [c(:); d(:)];  % declare euclidian norm function n = @(x) sum( sqrt( x .* x ) ); g = acos( dot( u, v ) ./ n( u ) ./ n( v ) );  % reshape original dimensions g = reshape( g, 654, [] ); 

first, vectorize a,b,c,d using (:) operator. function n performs norm calculation, first g use angle formula. second g calculation reshapes it's original dimensions.


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -