1  /*
  2   *  File:  Parallelogram.java
  3   *
  4   *  Parallelogram class
  5   *
  6   *  Copyright:  Northeast Parallel Architectures Center
  7   *  
  8   */
  9  
 10  // A parallelogram is a quadrilateral with parallel sides:
 11  public class Parallelogram extends Quadrilateral {
 12  
 13     // horizontal displacement (from vertical):
 14     private int d;
 15     // height of parallelogram:
 16     private int h;
 17     
 18     // accessor methods:
 19     public int getHeight() { return h; }
 20     public int getDisplacement() { return d; }
 21     
 22     // Parallelogram constructor #1 (assume the included
 23     // angle alpha satisfies the inequality  0 < alpha < PI ):
 24     public Parallelogram( int x, int y, 
 25                           int a, int b, 
 26                           double alpha  ) {
 27   
 28        // invoke the no-argument constructor of the superclass:
 29        super();
 30   
 31        // the 'this' reference is optional:
 32        this.addPoint( x, y );
 33        this.addPoint( x + a, y );
 34        this.d = ( int ) Math.round( b * Math.cos( Math.PI - alpha ) );
 35        this.h = ( int ) Math.round( b * Math.sin( Math.PI - alpha ) );
 36        this.addPoint( x + a - d, y + h );
 37        this.addPoint( x - d, y + h );
 38   
 39     }
 40  
 41     // Parallelogram constructor #2:
 42     public Parallelogram( int x, int y, 
 43                           int a, int b, 
 44                           double alpha,
 45                           double theta  ) {
 46   
 47        // invoke Parallelogram constructor #1:
 48        this( x, y, a, b, alpha );
 49      
 50        // rotate the parallelogram theta radians:
 51        this.rotate( theta );
 52   
 53     }
 54  
 55  }