Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Given the true wind speed and a race object. Returns the estimated boat speed from the boat
- * polar file.
- * @param trueWindSpeed Speed of wind relative to the earth.
- * @param race Race object that the boat is associated with.
- * @return
- */
- public double getEstimatedBoatSpeed(Double trueWindSpeed, Race race) throws IOException {
- Polar closestPolar = getClosestPolar(trueWindSpeed);
- //Calculate true wind angle from wind direction (apparent wind angle)
- Double windDirectionOpposite = (race.getWindDirection() + 180) % 360;
- Double trueWindAngle = Math.abs(windDirectionOpposite - this.getHeading());
- //Generate list of boat speeds from polar file
- List<Double> polarBoatSpeeds = listPolarBoatSpeeds(closestPolar);
- int index = getClosestBoatSpeedIndex(closestPolar, trueWindAngle);
- return polarBoatSpeeds.get(index);
- }
- /**
- * The boat speeds and true wind angles are evenly split into two arraylists.
- * This method returns the index value which we use to get the estimated boat speed.
- * @param closestPolar Polar object that has the closest TWS value from our given TWS
- * @param trueWindAngle previously calculated value from wind direction
- * @return integer value
- */
- private int getClosestBoatSpeedIndex(Polar closestPolar, Double trueWindAngle) {
- //Generate list of wind angles from polar file
- List<Double> polarWindAngles = listPolarWindAngles(closestPolar);
- Double currentMinDif = Math.abs(polarWindAngles.get(0) - trueWindAngle);
- int currentIndex = 0;
- for (int i = 1; i < 10; i++) {
- if (Math.abs(polarWindAngles.get(i) - trueWindAngle) < currentMinDif) {
- currentMinDif = Math.abs(polarWindAngles.get(i) - trueWindAngle);
- currentIndex = i;
- }
- }
- return currentIndex;
- }
- /**
- * Finds the correct polar to be used based on matching the wind speeds
- * @param trueWindSpeed Speed of wind relative to the earth.
- * @return A polar object that has a wind speed that is the closest match
- * to the wind speeds in the polar file.
- * @throws IOException
- */
- private Polar getClosestPolar(Double trueWindSpeed) throws IOException {
- //Parse polar file
- PolarDataAccessObject polarParser = new AccPolarParser();
- List<Polar> allPolars = polarParser.readFile("/accPolarFile.txt");
- //Get polar with Tws closest to given True Wind Speed
- Polar currentMinPolar = allPolars.get(0);
- Double currentMin = Math.abs(trueWindSpeed - allPolars.get(0).getTrueWindSpeed());
- for (Polar p : allPolars) {
- if (Math.abs(trueWindSpeed - p.getTrueWindSpeed()) < currentMin) {
- currentMinPolar = p;
- currentMin = Math.abs(trueWindSpeed - p.getTrueWindSpeed());
- }
- }
- return currentMinPolar;
- }
- /**
- * Sorts the boat speed fields of the given Polar into a list to be used in other methods
- * @param p A Polar object
- * @return An arraylist of boat speeds
- */
- private List<Double> listPolarBoatSpeeds(Polar p){
- List<Double> polarBoatSpeeds = new ArrayList<>();
- polarBoatSpeeds.add(p.getBoatSpeed0());
- polarBoatSpeeds.add(p.getBoatSpeed1());
- polarBoatSpeeds.add(p.getUpBoatSpeed());
- polarBoatSpeeds.add(p.getBoatSpeed2());
- polarBoatSpeeds.add(p.getBoatSpeed3());
- polarBoatSpeeds.add(p.getBoatSpeed4());
- polarBoatSpeeds.add(p.getBoatSpeed5());
- polarBoatSpeeds.add(p.getBoatSpeed6());
- polarBoatSpeeds.add(p.getDownBoatSpeed());
- polarBoatSpeeds.add(p.getBoatSpeed7());
- return polarBoatSpeeds;
- }
- /**
- * Sorts the wind angle fields of the given Polar into a list to be used in other methods
- * @param p A Polar object
- * @return An arraylist of wind angles
- */
- private List<Double> listPolarWindAngles(Polar p){
- List<Double> allIterateableAttributes = new ArrayList<>();
- allIterateableAttributes.add(p.getTrueWindAngle0());
- allIterateableAttributes.add(p.getTrueWindAngle1());
- allIterateableAttributes.add(p.getUpTrueWindAngle());
- allIterateableAttributes.add(p.getTrueWindAngle2());
- allIterateableAttributes.add(p.getTrueWindAngle3());
- allIterateableAttributes.add(p.getTrueWindAngle4());
- allIterateableAttributes.add(p.getTrueWindAngle5());
- allIterateableAttributes.add(p.getTrueWindAngle6());
- allIterateableAttributes.add(p.getDownTrueWindAngle());
- allIterateableAttributes.add(p.getTrueWindAngle7());
- return allIterateableAttributes;
- }
Advertisement
Add Comment
Please, Sign In to add comment