public static LineSegment2D_F32 convert ( LineParametric2D_F32 l , int width , int height ) { double t0 = ( 0 - l . p . x ) / l . getSlopeX ( ) ; double t1 = ( 0 - l . p . y ) / l . getSlopeY ( ) ; double t2 = ( width - l . p . x ) / l . getSlopeX ( ) ; double t3 = ( height - l . p . y ) / l . getSlopeY ( ) ; Point2D_F32 a = computePoint ( l , t0 ) ; Point2D_F32 b = computePoint ( l , t1 ) ; Point2D_F32 c = computePoint ( l , t2 ) ; Point2D_F32 d = computePoint ( l , t3 ) ; List < Point2D_F32 > inside = new ArrayList <> ( ) ; checkAddInside ( width , height , a , inside ) ; checkAddInside ( width , height , b , inside ) ; checkAddInside ( width , height , c , inside ) ; checkAddInside ( width , height , d , inside ) ; if ( inside . size ( ) != 2 ) { return null ; // System.out.println("interesting"); } return new LineSegment2D_F32 ( inside . get ( 0 ) , inside . get ( 1 ) ) ; }
Find the point in which the line intersects the image border and create a line segment at those points