I can't really wrap my brain around infinity. But more importantly, my program can't either. I have this line segment class that just goes something like this:
You can probably already see the problem. Yep. Slope. Vertical lines. Blowin' my programs mind. Indeterminate -1.#IND00. The thing is, I kind of need to know the slope, because I kinda determined these equations to figure out the points of intersections.Code:class CLineSegment { public: CLineSegment( const CPoint & start, const CPoint & end ); CLineSegment( double tx, double ty, double rx, double ry ); ~CLineSegment( void ); void setStart( const CPoint & start ); void setEnd( const CPoint & end ); const CPoint & getStart( void ) const; const CPoint & getEnd( void ) const; bool intersects( const CLineSegment & other ); bool operator == ( const CLineSegment & other ); private: CPoint m_start, m_end; double m_slope; };
Of course, I dealt with the special cases of things being paralell and being the same to avoid divide by 0's in these equations, but I can't think of a way to test for the verticals. Is it bad to leave that indeterminate form in? Can I check for it or something and then make a special case?Code:y - ya = ma * ( x - xa ) y - yb = mb * ( x - xb ) x = ( yb - ya - mb * xb + ma * xa ) / ( ma - mb ) y = ( mb * ya - mb * yb + ma * mb * ( xb - xa ) ) / ( mb - ma )



LinkBack URL
About LinkBacks


