// Point class in Java // Original code by Sofie Hon and John Morris // import java.lang.Math.*; public class Point { private double x,y; private static double eps = 1.0e8; public Point( double x, double y ){ this.x = x; this.y = y; } public Point PointRT( double r, double theta ) { Point p = new Point( r*java.lang.Math.cos( theta ), r*java.lang.Math.sin( theta ) ); return p; } public Point CopyPoint( ) { Point p1 = new Point( x, y ); return p1; } public double XCoord( ) { return x; } public double YCoord( ) { return y; } public double RPolar( ) { return java.lang.Math.sqrt( x*x + y*y ); } public double TPolar( ) { if ( java.lang.Math.abs(y) < eps ) { return 0.0; } else { if ( java.lang.Math.abs(x) < eps ) { return java.lang.Math.PI/2.0; } } return java.lang.Math.atan2( y, x ); } public double Dist( Point p2 ) { double dx, dy, d; dx = x - p2.x; dy = y - p2.y; d = java.lang.Math.sqrt( dx*dx + dy*dy ); return d; } //Wat abt these: //assert //#define eps 1.0e-8 //#define abs(x) (((x)>=0.0)?(x):(-(x))) // Make a point the same as p1 public void SetPoint2( Point p1 ) { this.x = p1.x; this.y = p1.y; } // Change a point's attributes public void SetPoint( double x, double y ) { this.x = x; this.y = y; } // Displace p by delta: p := p+delta */ public void Displace( Point delta ) { x = x + delta.x; y = y + delta.y; } // Direction (radians) from p1 to p2 */ public double Direction( Point p2 ) { double t; t = java.lang.Math.atan2( p2.y - y, p2.x - x ); return t; } public String PointToString ( ) { // fprintf( stderr, "%s (%6.2f,%6.2f)", s, p->x, p->y ); fflush( stderr ); return new String( "(" + x + "," + y + ")" ); } }