• Advertisement
Sign in to follow this  

using linear algebra to solve intersections wont fully work

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

If you intended to correct an error in the post then please contact us.

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);
				yIntersect = ((ad*c2) - (ad2*c))/(det);

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

Share this post


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


Link to post
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
ah i see. so if i choose the end point, and my line runs co-linearly into another, then the end point will be used as the collision point. thanks. that sorts out a lot. thanks

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement