Sign in to follow this  
fguihen

repesenting inifnity

Recommended Posts

im writing an algorithm to test if two lines intersect. its fine , except when a line is vertical ,and its m( slope) = infinity. this means that i have to scrap my algorithm. is there any way i can approximate infinity, so that i can keep my algorithm? i know infinity is..well infinity, nut worth asking

Share this post


Link to post
Share on other sites
What kind of precision are you using? Does your language have an "inf" built in? Is this in 2D or 3D? I guess for them to be parallel their slopes must be equal right? So assuming 2D couldnt you just have it be like
(assumign there exists Line.m = slope

bool 2dLineIntersect(Line L1,Line L2){
if(!(L1.m==L2.m))
{
REST OF ROUTINE
}

}

Share this post


Link to post
Share on other sites
Quote:
Original post by healeyx76
... I guess for them to be parallel their slopes must be equal right? ...

Parallel lines aren't the problem - it is vertical lines which are the problem, since they have an 'm' (slope) value of infinity.

Anyway, I'd agree with alvaro - represent the line with a point and a direction vector.

(and, have a look at Magic-Software.com, to see how they've done it - although, don't forget to read the license if you want to use that code itself, rather than using it to learn the relevant algorithms)

John B

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