Relative orientation of two vectors

Click For Summary
SUMMARY

This discussion focuses on determining the relative orientation of two vectors in a 2D plane, specifically whether two objects are facing each other based on their angles. The inner product is identified as a key mathematical tool for this analysis, with the formula cos(α) = (v·w) / (||v|| ||w||) being central to calculating the cosine of the angle between vectors. The conversation highlights the need for a method to quantify how much two objects are facing each other, suggesting a formula X = (180 - |α - β|) / 180 as a starting point. The importance of defining "facing" is emphasized to refine the approach further.

PREREQUISITES
  • Understanding of vector mathematics, specifically inner products
  • Familiarity with trigonometric functions, particularly cosine
  • Basic knowledge of 2D coordinate systems
  • Concept of angles and their representation in radians or degrees
NEXT STEPS
  • Research the application of the dot product in computer vision problems
  • Explore methods for defining and quantifying "facing" in vector mathematics
  • Learn about vector normalization and its impact on angle calculations
  • Investigate the use of distance metrics in determining object orientation
USEFUL FOR

Mathematicians, computer vision engineers, game developers, and anyone involved in physics simulations requiring vector orientation analysis.

xonxt
Messages
3
Reaction score
0
Hello. I'm sorry if this is a really trivial question, but I'm not that good with vector arithmetics, so I have to ask.

Let's say I have two objects on a 2D plane, that face some direction. I have (x,y) coordinates of each object, and I have an angle each object is facing. The relative coordinates are not important to me, what I need to find out, is if the objects are facing each other, and to compute some parameter X which, for lack of better terms, tells me how "much" are they facing each other. A relative angle, if you wish.
Here's an illustration of what I need, approximately:
1373921244-new-canvas-83kb.png


Does a thing like that exist, or do I need to invent it? :D
 
Mathematics news on Phys.org
The inner product should be what you're looking for.

Given two vectors ##\mathbf{v}## and ##\mathbf{w}## (both emanating from the origin). Then you have

\cos(\alpha) = \frac{\mathbf{v}\cdot \mathbf{w}}{\|\mathbf{v}\|\|\mathbf{w}\|}

For example, given ##\mathbf{v} = (1,2,3)## and ##\mathbf{w} = (5,1,2)##, then

\mathbf{v}\cdot \mathbf{w} = 1\cdot 5 + 2\cdot 1 + 3\cdot 2 = 13

Thus

\cos(\alpha) = \frac{13}{\sqrt{14}\sqrt{30}}

For more information, see "Introduction to Linear Algebra" by Serge Lang.
 
The example you show is confusing. For all your cases the vectors are in opposite direction.
 
mathman said:
The example you show is confusing. For all your cases the vectors are in opposite direction.
Well, maybe I phrased it wrong. Would it help, if I told you that it is a computer vision problem. I have computed the angle two objects are facing, now I need know if these two objects are facing towards or away from each other?

micromass said:
The inner product should be what you're looking for.
I was thinking of something more simple. First of all, I son't have vector coordinates, I only have angles.
Secondly, I thought along the lines of something like this:

X = \frac{180 - |\alpha - \beta|}{180}

I will only get a X = [0; 1] that way, but it's a start.
 
\cos(\alpha - \beta) is 1 when they are in the same direction and -1 when they are in opposite direction. When they are somewhat in the same direction it is smaller than 1 but still positive (the smaller the less they are in the same direction) and when they are somewhat in the opposite direction it is larger than -1 but still negative. So, for what you want you could use -\cos(\alpha - \beta)
 
gerben said:
\cos(\alpha - \beta) is 1 when they are in the same direction and -1 when they are in opposite direction. When they are somewhat in the same direction it is smaller than 1 but still positive (the smaller the less they are in the same direction) and when they are somewhat in the opposite direction it is larger than -1 but still negative. So, for what you want you could use -\cos(\alpha - \beta)

Well, that's almost what I'm looking for. The only downside is with that I can only determine if both vectors are directed somewhat along one line, but it doesn't show me if they are facing inwards or outwards.
Basically here is what we get. Cases A and B are similar and we don't get any information whether they're facing each other or not:
1373926137-clip-33kb.jpg
 
The way you drew it case A and case B are the same, (about) the same angle alpha and beta (alpha around 200 degrees and beta around 45 degrees) and since they are somewhat opposite you get a positive number. In case C you will also get a positive number, it is about -cos(100 - 250)
 
Maybe start with the easier problem of determining if one of the objects is facing the other. Also, you might want to think about precisely defining "facing", keeping in mind that you'd like to permit different degrees of "facing". Sometimes writing down exactly what you're trying to do leads to a fairly obvious solution. If you can define what you mean by "A is facing B", then "A and B are facing each other" should mean "A is facing B and B is facing A", right?
 
I find using dot product most convenient but it's up to you. If the object is facing each other exactly then their dot product will be -1.

Using distance method to decide if they're facing opposite each other or face-to-face: Imagine there's a point on the object face vector. Calculate the distance between that point with the second object face vector point. If they're facing outward, then the distance between those two points will be larger then the relative distance between the center of the objects. If they're facing inwards the distance will be less than it.

PxZFUlu.png
 

Similar threads

  • · Replies 23 ·
Replies
23
Views
2K
  • · Replies 13 ·
Replies
13
Views
2K
Replies
1
Views
2K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 20 ·
Replies
20
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 6 ·
Replies
6
Views
1K