What is the signed angle between two 2-dimensional vectors?

In summary, per Dave, if you cosine (the dot product) is positive you can tell the angle is in the first or third quadrant. If the sine (the wedge product part of the vector product) is positive you know the angle is in the first or second quadrant. However, if you cosine is negative then you can't determine the angle.
  • #1
daviddoria
97
0
The following discussion is in 2 dimensions:

Take two vectors, A and B. Generally we find the angle (theta) between them by
cos(theta) = dot(A,B) / (norm(A) * norm(B))

however, take vector A to be [0, 1] (straight up)

If vector B is [1,1], the angle between them is pi/4 radians. If vector B is [-1, 1], the angle between them is STILL pi/4 radians!

I need to know the signed angle between them (one of the B's above should be -pi/4, the other, pi/4). How would I do that?

Thanks!

Dave
 
Physics news on Phys.org
  • #2
daviddoria said:
The following discussion is in 2 dimensions:

Take two vectors, A and B. Generally we find the angle (theta) between them by
cos(theta) = dot(A,B) / (norm(A) * norm(B))

however, take vector A to be [0, 1] (straight up)

If vector B is [1,1], the angle between them is pi/4 radians. If vector B is [-1, 1], the angle between them is STILL pi/4 radians!

I need to know the signed angle between them (one of the B's above should be -pi/4, the other, pi/4). How would I do that?

Thanks!

Dave

Well, such a signed angle measure would have to be assymmetric in its arguments. I.e., angle(A,B) = -1*angle(B,A), right?

More generally, it seems that you'd need some kind of convention to specify which vector is the "reference" vector. In your above example, A played this role. So, supposing we make the first vector in the argument the reference, how would we go about getting a signed angle? Presumably we still want to normalize by the norms of the vectors in question, but then it follows that we need to change the dot product. Can you think of a way to modify it to reflect sign?
 
  • #3
No problem choosing a reference angle. I saw something called the "perp dot product" which rotated one vector pi/2 (we'll say C=(A rotated by pi/2) and then said
sin(theta) = dot(C,A)/(norm(A)*norm(C))

I tried this and I still was getting positive numbers both ways (unless I did something wrong - maybe rotated A the wrong way?)

Any other thoughts?

David
 
  • #4
daviddoria said:
No problem choosing a reference angle. I saw something called the "perp dot product" which rotated one vector pi/2 (we'll say C=(A rotated by pi/2) and then said
sin(theta) = dot(C,A)/(norm(A)*norm(C))

I tried this and I still was getting positive numbers both ways (unless I did something wrong - maybe rotated A the wrong way?)

Any other thoughts?

David


That looks to just be the regular cosine applied to a vector that's been rotated ahead of time. And, yeah, since the regular cosine gives you positive angles, this will too.

How about this: first, compute the usual cosine between A and B, and call this [itex]\theta[/itex]. Suppose A is the reference vector, and suppose that a counter-clockwise rotations are "positive" (i.e., the right hand rule). Now, the usual cosine has given you the magnitude of the angle between A and B, but not its sign. You can determine the sign by applying a rotation of [itex]-\theta[/itex] to B and seeing if you end up parallel to A. If so, you know the sign was positive. If not, you know the sign was negative.
 
  • #5
Since you only want an answer for R^2, use a complex polar representation:

[tex]
\hat{b} = \hat{a} \exp(i\theta)
[/tex]

[tex]
\theta = -i \ln(\hat{b}/\hat{a})
[/tex]

EDITed: forgot to write the hats above (ie: scale by length first just as with the typical cosine formula).
 
Last edited:
  • #6
quadraphonics: it seems like there may be some numerical error in check if the resulting rotated vector is parallel to the original vector. And you may also run into a case where the two vectors are originally perpendicular, so then no matter which way you rotate one of them they end up parallel...

Peeter, I don't understand - theta seems to be a complex number, how does this tell me the signed angle?
 
  • #7
theta's real in this case. The log of the quotient isn't, and that's why the -i factor is needed. Without loss of generality (since you can scale), for two unit vectors you have:

[tex]
\bar{a}b = (a_1 b_1 + a_2 b_2) + i (a_1 b_2 - a_2 b_1) = \cos(\theta) + i\sin(\theta)
[/tex]

Roughly speaking, if you cosine (the dot product) is positive you can tell the angle is in the first or third quadrant. If the sine (the wedge product part of the vector product) is positive you know the angle is in the first or second quadrant.

Using just [tex]\cos(\theta) = a \cdot b[/tex], you have really tossed half of the product information. In complex numbers, the log gives you both parts of the info to determine the angle appropriately (up to a factor of [tex]2 \pi n[/tex]).

A good treatment of this can be found in the Hestenes book "New foundations for Classical Mechanics". He treats the general case for vectors of dimension >=2, but for R^2 the ideas all reduce to classical complex variables.
 
  • #8
daviddoria said:
quadraphonics: it seems like there may be some numerical error in check if the resulting rotated vector is parallel to the original vector. And you may also run into a case where the two vectors are originally perpendicular, so then no matter which way you rotate one of them they end up parallel...

Well, what I meant by 'check if they're parallel' was actually 'check that [itex]A^TB=|A||B|[/itex].'
 
  • #9
quadraphonics - if I'm not mistaken A'B will only equal |A||B| if theta is exactly equal 0 (because then cos(theta) = 1) - there will still be some numerical error?

peeter- i'll take a look at doing it using actual complex numbers tomorrow
 
  • #10
fyi. The following two wikipedia article's look like they spell out the angle conversion if you don't have an arg() function handy:

http://en.wikipedia.org/wiki/Arg_(mathematics)

http://en.wikipedia.org/wiki/Atan2

I tried on my hand calculator with a = (3,1) and b=(2,-2) and [tex]arg(\sqrt{(10/8) }((2,2)/(3,1)))[/tex] gives -63 degrees for the angle from a to b, which looks about right by eye.
 
  • #11
daviddoria said:
quadraphonics - if I'm not mistaken A'B will only equal |A||B| if theta is exactly equal 0 (because then cos(theta) = 1) - there will still be some numerical error?

There's going to be numerical error in any finite-precision computation. You just make sure to use enough precision that you can ignore it. I'm not sure what your point is here.
 
  • #12
my point is that if you have a function that gives the signed angle and it has a precision error the angle should be 60 but it is really 59.9999 that is no problem, but if you have a conditional statement, to say
if (Rotated Vector B is parallel to Vector A)

and that comparison had an error, then you're in big trouble

of course you could fix it by saying

if (Angle between A and Rotated B is < epsilon) where epsilon is .0001 or something

but that seems very "not nice" haha

peteer - thanks for the links

everyone - i appreciate it - i got it working!

~Dave
 
  • #13
daviddoria said:
my point is that if you have a function that gives the signed angle and it has a precision error the angle should be 60 but it is really 59.9999 that is no problem, but if you have a conditional statement, to say
if (Rotated Vector B is parallel to Vector A)

and that comparison had an error, then you're in big trouble

of course you could fix it by saying

if (Angle between A and Rotated B is < epsilon) where epsilon is .0001 or something

but that seems very "not nice" haha

Well, if 59.9999 is close enough to 60 for you, then I see no reason why 0.0001 shouldn't be close enough to 0.

More generally, though, maybe you can avoid this issue. That is, you try applying the positive and negative rotations to one of the vectors. One is going to make it more parallel, and the other is going to make it less parallel (or, equivalently, more anti-parallel). So, you don't have to check that it's *exactly* parallel (even though it should theoretically be so), but just confirm that the other possible rotation made it *less* parallel. What I mean is that for any non-zero angle [itex]\theta[/itex], when you rotate one of the vectors by that angle, the inner-product between the result and the other original vector is going to either increase or decrease. That it should come out to 0 for one of the rotations doesn't really matter; you just pick the sign such that you get an increase in the resulting inner product.
 

1. What is the signed angle between vectors?

The signed angle between vectors is the measure of the angle formed between two vectors in a specific direction. It takes into account the direction of rotation from one vector to another.

2. How is the signed angle between vectors calculated?

The signed angle between vectors can be calculated using the dot product formula: cosθ = (a · b) / (|a| * |b|), where a and b are the two vectors in consideration. The arccosine of the result will give the signed angle between the vectors.

3. What is the difference between a signed angle and an unsigned angle?

A signed angle takes into account the direction of rotation, while an unsigned angle does not. This means that a signed angle can be positive or negative, indicating a clockwise or counterclockwise rotation, while an unsigned angle is always positive.

4. Why is the signed angle between vectors important?

The signed angle between vectors is important in many fields, such as physics, engineering, and computer graphics. It allows for a more accurate representation of the relationship between two vectors, taking into account both magnitude and direction.

5. Can the signed angle between vectors be greater than 180 degrees?

Yes, the signed angle between vectors can be greater than 180 degrees. This indicates that the vectors are in opposite directions and have a larger angle between them than 180 degrees. In this case, the signed angle would be negative to indicate the direction of rotation.

Similar threads

  • Linear and Abstract Algebra
Replies
14
Views
642
  • Linear and Abstract Algebra
Replies
5
Views
985
  • Linear and Abstract Algebra
Replies
1
Views
921
  • Linear and Abstract Algebra
Replies
9
Views
572
  • Linear and Abstract Algebra
Replies
3
Views
981
  • Linear and Abstract Algebra
Replies
12
Views
3K
Replies
9
Views
1K
  • Linear and Abstract Algebra
Replies
13
Views
514
Replies
3
Views
1K
  • Linear and Abstract Algebra
Replies
8
Views
1K
Back
Top