Slick Forums

Discuss the Slick 2D Library
It is currently Sat Dec 07, 2019 4:58 pm

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Tue Nov 29, 2011 2:40 am 
Offline
User avatar

Joined: Fri Oct 07, 2011 11:05 pm
Posts: 97
Location: France, Nantes
Hi guys,

I don't know if this is intentional or not, but the dot(other) function on Vector2f doesn't take in consideration the angle between the vectors (cos(theta) is not involved), which is I believe a mistake in most cases.

See http://en.wikipedia.org/wiki/Dot_product ;)

_________________
"The Keeper is aware. The Keeper understands. The Keeper has seen the enemy."


Top
 Profile  
 
PostPosted: Thu Dec 15, 2011 7:39 pm 
Offline
User avatar

Joined: Fri Oct 07, 2011 11:05 pm
Posts: 97
Location: France, Nantes
Up: I just looked back at my college math lesson (damn these simple things you forgot with time) :mrgreen:

If the two vector aren't normalise, the result will be just wrong.

We should ensure something like that:
Code:
public float dot(Vector2f other) {

return (getNormal().x * other.getNormal().getX()) + (getNormal().y * other.getNormal().getY());
}

_________________
"The Keeper is aware. The Keeper understands. The Keeper has seen the enemy."


Top
 Profile  
 
PostPosted: Thu Dec 15, 2011 8:12 pm 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1242
That is a very stupid idea. For one it would be terrible slow, and not all use cases of a dot product are to compute an angle.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
PostPosted: Thu Dec 15, 2011 8:34 pm 
Offline
User avatar

Joined: Fri Oct 07, 2011 11:05 pm
Posts: 97
Location: France, Nantes
I don't get it: if you don't use a normal vector, the result will be just wrong...

plus, it wouldn't be "terrible slow": I think you really exaggerate it.

Anyway, you are right saying this would add some math, but saying
Quote:
not all use cases of a dot product are to compute an angle.
is not the right way to see things to my point of view, at least we'd better put a note saying " careful if you are not using normal vectors": I had wrong result because of that, not a big deal, but always good to know.

Or, if you don't want it angle related, well then don't call it a dot product.

_________________
"The Keeper is aware. The Keeper understands. The Keeper has seen the enemy."


Top
 Profile  
 
PostPosted: Fri Dec 16, 2011 7:07 am 
Offline
Slick Zombie

Joined: Fri Jan 29, 2010 7:02 pm
Posts: 1242
The dot product as currently implemented is correct. It is implemented the same way as in every other application - including tools like Matlab.

See for example this Google hit which nicely explains it.

_________________
TWL - The Themable Widget Library


Top
 Profile  
 
PostPosted: Fri Dec 16, 2011 7:53 am 
Offline
Game Developer

Joined: Sun Nov 12, 2006 11:18 pm
Posts: 890
Location: Germany
I agree with MatthiasM. IgoR, even your Google link says the same:
Quote:
In dimension 2, the dot product of vectors [a,b] and [c,d] is ac + bd. Similarly, in a dimension 3, the dot product of vectors [a,b,c] and [d,e,f] is ad + be + cf. For example, the dot product of two three-dimensional vectors [1, 3, −5] and [4, −2, −1] is
[1, 3, -5] o [4, -2, -1] = (1)(4) + (3)(-2) + (-5)(-1) = 4 - 6 + 5 = 3.


No normalization at all. The normalization is only used in the special case of Geometric Interpretation according to the Wiki entry.

_________________
Right Angle Games | Marte Engine
Back to the past | Star Cleaner | SpiderTrap


Top
 Profile  
 
PostPosted: Fri Dec 16, 2011 5:30 pm 
Offline
User avatar

Joined: Fri Oct 07, 2011 11:05 pm
Posts: 97
Location: France, Nantes
Oh I see, nevermind! I guess I have to work my basic math again ^^.

As I am only using it as a geometric tool, I didn't look at its general definition, sorry.

Anyway, I'll normalise it manually then, thanks guys!

_________________
"The Keeper is aware. The Keeper understands. The Keeper has seen the enemy."


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group