import java.awt.geom.*; // a class with four constructors that specified 4 line in different ways public class Line { // @param x: x coordinate of the given point // @param m: slope // @param intercept: intercept of the line // a line by given a point (x,y) and slope m public Line( Point2D.Double p, double m ) { _m = m; _b = p.y - ( _m * p.x ); if( -1 == _m ) _b = 0; } // a line by given two points public Line( Point2D.Double p1, Point2D.Double p2 ) { if( p2.x == p1.x ) { _m = -1; _b = 0; } else { _m = ( p2.y - p1.y ) / ( p2.x - p1.x ); _b = p1.y - ( _m * p1.x ); } } // a line by applying equation y = mx + b public Line( double m, double b ) { _m = m; _b = b; if( -1 == _m ) _b = 0; } // a vertical line public Line( double a ) { _m = -1; _b = 0; } // a method that check if the lines intersect to each other public boolean intersects( Line other ) { boolean retval = false; if( _m != other._m ) retval = true; return retval; } public boolean equals( Line other ) { boolean retval = false; if( _m == other._m && _b == other._b ) retval = true; return retval; } public boolean isParallel( Line other ) { boolean retval = false; if( _m == other._m && _b != other._b ) retval = true; return retval; } private double _m; private double _b; }