Jump to content

  • Log In with Google      Sign In   
  • Create Account

Intersection Point of two Vectors


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 Ntwiles   Members   -  Reputation: 144

Like
0Likes
Like

Posted 14 September 2013 - 02:14 AM

My math is very shaky, and I'm trying to use the following tutorial to get a grasp on vectors and collision detection/response:
 
http://www.tonypa.pri.ee/vectors/tut05.html
 
I've made an example and I'll just go through the process then explain my questions.
 

UJbpcuR.png

 
After some research, I've learned that the t value he's using is a factor in the parametric equation of a line (x,y)=(1-t)(x1,y1)+t(x2,y2). So I need to find the ratio t of vector a at which it intersects b. Then I'll add that to the starting position of a to get the point at which the two vectors intersect.
 
First I find c, which is the vector between the starting points of a and b. c = (-1,-4). I can then (apparently) solve for t using the ratio of the Dot Products of the normals of my vectors (Perp Product).

 

t = (c * b) / (a * b).
 
c*b = (4*6) + (-1*1) = 24 -1 = 23
a*b = (5*6) + (4*1) = 30 + 4 = 34
 
t = 23/34
 
a*t is (46/17,-115/34). Adding that to the starting point of a, I get (80/17,-55/34)  (4.7,1.6), which looks to be right.

 

I have all the steps down, but I'd like to get a better understanding of the math behind it. Specifically, there's a bit of a logical leap while solving for t. I don't understand how the Perp Product gets us the ratio we need to find the intersection point, or how the vector connecting the two starting points is involved. Any explanations on that or links to theorems explaining it would be really appreciated, as well as any corrections to my explanation. 



Sponsor:

#2 haegarr   Crossbones+   -  Reputation: 4604

Like
3Likes
Like

Posted 14 September 2013 - 02:55 AM

The vectors a and b are direction vectors. The intersection point is a, well, position vector. Direction vectors are just directions; they don't have a beginning, end, or any point in-between. You can calculate the length of a direction vector, and you can calculate the angle between 2 direction vectors (at least in 2D), but you cannot calculate their intersection point just because there is no concept like a position when looking at direction vectors.

 

On the other hand, a ray can be defined as

   r( t ) := p + t * d

where p denotes any point on the ray (obviously a position vector), d denotes the direction of the ray (obviously a direction vector), and t denotes the running parameter.

 

Accordingly to one of the rules dealing with positions and directions, namely

   position + direction => position

a ray denotes an infinitesimal amount of points (if d is not null).

 

So you have 2 rays, each one with its own running parameter

   r1( t1 ) := p1 + t1d1

   r2( t2 ) := p2 + t2d2

and you are interested in the point of intersection where
   r1( t1 ) = r2( t2

 

The above is a linear equation system with 2 equations in 2 variables t1 and t2, and hence can be solved the usual way:

   p1 + t1 * d1p2 + t2 * d2

<=> 

   p1 - p2 = t2 * d- t1 * d1

 

Using an abbreviation for the difference between the both origins of the rays

   c := p1 - p2

one gets the 2 scalar equations

   cx = t2 * d2x - t1 * d1x

   cy = t2 * d2y - t1 * d1y

 

Solving this for e.g. t1 gives

   cx * d2y - cy * d2x = t1 * ( d1y * d2x - d1x * d2y )

 

Comparing this with the working of the perpDot operator, one can see the correspondences, so that the above is the same as

   perpDot( c, d2 ) = t1 * perpDot( d1, d2 )


Edited by haegarr, 14 September 2013 - 02:55 AM.


#3 Ntwiles   Members   -  Reputation: 144

Like
0Likes
Like

Posted 14 September 2013 - 04:11 AM

Alright, so bear with me; I have a lot of knowledge gaps to fill in. Solving it algebraically like you set it up, I see there being two unknowns, t1 and t2, right?

p1 = (2,5)
p2 = (1,1)
d1 = (4,-5)
d2 = (6,1)

p1 + t1 * d1 = p2 + t2 * d2

 

So, plugging in the x values only, and solving for t1:

 

4t1 + 2  = 6t2 + 1

4t1 = 6t2 -1

t1 = 3/2t2 - 1/4 

 

I still need to get the value of either tor t2 to go any further, don't I?

 

 



#4 haegarr   Crossbones+   -  Reputation: 4604

Like
2Likes
Like

Posted 14 September 2013 - 04:34 AM

I still need to get the value of either t1 or t2 to go any further, don't I?

Yes. But notice that either t1 or t2 is identical to the t in your OP.

 

Solving a linear equation system means to look at all equations, and to use all other equations to eliminate all other unknowns until just 1 unknown is left. In your problem you have 2 equations in the system when you write down the vector equation as scalar equation. You also have 2 unknowns, namely t1 and t2. Assuming that the both equations are not linear dependent, they are sufficient to solve the problem.

 

Looking in particular at the equation system

   cx = t2 * d2x - t1 * d1x

   cy = t2 * d2y - t1 * d1y

 

Multiply e.g. the upper equation with d2y and the lower equation with d2x yields in

   cx * d2y = t2 * d2x * d2y - t1 * d1x * d2y

   cy * d2x = t2 * d2y * d2x - t1 * d1y * d2x

 
Now subtract the lower equation from the upper one yields in:
   ( cx * d2y ) - ( cy * d2x ) = ( t2 * d2x * d2y - t1 * d1x * d2y ) - ( t2 * d2y * d2x - t1 * d1y * d2x )
Dissolving the parenthesis:
   cx * d2y - cy * d2x = t2 * d2x * d2y - t1 * d1x * d2y - t2 * d2y * d2x + t1 * d1y * d2x
Reordering and factoring out the unknowns:
   cx * d2y - cy * d2x = t2 * ( d2x * d2y - d2y * d2x ) - t1 * ( d1x * d2y - d1y * d2x )
Neglecting the part with t2, because it is parenthesis term is always zero:
   cx * d2y - cy * d2x = - t1 * ( d1x * d2y - d1y * d2x )
Shifting the negation into the parenthesis:
   cx * d2y - cy * d2x = t1 * ( d1y * d2x - d1x * d2y )
 
So you have eliminated the 1 unknown by using the 2nd equation within the 1st one. Just 1 unknown is remaining, and it can be determined. An exception is of course if ( d1y * d2x - d1x * d2y ) computes zero. In this case the both directions d1 and d2 are parallel or else anti-parallel. In that case either none solution exists, or else the both rays are one upon the other and hence infinite many solutions exist. This exception is called "linear dependency".

 

Do you need to compute the 2nd unknown t2 as well? No, because of r1( t1 ) = r2( t2 ) means that you'd get the same point a second time.


Edited by haegarr, 14 September 2013 - 04:36 AM.


#5 Álvaro   Crossbones+   -  Reputation: 13935

Like
0Likes
Like

Posted 14 September 2013 - 07:19 AM

The vectors a and b are direction vectors. The intersection point is a, well, position vector. Direction vectors are just directions; they don't have a beginning, end, or any point in-between. You can calculate the length of a direction vector, and you can calculate the angle between 2 direction vectors (at least in 2D), but you cannot calculate their intersection point just because there is no concept like a position when looking at direction vectors.


Oh, boy. Sorry, the mathematician in me needs to make this paragraph more precise, even if nobody else cares.

There are vectors (what I think haegarr is calling "direction vectors") and there are points (what I think he's calling "position vectors"). Vectors don't have a beginning, end or any point in between. As long as you have a metric defined (if you don't know what this means, it doesn't matter, because you are probably thinking of Euclidean space, which comes with a metric), you can calculate the length of a vector and you can calculate the angle between 2 vectors (in any dimension), but you cannot calculate their intersection point.

But nothing in this problem really requires a metric, because it's a perfectly well defined affine problem, so we shouldn't have to talk about length and angle at all.

What the OP wants is to compute the intersection between two rays in 2D. A ray is specified by a starting point S and a vector d, and it is the set of all points of the form P = S + t*d, with t >= 0.

#6 Ntwiles   Members   -  Reputation: 144

Like
0Likes
Like

Posted 14 September 2013 - 02:58 PM

To be clear guys, the implementation I used above works, I'm just curious about how it works. Specifically the prep product. Are there any governing theorems that explain this property of prep products?

#7 Álvaro   Crossbones+   -  Reputation: 13935

Like
0Likes
Like

Posted 14 September 2013 - 07:15 PM

The standard name for that operation is determinant of a 2x2 matrix, whose columns are the two vectors. The solution of a system of linear equations as the ratio of two determinants is known as Cramer's rule.

Edited by Álvaro, 14 September 2013 - 07:19 PM.


#8 PeterStock   Members   -  Reputation: 396

Like
0Likes
Like

Posted 15 September 2013 - 12:09 PM

Sometimes I'm lazy and just skip to the answer rather than work it out myself. Here's a very good site about all sorts of geometry-related calculations:

 

http://paulbourke.net/geometry/

 

Add it to your bookmarks :)






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS