September 2017 Update

This commit is contained in:
Ingy döt Net 2017-09-23 10:01:46 +02:00
parent bba7bfd280
commit ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions

View file

@ -1,60 +1,30 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class RAvgMeanAngle {
public class AverageMeanAngle {
private static final List<List<Double>> samples;
static {
samples = new ArrayList<>();
samples.add(Arrays.asList(350.0, 10.0));
samples.add(Arrays.asList(90.0, 180.0, 270.0, 360.0));
samples.add(Arrays.asList(10.0, 20.0, 30.0));
samples.add(Arrays.asList(370.0));
samples.add(Arrays.asList(180.0));
}
public RAvgMeanAngle() {
return;
}
public double getMeanAngle(List<Double> sample) {
double x_component = 0.0;
double y_component = 0.0;
double avg_d, avg_r;
for (double angle_d : sample) {
double angle_r;
angle_r = Math.toRadians(angle_d);
x_component += Math.cos(angle_r);
y_component += Math.sin(angle_r);
}
x_component /= sample.size();
y_component /= sample.size();
avg_r = Math.atan2(y_component, x_component);
avg_d = Math.toDegrees(avg_r);
return avg_d;
}
public static void main(String[] args) {
runSample(args);
return;
}
public static void runSample(String[] args) {
RAvgMeanAngle main = new RAvgMeanAngle();
for (List<Double> sample : samples) {
double meanAngle = main.getMeanAngle(sample);
System.out.printf("The mean angle of %s is:%n%12.6f%n%n", sample, meanAngle);
public static void main(String[] args) {
printAverageAngle(350.0, 10.0);
printAverageAngle(90.0, 180.0, 270.0, 360.0);
printAverageAngle(10.0, 20.0, 30.0);
printAverageAngle(370.0);
printAverageAngle(180.0);
}
return;
}
private static void printAverageAngle(double... sample) {
double meanAngle = getMeanAngle(sample);
System.out.printf("The mean angle of %s is %s%n", Arrays.toString(sample), meanAngle);
}
public static double getMeanAngle(double... anglesDeg) {
double x = 0.0;
double y = 0.0;
for (double angleD : anglesDeg) {
double angleR = Math.toRadians(angleD);
x += Math.cos(angleR);
y += Math.sin(angleR);
}
double avgR = Math.atan2(y / anglesDeg.length, x / anglesDeg.length);
return Math.toDegrees(avgR);
}
}