Jump to content

  • Log In with Google      Sign In   
  • Create Account


Help solving linear equations


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 PrestoChung   Members   -  Reputation: 177

Like
0Likes
Like

Posted 01 August 2011 - 01:58 PM

Hi I'm trying to implement a fast triangle-triangle intersection algorithm (Tropp06,PDF)


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:
-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

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.

Sponsor:

#2 Zipster   Crossbones+   -  Reputation: 585

Like
1Likes
Like

Posted 02 August 2011 - 05:29 AM

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

#3 PrestoChung   Members   -  Reputation: 177

Like
0Likes
Like

Posted 03 August 2011 - 05:10 AM

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


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: http://www.jimloy.com/algebra/determin.htm


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

#4 Zipster   Crossbones+   -  Reputation: 585

Like
0Likes
Like

Posted 04 August 2011 - 04:07 AM


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


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: http://www.jimloy.co...ra/determin.htm


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

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 close 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 best solvable system (if there is one).

#5 Emergent   Members   -  Reputation: 971

Like
0Likes
Like

Posted 04 August 2011 - 09:01 AM

You have a linear system

A x = b

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

AT A x = AT b .

The 2x2 matrix G = AT A is called the Grammian 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 is 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.

#6 Zipster   Crossbones+   -  Reputation: 585

Like
0Likes
Like

Posted 04 August 2011 - 12:03 PM

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.

#7 luca-deltodesco   Members   -  Reputation: 637

Like
0Likes
Like

Posted 04 August 2011 - 12:07 PM

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

#8 PrestoChung   Members   -  Reputation: 177

Like
0Likes
Like

Posted 08 August 2011 - 01:00 AM

Thanks, guys.

I must have fudged my algebra somewhere.

P + d p = T + g t
d p + g(-t) = T - P

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




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