Last active
November 20, 2015 08:17
-
-
Save jafesch/841741f9248be485d830 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.HashMap; | |
public class GlobalRayFactor_main { | |
/** | |
* HashMap with all ray factors. Key is a combination of beta and gamma. | |
* Example: 20°,0°=>20 + 0 = 20 | 45°,30°=>45 + 1 = 46 | 90°,45°=>90 + 2 = 92 | |
*/ | |
static HashMap<Integer, int[]> globalRayFacotrs; | |
public static void main(String[] args) { | |
System.out.println(globalRayFactor(0, 32, 16)); //expected 31 | |
System.out.println(globalRayFactor(0, 65, 45)); //expected 62 | |
System.out.println(globalRayFactor(0, 90, 38)); //expected 92 | |
} | |
/** | |
* Searches global ray factor in hash map for the given parameters. | |
* | |
* @param month int from 0 - 11 | |
* @param beta float angle from 0° - 90° | |
* @param gamma float angle from -45° - 45° | |
* @return float global ray factor | |
*/ | |
public static float globalRayFactor(int month, float beta, float gamma) { | |
//calculate betaHash | |
int betaHash; | |
if (beta < 25) { | |
betaHash = 20; | |
} else if (beta < 37.5) { | |
betaHash = 30; | |
} else if (beta < 52.5) { | |
betaHash = 45; | |
} else if (beta < 75) { | |
betaHash = 60; | |
} else { | |
betaHash = 90; | |
} | |
//calculate gammaHash | |
float gammaAbs = Math.abs(gamma); | |
//rounds value to 0, 15, 30, 45 | |
int roundedGamma = 15 * Math.round(gammaAbs/15); | |
//creates values 0, 1, 2, 3 | |
int gammaHash = roundedGamma/15; | |
//creates values 0, 1, 2 | |
if (gammaHash > 1) gammaHash -= 1; | |
int hashKey = betaHash + gammaHash; | |
return hashKey; | |
//@beni korrekter output mit gefüllter map | |
//return globalRayFacotrs.get(hashKey)[month]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment