package hirondelle.starfield.physics;
import hirondelle.starfield.util.Consts;
import hirondelle.starfield.util.Util;
import java.awt.Color;
import java.util.LinkedHashMap;
import java.util.Map;
public final class Star {
private static Map<String, Double> SPECTRAL_TYPE_TO_TEMPERATURE = new LinkedHashMap<>();
static {
SPECTRAL_TYPE_TO_TEMPERATURE.put("M",3050.0);
SPECTRAL_TYPE_TO_TEMPERATURE.put("K",4450.0);
SPECTRAL_TYPE_TO_TEMPERATURE.put("G",5600.0);
SPECTRAL_TYPE_TO_TEMPERATURE.put("F",6750.0);
SPECTRAL_TYPE_TO_TEMPERATURE.put("A",8750.0);
SPECTRAL_TYPE_TO_TEMPERATURE.put("B",20000.0);
SPECTRAL_TYPE_TO_TEMPERATURE.put("O",30000.0);
}
public static double spectralTypeToTemperature(String aSpectralClass){
Double result = SPECTRAL_TYPE_TO_TEMPERATURE.get(aSpectralClass);
if (result == null){
Util.log("Unexpected spectral class: " + Util.quote(aSpectralClass));
}
return result;
}
public static double colorIndexToTemperature(double aColorIndex){
double result = -1; if (aColorIndex>=1.39){
result = 3050.0D;
}
else if (aColorIndex>=0.81){
result = 4450.0D;
}
else if (aColorIndex>=0.57){
result = 5600.0D;
}
else if (aColorIndex>=0.30){
result = 6750.0D;
}
else if (aColorIndex>=0.00){
result = 8750.0D;
}
else if (aColorIndex>=-0.31){
result = 20000.0D;
}
else {
result = 30000.0D;
}
if (result == -1){
throw new AssertionError("Unable to assign a temperature to color index: " + aColorIndex);
}
return result;
}
public static Color temperatureToColor(double temperature){
Color result = new Color(255,255,255); if (temperature>=30000){ result = new Color(155,176,255);
}
else if (temperature>=10000){ result = new Color(170,191,255);
}
else if (temperature>=7500){ result = new Color(202,215,255);
}
else if (temperature>=6000){ result = new Color(248,247,255);
}
else if (temperature>=5200){ result = new Color(255,244,234);
}
else if (temperature>=3700){ result = new Color(255,210,161);
}
else { result = new Color(255,204,111);
}
return result;
}
public double RightAscension;
public double Declination;
public double Magnitude;
public double Temperature;
@Override public String toString(){
StringBuilder result = new StringBuilder();
result.append("Star RA: " + RightAscension);
result.append(" Dec: " + Declination);
result.append(" Mag: " + Magnitude);
result.append(" Temp: " + Temperature + Consts.NL);
return result.toString();
}
}