• 11
• 9
• 10
• 9
• 10

# using linear algebra to solve intersections wont fully work

This topic is 4766 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

im using cramers rule to determin if two lines intersect. it all works fine until i get a line paralell. im using the double.Epsilon to try to get round this as shown below but its not working for some reason. any suggestions?
if(Math.Abs(det) < double.Epsilon)
{
//lines are paralell. check against epsilon values.
//				magnitude++;
//				if(magnitude > 4)
//				{
//					magnitude = 4;
//				}
xIntersect = ((bc2*c) - (bc*c2))/(det);

Vector intersection = new Vector((float)xIntersect,(float)yIntersect);

}


##### Share on other sites
I'm not sure what you are trying to solve here, but if two lines are parallel: trust me, they won't intersect. Solution: return false.

Greetz,

Illco

##### Share on other sites
Two parallel lines do intersect if they are colinear. But, this is a degenerate case and its a bad idea to be dividing by det when det < double.Epsilon. If they are colinear, there is an infinite # of intersection points, so you can't find just one. You need to think carefully about what is the appropriate way to handle this, for YOUR game, as its a case-by-case thing.

##### Share on other sites
i have thought about this, and if theres an infinite number of collision points, how do i find just one? i really have no idea on how to fix this one.

##### Share on other sites
As Graham said it depends on your particular needs and circumstances. In general the intersection of two colinear line segments is itself a line segment. If you only need a single point, you have to choose one from the infinite number possible. It could be the midpoint of the segment of intersection; or, it could be an endpoint from one segment that lies within the other. It's up to you.

I'm not sure what you're doing exactly, but for some situations it may be useful to have the intersection point be the point on the segment of intersection closest to the beginning of one of the segments. This would apply to, say, vision or a projectile such as a bullet.