Calculating angle between neighboring vectors in vector field
Show older comments
I have a vector field reconstruction from some data. I have four matrices from this operation: X (contains X coordinate of vector head); Y (Y coordinate of vector head); U (vector mag in X direction); V (vector mag in Y direction).
For simplicity, let's say that I have four 4x4 matrices. Some of the values will be NaN, but consistently throughout all matrices. My goal is to, say, calculate the angle (I realize this is done by changing around dot product) and all neighboring vectors, and return this as a map. I can give a pictorial reference from a paper:
Distinct Timing Mechanisms Produce Discrete and Continuous Movements Raoul Huys mail, Breanna E. Studenka, Nicole L. Rheaume, Howard N. Zelaznik, Viktor K. Jirsa

In plot A or D, the vector reconstruction has been completed; I have made it this far. However, on plot 'C', it is essentially a mapping of the angles. I need help calculating the angles between the vectors, creating such a plot, and extracting all of the angles; obviously if I can get the angles, the plot isn't a problem. Any help is immensely appreciated. No luck so far.
Answers (1)
Roger Stafford
on 2 Aug 2013
I can tell you how to compute the angle between any two vectors in your vector field. I have no idea how you plan to depict such angle measures from vector pairs in maps such as you show in C and F.
Let u1 and v1 be the x and y components of one field vector and u2 and v2 those of another. The angle between them can be computed by
ang = atan2(abs(u1*v2-v1*u2),u1*u2+v1*v2);
This yields a value between 0 and pi radians, which is the inner angle you would have between the field vectors if their bases were moved so as to coincide. I have used the 'atan2' function here instead of 'acos' because of rounding error problems that occur with the latter for angles near 0 or pi.
1 Comment
Categories
Find more on Linear Algebra 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!