Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Angle between two vectors  (Read 1993 times)

0 Members and 1 Guest are viewing this topic.

lafoniz

  • Newbie
  • *
  • Posts: 19
    • View Profile
Angle between two vectors
« on: December 20, 2014, 11:29:51 pm »
I was reading a book and there was described a formula to calculate angle between two vectors, I tried to use it on paper but it didn't work for me (maybe I don't understand this correctly). Here is a brief description of it:

Quote
Let's say you have point A and point B,
which represent two characters in an action game. When the enemy at point A wants
to shoot our player at point B, it needs to know the direction in which to shoot the
projectile. Why waste your brains thinking on how to solve this problem if this field
of math defines this operation as one of its most basic rules? All you need is to find
the direction vector C, which is obtained by calculating B minus A. The difference
between two positions gives us the direction between the two

I need help with computing it, if this formula is okay, because I'm using this http://www.wikihow.com/Find-the-Angle-Between-Two-Vectors formula which seems to be worse for performance. Thanks for any kind of help :)

StormWingDelta

  • Sr. Member
  • ****
  • Posts: 365
    • View Profile
Re: Angle between two vectors
« Reply #1 on: December 20, 2014, 11:57:14 pm »
It's a basic math equation so if you've kept your math notes over the years or hunted around online it should be easy enough to find but here's two places that have the equation for it.

https://www.khanacademy.org/math/linear-algebra/vectors_and_spaces/dot_cross_products/v/defining-the-angle-between-vectors
http://www.euclideanspace.com/maths/algebra/vectors/angleBetween/


and the search: https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=math%20angle%20between%20two%20lines%20or%20vectors

Hope it helps.  Now if you're trying to convert it from the math that gets the end result to the math that is each frame than it is going to take a few more steps but from the sounds of it you only wanted the equation itself and yes this is as minimal as it gets unless someone can find a smaller version. :)
I have many ideas but need the help of others to find way to make use of them.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6286
  • Thor Developer
    • View Profile
    • Bromeon
Re: Angle between two vectors
« Reply #2 on: December 22, 2014, 07:06:07 am »
You can also use Thor.Vectors (see my signature).
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

 

anything