repesenting inifnity
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
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
}
}
(assumign there exists Line.m = slope
bool 2dLineIntersect(Line L1,Line L2){
if(!(L1.m==L2.m))
{
REST OF ROUTINE
}
}
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement