# How to find the difference between angles of two complex numbers

• May 21st 2013, 07:23 AM
ashokec
How to find the difference between angles of two complex numbers
Hi
I have two vectors represented as complex numbers and need to calculate angle between in most efficient way.
This is for implementing in C.
If I use tan-1 to take angles of both and subtract it will take a lot of processing power.
So, please suggest me an efficient method for this.

Thanks and Regards
Ashok
• May 21st 2013, 02:31 PM
chalaman1403
Re: How to find the difference between angles of two complex numbers
Ashok, I assume you are using rectangular coordinates, this is $V_1 = (x_1,y_1)$ and $V_2 = (x_2,y_2)$ it doesn't really matter that they are complex numbers. Remember dot product $V_1*V_2 = |V_1||V_2|cos(\theta)$ where $\theta$ is the smallest angle between them, so it is always true that $|\theta| .
So you can use $\theta = \arccos(\frac{V_1*V_2}{|V_1||V_2|})$. You still need to find the dot product, that is just $x_1*x_2 +y_1*y_2$ and the length of the vectors, that is
$|V_i |= \sqrt{x_i^2+y_i^2}$ so I'm not sure how much memory you are saving with this. And this will give you the smallest angle, that may not be what you need, I don't know.
I advice you look up some math library for c, I'm sure there is an "arg" function implemented that gives you the angles, if you don't want to use that, you can look at the code (if it is accessible) and
get a better idea. I hope that helped, regards
Damián Vallejo.
You can visit my blog if you want, it is Math 911 I expose some math topics there.
• May 21st 2013, 02:37 PM
emakarov
Re: How to find the difference between angles of two complex numbers
But the problem of finding $\tan^{-1}$ is reducible to the problem of finding the angle between two vectors: given y, $\tan^{-1}(y)$ is the angle between (1, y) and (1, 0). Therefore, the problem of finding the angle is at least as hard as the problem of computing the $\tan^{-1}$.

From the standpoint of good programming practices, it is probably good to use a library dealing with complex numbers. It must have a function returning the argument of a given complex number (internally, this function is likely to use $\tan^{-1}$ or some other inverse trigonometric function).

On the other hand, if the angle between vectors is not your ultimate goal (for example, if you are taking its tangent), then there may be ways to avoid computing $\tan^{-1}$ or a similar function.
• May 22nd 2013, 12:09 AM
ashokec
Re: How to find the difference between angles of two complex numbers
Hi
the the cos method gives the difference but it won't give the direction, I mean it won't give negative values.
standard Library functions are less efficient for me.

Actually I have one more step after this, shifting the phase of second vector based on the angle difference
Is there any method to do these steps together ? (with least complexity , so best timing efficiency)

Regards

Quote:

Originally Posted by chalaman1403
Ashok, I assume you are using rectangular coordinates, this is $V_1 = (x_1,y_1)$ and $V_2 = (x_2,y_2)$ it doesn't really matter that they are complex numbers. Remember dot product $V_1*V_2 = |V_1||V_2|cos(\theta)$ where $\theta$ is the smallest angle between them, so it is always true that $|\theta| .
So you can use $\theta = \arccos(\frac{V_1*V_2}{|V_1||V_2|})$. You still need to find the dot product, that is just $x_1*x_2 +y_1*y_2$ and the length of the vectors, that is
$|V_i |= \sqrt{x_i^2+y_i^2}$ so I'm not sure how much memory you are saving with this. And this will give you the smallest angle, that may not be what you need, I don't know.
I advice you look up some math library for c, I'm sure there is an "arg" function implemented that gives you the angles, if you don't want to use that, you can look at the code (if it is accessible) and
get a better idea. I hope that helped, regards
Damián Vallejo.
You can visit my blog if you want, it is Math 911 I expose some math topics there.

• May 22nd 2013, 12:13 AM
ashokec
Re: How to find the difference between angles of two complex numbers
Hi
The tan inverse method is better. But it has not helped me to reach my ultimate goal within my processing time constraint.
As you guessed my ultimate goal is different :)

Actually I have one more step after this, shifting the phase of second vector based on the angle difference
Is there any method to do these steps together ? (with least complexity , so best timing efficiency)

Thanks and Regards

Quote:

Originally Posted by emakarov
But the problem of finding $\tan^{-1}$ is reducible to the problem of finding the angle between two vectors: given y, $\tan^{-1}(y)$ is the angle between (1, y) and (1, 0). Therefore, the problem of finding the angle is at least as hard as the problem of computing the $\tan^{-1}$.

From the standpoint of good programming practices, it is probably good to use a library dealing with complex numbers. It must have a function returning the argument of a given complex number (internally, this function is likely to use $\tan^{-1}$ or some other inverse trigonometric function).

On the other hand, if the angle between vectors is not your ultimate goal (for example, if you are taking its tangent), then there may be ways to avoid computing $\tan^{-1}$ or a similar function.