• 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
PrestoChung

Help solving linear equations

7 posts in this topic

Hi I'm trying to implement a fast triangle-triangle intersection algorithm (Tropp06,[url="http://news.xinhuanet.com/english2010/china/2011-07/30/c_131018764.htm"]PDF[/url])


In Stage 4 of the paper I have found the line of intersection between the plane of triangle B and triangle A, this a vector t emenating from a point T.
The edge of B that I'm looking for intersection with is defined as a point in B, P plus an edge vector p.

So the equation as given in the paper is of the from
P + d p = T + g t
where d and g are scalar multiples of the vectors p and t.

P,p,T and t are all known. d and g are the unknown scalars I need to solve for.

The goal here is to save operations and avoid using divides. The paper also hints at using determinants to save calculations.
The result is a point where the line T+t and P+p cross.

I re-write the equation to look like this -d p + g t = (P-T) in an attempt to make it look more like what I find in linear algebra texts.
I look at this as a series of 3 equations of 2 variables. Something like:
[code]-d * p.x + g * t.x = (P-T).x
-d * p.y + g * t.y = (P-T).y
-d * p.z + g * t.z = (P-T).z[/code]

Now, all the examples I can find show how to solve for 3 equations and 3 variables, or 2 equations and 2 variables, not 3 equations and 2 variables.
Also, the paper says that since the vectors lie in the same plane "2 x 2 equations sets are solved".

Thanks to anyone who can help with this.
0

Share this post


Link to post
Share on other sites
Knowing that the vectors lie on the same plane allows you to ignore one of the equations and solve a 2x2 linear system instead. The rule of thumb is usually to take the cross product of 'p' and 't', determine the component with the largest magnitude, and throw away the equation whose coefficients are that component (i.e. if (p x t).y has the largest magnitude, throw out the middle equation in your system). The purpose of that approach is to leave you with the most stable 2x2 system that has a solution (if there is one to begin with).
1

Share this post


Link to post
Share on other sites
[quote name='Zipster' timestamp='1312284574' post='4843508']
Knowing that the vectors lie on the same plane allows you to ignore one of the equations and solve a 2x2 linear system instead. The rule of thumb is usually to take the cross product of 'p' and 't', determine the component with the largest magnitude, and throw away the equation whose coefficients are that component (i.e. if (p x t).y has the largest magnitude, throw out the middle equation in your system). The purpose of that approach is to leave you with the most stable 2x2 system that has a solution (if there is one to begin with).
[/quote]

Thank you this is helpful. I'm not sure what you mean by 'stable'? Perhaps I will have problems in floating point accuracy if the plane is in a certain orientation? I intend to solve using determinants according to the example here: [url="http://www.jimloy.com/algebra/determin.htm"]http://www.jimloy.com/algebra/determin.htm[/url]


It looks like if there is no solution the denominator of one of the determinants is 0.
0

Share this post


Link to post
Share on other sites
[quote name='PrestoChung' timestamp='1312369801' post='4844001']
[quote name='Zipster' timestamp='1312284574' post='4843508']
Knowing that the vectors lie on the same plane allows you to ignore one of the equations and solve a 2x2 linear system instead. The rule of thumb is usually to take the cross product of 'p' and 't', determine the component with the largest magnitude, and throw away the equation whose coefficients are that component (i.e. if (p x t).y has the largest magnitude, throw out the middle equation in your system). The purpose of that approach is to leave you with the most stable 2x2 system that has a solution (if there is one to begin with).
[/quote]

Thank you this is helpful. I'm not sure what you mean by 'stable'? Perhaps I will have problems in floating point accuracy if the plane is in a certain orientation? I intend to solve using determinants according to the example here: [url="http://www.jimloy.com/algebra/determin.htm"]http://www.jimloy.co...ra/determin.htm[/url]


It looks like if there is no solution the denominator of one of the determinants is 0.
[/quote]
Yes, you can't just throw out any equation at random because it's possible you'll get a denominator of 0 when you attempt to solve the remaining equations, however at the same time a denominator that's extremely [i]close[/i] to 0 might not behave very well either, depending on your available range and precision. So as long as you have to check for a solvable system anyway, might as well choose the [i]best[/i] solvable system (if there is one).
0

Share this post


Link to post
Share on other sites
You have a linear system

A x = b

where A is 3x2, x is 2x1, and b is 3x1. Instead you can solve,

A[sup]T[/sup] A x = A[sup]T[/sup] b .

The 2x2 matrix G = A[sup]T[/sup] A is called the [i]Grammian [/i]of the columns of A. It's a matrix of dot products, and it will be invertible so long as the columns of A are linearly independent. This will give you a least-squares solution. I.e., if there is no x such that A x = b, it'll give you an x that minimizes ||A x - b||. But of course, if there [i]is [/i]a solution, that's what you get.

This approach has the advantage of not requiring branches to choose which set of equations to solve. It has the disadvantage of involving a bunch of multiplies to compute G.

What's fastest? I don't know.
0

Share this post


Link to post
Share on other sites
Yes, I intentionally omitted the projection approach because it felt a little too advanced if you don't already understand linear systems :) However, it will work, as long as you know beforehand that your vectors are coplanar, or else |Ax - b| will be greater than 0 and the solution won't actually be an intersection.
0

Share this post


Link to post
Share on other sites
well you could argue that solving the least squares problem is actually more accurate; since with numerical precision 'coplanar' lines will probably not 'actually' be coplanar, so the least squares solution should be closer to the ideal solution than dropping a dimension and solving in 2D assuming they are 100% coplanar :P
0

Share this post


Link to post
Share on other sites
Thanks, guys.

I must have fudged my algebra somewhere.

[color=#1C2837][size=2]P + d p = T + g t[/size][/color]
[color=#1C2837][size=2]d p + g(-t) = T - P[/size][/color]

Does that look right?
I"m solving for scalars d and g. The x,y(or z) component of vectors p and t, and the point (T-P) are the 'constant' factors in Cramers rule.
So d = |Ad|/|A|.
And this part comes out correct in my calculations.
But for some reason i'm getting g = 1+|Ag|/|A|

I thought it might have been because I attached the 'negative' sign to the -t vector? But if that was the case I would think d would come out wrong because it shares the same denominator with g, namely
A=
| p.x -t.x |
| p.y -t.y |
while the matrix in the numerator of g doesn't involve -t at all. That is
Ag=
| p.x (T-P).x |
| p.y (T-P).y |

At least when I plug in 1+|Ag|/|A| for g I get the same point as when I plug in the proper d, but it does confuse me that the form doesn't match what I've seen for Cramer's rule.

Thanks to all for the help on this one
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