pouët.net

Go to bottom

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.
added on the 2016-11-23 02:00:27 by sigflup sigflup
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?
added on the 2016-11-23 02:28:31 by cxw cxw
Same origin. Maybe I'm not doing dot product right. A.B = (Ax * Bx) + (Ay * By)?
added on the 2016-11-23 02:30:51 by sigflup sigflup
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
added on the 2016-11-23 03:22:48 by cxw cxw
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 ?
added on the 2016-11-23 09:20:20 by Soundy Soundy
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
added on the 2016-11-23 09:25:02 by imerso imerso
Although Soundy is also right, no need to normalize if you just want the sign of the dot product.
added on the 2016-11-23 09:28:27 by imerso imerso
Well, this is what I did with it. theadesilva.com/fresh.mp4
added on the 2016-11-23 23:50:08 by sigflup sigflup
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?
added on the 2016-11-24 00:23:05 by kb_ kb_
(eh, "the guys" == Soundy, that's what you get from reading too fast...)
added on the 2016-11-24 00:23:47 by kb_ kb_
Looks pretty fresh! ;)
added on the 2016-11-24 01:57:01 by cxw cxw
@kb_:
Quote:
"the guys" == Soundy, that's what you get from reading too fast...
, 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!
added on the 2016-11-24 09:23:03 by Soundy Soundy
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. =)
added on the 2016-11-24 10:35:01 by imerso imerso
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.
added on the 2016-11-24 10:42:36 by imerso imerso
contrary to popular believe, sigflup is not a guy ;p
added on the 2016-11-24 10:44:54 by wysiwtf wysiwtf
nice. =)
added on the 2016-11-24 11:26:38 by imerso imerso
Fiiiine. Note: don't answer technical questions when too tired :/
added on the 2016-11-24 11:35:16 by kb_ kb_
Which side is zero-length vector facing though?

(disclaimer: totally kidding, just bored like the rest)
added on the 2016-11-24 22:40:53 by tomkh tomkh
Divide by zer*&&#*Illegal Instruction&*#()*@#&# NO CARRIER
added on the 2016-11-24 23:36:55 by imerso imerso
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 ;)
added on the 2016-11-25 00:51:11 by tomkh tomkh
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. =)
added on the 2016-11-25 00:53:26 by imerso imerso
http://mathinsight.org/zero_vector
added on the 2016-11-25 00:55:45 by imerso imerso
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 :)
added on the 2016-11-25 01:04:17 by tomkh tomkh

login

Go to top