public static float lineIntersect(float x1, float y1, 
                                      float x2, float y2, 
                                      float x3, float y3, 
                                      float x4, float y4) {
        float denom = (y4-y3)*(x2-x1) - (x4-x3)*(y2-y1);
        
        if (denom == 0.0f) {
            return SonarSensor.max;
        }
        
        float ua = ((x4-x3)*(y1-y3) - (y4-y3)*(x1-x3)) / denom;
        float ub = ((x2-x1)*(y1-y3) - (y2-y1)*(x1-x3)) / denom;
        
        if (ua <= 1 && ua >= 0 && ub <= 1 && ub >= 0) {
            float x = x1 + ua*(x2-x1);
            float y = y1 + ua*(y2-y1);
            
            return (float) Math.sqrt(Math.pow(x-x1,2) + Math.pow(y-y1,2));
        }
        
        return SonarSensor.max;
    }