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 class Parallelogram extends Quadrilateral { 12 13 // Parallelogram constructor #1 (assume the included 14 // angle alpha satisfies the inequality 0 < alpha < PI ): 15 public Parallelogram( int x, int y, 16 int a, int b, 17 double alpha ) { 18 19 // invoke the no-argument constructor of the superclass: 20 super(); 21 22 // the 'this' reference is optional: 23 this.addPoint( x, y ); 24 this.addPoint( x + a, y ); 25 // the displacement from the vertical: 26 int d = ( int ) Math.round( b * Math.cos( Math.PI - alpha ) ); 27 // the height of the parallelogram: 28 int h = ( int ) Math.round( b * Math.sin( Math.PI - alpha ) ); 29 this.addPoint( x + a - d, y + h ); 30 this.addPoint( x - d, y + h ); 31 32 } 33 34 // Parallelogram constructor #2: 35 public Parallelogram( int x, int y, 36 int a, int b, 37 double alpha, 38 double theta ) { 39 40 // invoke Parallelogram constructor #1: 41 this( x, y, a, b, alpha ); 42 43 // rotate the parallelogram theta radians: 44 this.rotate( theta ); 45 46 } 47 48 }