• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
ntwiles

Intersection Point of two Vectors

7 posts in this topic

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. 

0

Share this post


Link to post
Share on other sites

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?

 

 

0

Share this post


Link to post
Share on other sites
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
2

Share this post


Link to post
Share on other sites

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.
0

Share this post


Link to post
Share on other sites
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?
0

Share this post


Link to post
Share on other sites
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
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0