## vectors not facing one another.

**category:**code [glöplog]

Dearest lazy pouet,

What's a cheap way to tell when two vectors are not facing each other? Like a dot product with a negative side.

What's a cheap way to tell when two vectors are not facing each other? Like a dot product with a negative side.

Exactly that- negative dot product means angle>90°. Do you mean vectors *with different origins*, like to see if two characters can see each other?

Same origin. Maybe I'm not doing dot product right. A.B = (Ax * Bx) + (Ay * By)?

That's right. https://en.wikipedia.org/wiki/Dot_product

The positive/negative should work for any vector, but a.b =cos angle only if a and b both have length 1. A.b = |a| |b| cos theta

The positive/negative should work for any vector, but a.b =cos angle only if a and b both have length 1. A.b = |a| |b| cos theta

If they have the same origin:

- Well they can never "face" each other (unless being both null)

- Looking towards the same direction ==> A.B > 0

- Not looking towards the same direction ==> A.B < 0

You don't need to normalize your vectors or make them same length as you only care about the sign of A.B, not its absolute value. The output won't be the cos() itself (it will be the cos() scaled by the length of both vectors, but you don't care, doesn't change the sign).

As your dot product formula is fine, maybe you just made an error calculating your vectors X&Y ?

- Well they can never "face" each other (unless being both null)

- Looking towards the same direction ==> A.B > 0

- Not looking towards the same direction ==> A.B < 0

You don't need to normalize your vectors or make them same length as you only care about the sign of A.B, not its absolute value. The output won't be the cos() itself (it will be the cos() scaled by the length of both vectors, but you don't care, doesn't change the sign).

As your dot product formula is fine, maybe you just made an error calculating your vectors X&Y ?

As cxw said, make sure you normalize your vectors before doing the dot product. Here is one page with sample code for that: http://snipd.net/2d-and-3d-vector-normalization-and-angle-calculation-in-c

Although Soundy is also right, no need to normalize if you just want the sign of the dot product.

Well, this is what I did with it. theadesilva.com/fresh.mp4

Don't listen to the guys above, you don't need to normalize the vectors, the sign isn't affected by that :)

Also, if the vectors "start" somewhere else than (0,0,0) you need to subtract the origin from both vectors before taking the dot product. Maybe that's the problem?

Also, if the vectors "start" somewhere else than (0,0,0) you need to subtract the origin from both vectors before taking the dot product. Maybe that's the problem?

(eh, "the guys" == Soundy, that's what you get from reading too fast...)

Looks pretty fresh! ;)

@kb_: , you say don't listen to "the guys" and then "the guys" equal "Soundy", which means "don't listen to soundy", but I'm saying the same as you do. Damn, we reached an infinite loop. Is that what you get by writing too fast ;)

@sigflup: Nice! keep on!

**Quote:**

"the guys" == Soundy, that's what you get from reading too fast...

@sigflup: Nice! keep on!

If we read carefully, everyone said the same thing, maybe except me at first.

cxw first said "The positive/negative should work for any vector" which is correct.

Soundy said "You don't need to normalize your vectors or make them same length as you only care about the sign" which is correct.

The only guy who have suggested to normalize (have skipped the sign detail at first) was me, but even then I noticed that and also said "Soundy is correct, no need to normalize if you just want the sign". Anyway, if you normalize you get the right results, just spending a few unneeded cpu cycles.

So, ok, I am maybe the one to blame? I can live with that, no probs. =)

cxw first said "The positive/negative should work for any vector" which is correct.

Soundy said "You don't need to normalize your vectors or make them same length as you only care about the sign" which is correct.

The only guy who have suggested to normalize (have skipped the sign detail at first) was me, but even then I noticed that and also said "Soundy is correct, no need to normalize if you just want the sign". Anyway, if you normalize you get the right results, just spending a few unneeded cpu cycles.

So, ok, I am maybe the one to blame? I can live with that, no probs. =)

At first I just wanted to be clear that in the most common case, vectors are normalized before dot products -- the guy was even unsure if he was doing the dot product right, maybe he did not know that.

contrary to popular believe, sigflup is not a guy ;p

nice. =)

Fiiiine. Note: don't answer technical questions when too tired :/

Which side is zero-length vector facing though?

(disclaimer: totally kidding, just bored like the rest)

(disclaimer: totally kidding, just bored like the rest)

Divide by zer*&&#*Illegal Instruction&*#()*@#&# NO CARRIER

imerso: what? you at normalization again? :) There is no division involved ;)

The correct answer is: it points at every direction with zero magnitude

(because it is orthogonal to every vector according to Hoyle).

And yes, I'm so smart lol ;)

The correct answer is: it points at every direction with zero magnitude

(because it is orthogonal to every vector according to Hoyle).

And yes, I'm so smart lol ;)

I was being sarcastic, should have added that it is commonly considered to point into all directions -- although it has, in reality, undefined direction imho.

Yes, you're so smart. =)

Yes, you're so smart. =)

http://mathinsight.org/zero_vector

http://mathinsight.org/zero_vector

</spam> =)

</spam> =)

imerso, I was actually double-sarcastic, so it's even more confusing than sarcastic, because it's like sarcasm, but with no indication at all. It is sometimes confused with trolling, but it is really not :)

It's just reminded me of old sci.math.* or other math forums fights over petty issues like this = good times :)

It's just reminded me of old sci.math.* or other math forums fights over petty issues like this = good times :)