/** * Write a description of class CornFields here. * * @author (your name) * @version (a version number or a date) */ public class CornField { static final double L = 100.0; public static double getDirection(double angle){ double d = Math.cos( Math.toRadians(angle)); if(d >=0) return 1; return -1; } public static double computeAreaOfTrapezoid(double h, double a, double b){ return h * ((a + b) / 2 ); } public static double computeHeight(double l, double angle){ double a = Math.toRadians(angle); if( angle >= 0 && angle <= 90){ return l * Math.cos( a ); }else if( angle > 90 && angle <= 180){ return -l * Math.cos( Math.PI - a ); }else if(angle > 180 && angle <= 270){ return -l * Math.cos( a - Math.PI ) ; }else{ return l * Math.cos( 2* Math.PI - a ); } } public static double computeFrontSide(double l, double h){ return Math.sqrt(Math.pow(l,2) - Math.pow(h,2)); } public static void printHeights(double[] ls, double[] angles){ // accumulate the total areas of trapezoids double total = 0; // keep track of the hights of each trapezoids while moving double rWidth = 0; //this is the left side of the trapezoid double a = L; // this is the right side of the trapezoid double b = L; for(int i=0;i 180){ b -= ll; }else{ b += ll; } double area = computeAreaOfTrapezoid(h,a,b); //System.out.println("h:" + h + " a :" + a + " b:" + b); //System.out.println("area:" + area); total+=area; rWidth +=h; a = b; } //compute the distance between the first point and the last one. double rDistance = computeLastDistance(a,rWidth); //compute the area of the last remaining trapezoid that connect the last point // with the first one. double rArea = -1 * computeAreaOfTrapezoid(rWidth , a, L); //System.out.println("remaining area:" + rArea); int ra = (int) ( ( rArea + total) * 10); rArea = (double)ra / 10; System.out.println("Area:" + rArea); //System.out.println("area:" + (total + rArea)); //compute the perimeter of the polygram. //double peri = rDistance; //for(int i=0;i