package util; /** * gets a series of angles, finds the peak and then * reorders a subset to find the weighted sum of that angle * @author John H. Krantz, PH.D. * @version 0.1 * */ public class WeightAngle { WeightSum ws = new WeightSum(); public WeightAngle(){} public double getWeightAngle(double [] angles, double []activities, int range){ double angl = 0; double max = 0; int maxPos = 0; double [] angSet = new double [2*range+1]; double [] actSet = new double [2*range+1]; // find max for (int i = 0; i < activities.length; i ++){ if (activities[i]>max) { max = activities[i]; maxPos = i; } } // put the max in the middle of the array angSet[range] = angles[maxPos]; actSet[range] = activities[maxPos]; // put items below the peak // and above the peak int start = maxPos; int upStart = maxPos; for (int i = 1; i <= range; i ++){ // below the peak if (start - i < 0) start = 18 + maxPos; angSet[range-i] = 10*(maxPos-i); actSet[range-i]=activities[start-i]; // above the peak if (upStart + i >= activities.length){ upStart = maxPos-18; } angSet[range+i] = 10*(maxPos+i); actSet[range+i]=activities[upStart+i]; } angl = ws.getWeightAvg(angSet, actSet); return angl; } }