Wind oscillates, replaces random wind with shifting wind. #story[1187]

main
Joseph Gardner 8 years ago
parent 0be5b731c3
commit d0ba7b93e0

@ -23,6 +23,8 @@ import javax.xml.bind.JAXBException;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
/**

@ -13,10 +13,11 @@ public class ShiftingWindGenerator implements WindGenerator {
double baseLineSpeed;
double speedVariance = 4;
double bearingVariance = 5; // In degrees
double oscillationPeriod = 3e6; // In milliseconds
double oscillationVariance = 0.25;
double oscillationPeriod = 1e3 * 60 * 1; // In milliseconds
double timeOfLastOscillationReset = 0;
double timeSinceLastChange = 0;
double timeOfLastChange = 0;
double timeSinceLastShift = 0; // Back / veer
boolean oscillationLeft = false;
@ -42,13 +43,39 @@ public class ShiftingWindGenerator implements WindGenerator {
oscillateWind(newWind);
shiftWind(newWind);
changeWindSpeed(newWind);
timeOfLastChange = System.currentTimeMillis();
return newWind;
}
private void oscillateWind(Wind wind) {
double timeSinceLastOscillationReset = System.currentTimeMillis() - timeOfLastOscillationReset;
double timeSinceLastChange = System.currentTimeMillis() - timeOfLastChange;
double newBearing = wind.getWindDirection().degrees();
double degreeChange = timeSinceLastChange * 2 * bearingVariance / oscillationPeriod;
degreeChange = (1 - oscillationVariance) * degreeChange + (2 * oscillationVariance) * degreeChange * Math.random();
if (timeSinceLastOscillationReset >= oscillationPeriod) {
timeOfLastOscillationReset = System.currentTimeMillis();
oscillationLeft = !oscillationLeft;
}
if (oscillationLeft) {
newBearing -= degreeChange;
if (newBearing < baselineBearing.degrees() - bearingVariance) {
System.out.println(timeSinceLastOscillationReset);
oscillationLeft = !oscillationLeft;
timeOfLastOscillationReset = System.currentTimeMillis();
} else {
wind.setWindDirection(Bearing.fromDegrees(newBearing % 360));
}
} else {
newBearing += degreeChange;
if (newBearing > baselineBearing.degrees() + bearingVariance) {
System.out.println(timeSinceLastOscillationReset);
oscillationLeft = !oscillationLeft;
timeOfLastOscillationReset = System.currentTimeMillis();
} else {
wind.setWindDirection(Bearing.fromDegrees(newBearing % 360));
}
}
}

Loading…
Cancel
Save