# repesenting inifnity

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

## 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 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 on other sites
Try representing a line by a point and a direction vector.

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

1. 1
2. 2
Rutin
21
3. 3
JoeJ
18
4. 4
5. 5
gaxio
12

• 14
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631724
• Total Posts
3001897
×