Hi all,
My problem is the following..I have a grid with about 8000 grid points. On one of those grid points, there's a 2 dimensional vector. I should now calculate the angle of every single gridpoint compared to the direction where the "master-vector" points. To know in which direction the angle is oriented, the results should be between -180° and 180°.
At the moment I make a vector for every gridpoint (endpoint-startpoint) and then tried several things with atan2 I found here, but had to find out that "dot" takes extremely long to calculate. The code should be as fast as possible, because I have to calculate those angle for all the 8000 gridpoints for 1020 "master-vectors".
Anybody of the experts an idea how I could speed up the process, or somebody knowing a completely different approach which could give me the result I'm looking for?
Thanks in advance! cheers, jip
|
|
0
|
|
|
|
Reply
|
Jip
|
10/19/2010 2:54:04 PM |
|
"Jip " <nonexistent@gmail.com> wrote in message <i9kbec$5dn$1@fred.mathworks.com>...
>
> At the moment I make a vector for every gridpoint (endpoint-startpoint) and then tried several things with atan2 I found here, but had to find out that "dot" takes extremely long to calculate. The code should be as fast as possible, because I have to calculate those angle for all the 8000 gridpoints for 1020 "master-vectors".
==============
The dot() and norm() operations can be replaced by calls to MTIMESX:
http://www.mathworks.com/matlabcentral/fileexchange/25977-mtimesx-fast-matrix-multiply-with-multi-dimensional-support
See also, this thread for a related discussion:
http://www.mathworks.com/matlabcentral/newsreader/view_thread/293747#787738
|
|
0
|
|
|
|
Reply
|
mattjacREMOVE (3177)
|
10/19/2010 4:17:04 PM
|
|
"Jip " <nonexistent@gmail.com> wrote in message <i9kbec$5dn$1@fred.mathworks.com>...
> Hi all,
>
> My problem is the following..I have a grid with about 8000 grid points. On one of those grid points, there's a 2 dimensional vector. I should now calculate the angle of every single gridpoint compared to the direction where the "master-vector" points. To know in which direction the angle is oriented, the results should be between -180° and 180°.
> At the moment I make a vector for every gridpoint (endpoint-startpoint) and then tried several things with atan2 I found here, but had to find out that "dot" takes extremely long to calculate. The code should be as fast as possible, because I have to calculate those angle for all the 8000 gridpoints for 1020 "master-vectors".
>
> Anybody of the experts an idea how I could speed up the process, or somebody knowing a completely different approach which could give me the result I'm looking for?
>
> Thanks in advance! cheers, jip
- - - - - - - - - - -
It's not quite clear what angle you are computing, whether an angle between vectors associated with two different grid points, or an angle between one "master vector" and the vector extending from that grid point to another grid point.
In any case your basic problem is to calculate the angle lying between -180 and +180 between two vectors, call them v1 = [v1x,v1y] and v2 = [v2x,v2y], however you arrive at them. The formula going positively from v1 toward v2, that I would normally recommend is:
ang = 180/pi*atan2( v1x*v2y-v1y*v2x , v1x*v2x+v1y*v2y );
If the answer to the question in the first paragraph above is that each grid point has an associated vector, it would be best to just calculate the angle between that vector [vx,vy] and, say, the x-axis, which would be:
angx = 180/pi*atan2(vy,vx)
Then the angle between any two vectors would be obtained by subtraction combined with a 'mod' operation. That is, if a and b are two x-axis angles, then the angle between them going positively from the first vector to the second is:
mod(b-a+180,360)-180;
which would be a fast operation.
If the answer above is to find the angle between master vectors and vectors pointing from the master points to other grid points, you could again calculate the angle between each master vector and the x-axis. To get the angle between every line connecting grid points and the x-axis is more laborious. However, you can take advantage of the inherent regularity in a grid arrangement. The x-axis angle for a vector from (x1,y1) to (x2,y2) grid points is the same as that from the different grid points (x1+h,y1+k) to (x2+h,y2+k), so there are far fewer combinations that need to be computed than taking every possible pairing.
Roger Stafford
|
|
0
|
|
|
|
Reply
|
Roger
|
10/19/2010 4:57:03 PM
|
|
|
2 Replies
361 Views
(page loaded in 0.055 seconds)
Similiar Articles: Re: fast angle calculation between 2D vectors - comp.soft-sys ...This function calculates angels between to groups of vectors function angle=Angle(vects1, vects2)%Unit vectors beam_dot=sum(vects1'.*vec... Is glRotate the same as axisAngle to quaternion to matrix? - comp ...Re: fast angle calculation between 2D vectors - comp.soft-sys ... Is glRotate the same as axisAngle to quaternion to matrix? - comp ... Re: fast angle calculation between ... angle between two vectors - comp.soft-sys.matlabRe: fast angle calculation between 2D vectors - comp.soft-sys ... This function calculates angels between to groups of vectors function angle=Angle(vects1, vects2)%Unit ... cross product between vector and array - comp.soft-sys.matlab ...Re: fast angle calculation between 2D vectors - comp.soft-sys ... This function calculates angels between to groups of vectors ... implementation angle = atan2(norm(cross ... angle between 2 lines on image - comp.soft-sys.matlabRe: fast angle calculation between 2D vectors - comp.soft-sys ... Q: How to Fade 2 images into each other? - comp ... top of each other, or how to take each line from a ... fast linear to log conversion algorithm? - comp.dspRe: fast angle calculation between 2D vectors - comp.soft-sys ..... between subspaces are fundamental notion in linear ... circle covering set of points - comp.graphics ... Shift matrix in y direction - comp.soft-sys.matlabRe: fast angle calculation between 2D vectors - comp.soft-sys ... On Feb 10, 1:05=A0am, "Jan Simon" <matlab.THIS_Y ... angle between the gradient and conjugate gradient ... rewrite glRotate? - comp.graphics.api.openglRe: fast angle calculation between 2D vectors - comp.soft-sys ... rewrite glRotate? - comp.graphics.api.opengl So from this angle the 256 bit wide (whatever you meant by ... Q: How to Fade 2 images into each other? - comp.graphics.apps.gimp ...Re: fast angle calculation between 2D vectors - comp.soft-sys ... Q: How to Fade 2 images into each other? - comp.graphics.apps.gimp ..... How do I do this in GIMP ... Poker hand evaluator - comp.lang.javascriptRe: fast angle calculation between 2D vectors - comp.soft-sys ... Poker hand evaluator - comp.lang.javascript But it sounds like you're looking for ... from 0 to 51, like ... fast angle calculation between 2D vectors - comp.soft-sys.matlab ...Hi all, My problem is the following..I have a grid with about 8000 grid points. On one of those grid points, there's a 2 dimensional vector. I should now calculate ... fast angle calculation between 2D vectors - Newsreader - MATLAB ...Hi all, My problem is the following..I have a grid with about 8000 grid points. On one of those grid points, there's a 2 dimensional vector. I should now calculate ... 7/20/2012 9:37:37 PM
|