From 4cf5f3f449f25a6a853ccb4807cadb68768925b7 Mon Sep 17 00:00:00 2001 From: Joachim Date: Mon, 24 Sep 2018 22:58:25 +0200 Subject: [PATCH] Fixing the bug, pleeeeease --- .gitignore | 2 + src/main/java/HygParser.kt | 5 +- src/main/java/HygStar.kt | 2 +- src/main/java/SvgCreator.kt | 116 +- src/main/java/TestHoekskes.kt | 7 + stars.svg | 4275 --------------------------------- 6 files changed, 99 insertions(+), 4308 deletions(-) create mode 100644 src/main/java/TestHoekskes.kt delete mode 100644 stars.svg diff --git a/.gitignore b/.gitignore index a828e80..b8a9d61 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ target *.iml .idea data +stars.svg +*.log diff --git a/src/main/java/HygParser.kt b/src/main/java/HygParser.kt index 97a8e87..b32563d 100644 --- a/src/main/java/HygParser.kt +++ b/src/main/java/HygParser.kt @@ -58,7 +58,10 @@ class HygParser { dec = it[dec].toDouble(), mag = it[mag].toDouble(), absmag = it[absmag].toDouble(), - properName = it[proper] + properName = it[proper], + colorIndex = it[ci], + bayerFlamsteed = it[bf], + constellationAbbreviation = it[con] ) }.stream() diff --git a/src/main/java/HygStar.kt b/src/main/java/HygStar.kt index 9c0acbf..cc49cb8 100644 --- a/src/main/java/HygStar.kt +++ b/src/main/java/HygStar.kt @@ -1 +1 @@ -data class HygStar(val ra: Double, val dec: Double, val mag: Double, val absmag: Double, val properName: String?) \ No newline at end of file +data class HygStar(val ra: Double, val dec: Double, val mag: Double, val absmag: Double, val properName: String?, val colorIndex: String, val bayerFlamsteed: String, val constellationAbbreviation: String) \ No newline at end of file diff --git a/src/main/java/SvgCreator.kt b/src/main/java/SvgCreator.kt index 83a78cc..468f54d 100644 --- a/src/main/java/SvgCreator.kt +++ b/src/main/java/SvgCreator.kt @@ -7,11 +7,14 @@ import com.singulariti.os.ephemeris.domain.Star import com.singulariti.os.ephemeris.utils.StarCatalog import java.io.File import java.io.FileReader +import java.time.Duration import java.time.Instant import java.time.ZoneId import java.time.ZonedDateTime import java.util.* +import java.util.concurrent.TimeUnit import java.util.stream.Stream +import javax.xml.datatype.DatatypeConstants.HOURS import kotlin.math.absoluteValue @@ -25,17 +28,26 @@ import kotlin.math.absoluteValue fun main(args: Array) { // set the place and time you want val starPositionCalculator = StarPositionCalculator() + val observatory = getObservatory() - // at least get this absolute magnitude (smaller is brighter) - val apparentMagnitudeCutOff = 6.5 + // at least get this absolute magnitude (smaller is brighter) 6.5 = human vis + val apparentMagnitudeCutOff = 7 // make the svg file File("stars.svg").printWriter().use { out -> out.println(""" """.trimIndent()) // history.forEach { @@ -44,11 +56,9 @@ fun main(args: Array) { // second attempt val calendarAstronomer = CalendarAstronomer(Date(Instant.parse("2018-10-05T10:15:30.00Z").toEpochMilli())) - var maxAltitude = Double.NEGATIVE_INFINITY - var minAltitude = Double.POSITIVE_INFINITY + val colorIndices = HashSet() - var maxMagnitude = Double.NEGATIVE_INFINITY - var minMagnitude = Double.POSITIVE_INFINITY + val casA = StarCatalog.byIdAndConstellation("a", "cas") // read the hyg database... HygParser() @@ -59,17 +69,19 @@ fun main(args: Array) { } .forEach { star -> - if (star.absmag < minMagnitude) - minMagnitude = star.absmag - if (star.absmag > minMagnitude) - maxMagnitude = star.absmag + colorIndices.add(star.colorIndex) + + val convertDegreesToHoursMinutesSeconds = convertDecimalHoursToHMS(star.ra) + val convertDegreesToHoursMinutesSeconds1 = convertDecimalHoursToHMS(star.dec) + + println("convertDegreesToHoursMinutesSeconds = ${convertDegreesToHoursMinutesSeconds} ${convertDegreesToHoursMinutesSeconds1}") val star1 = Star( null, null, null, - convertDegreesToHoursMinutesSeconds(star.ra), - convertDegreesToHoursMinutesSeconds(star.dec), + convertDegreesToHoursMinutesSeconds, + convertDegreesToHoursMinutesSeconds1, star.mag.toInt().toString(), null, null @@ -77,6 +89,7 @@ fun main(args: Array) { // print the star println("it = $star") + println(" > star1 = ${star1.ra} ${star1.de}") val position = starPositionCalculator.getPosition(star1, observatory) // println("position = $position") @@ -106,36 +119,64 @@ fun main(args: Array) { y += 90 x += 90 + // figure out the color + val colorClass = if (star.colorIndex.isNotEmpty()) { + star.colorIndex.toDouble().let { + when { + it <= -.33 -> "colorClassO5V" + it <= -.3 -> "colorClassB0V" + it <= -0.02 -> "colorClassA0V" + it <= 0.3 -> "colorClassF0V" + it <= 0.58 -> "colorClassG0V" + it <= 0.81 -> "colorClassK0V" + it <= 1.40 -> "colorClassM0V" + else -> "colorClassDefault" + } + } + } else { + "colorClassDefault" + } + // determine the size of the circle -> depending on the apparent magnitude val circleR = ((star.mag - apparentMagnitudeCutOff) * -1) * 0.05 // print it to svg val random = Random() - out.println("""""") + out.println("""""") // print name? if (star.properName?.isNotEmpty() == true) { out.println("""${star.properName}""") } - } - if (altitude < minAltitude) - minAltitude = altitude - if (altitude > maxAltitude) - maxAltitude = altitude + if (star.constellationAbbreviation?.isNotEmpty()) { + val col = when (star.constellationAbbreviation) { + "Dra" -> "red" + "UMa" -> "green" + "Her" -> "blue" + else -> "white" + } + out.println("""${star.constellationAbbreviation}""") + } + } else { +// println("skipping star... $altitude") + } // filter the stars on altitude } - println("minAltitude = ${minAltitude}") - println("maxAltitude = ${maxAltitude}") - println("minMagnitude = ${minMagnitude}") - println("maxMagnitude = ${maxMagnitude}") + val minRaa = HygParser().parse().mapToDouble { star -> star.ra }.min() + println("minRa = ${minRaa}") + val maxRaa = HygParser().parse().mapToDouble { star -> star.ra }.max() + println("maxRa = ${maxRaa}") + val minDec = HygParser().parse().mapToDouble { star -> star.dec }.min() + println("minDec = ${minDec}") + val maxDec = HygParser().parse().mapToDouble { star -> star.dec }.max() + println("maxDec = ${maxDec}") out.println("") } - } /** @@ -155,23 +196,32 @@ fun dmsToRad(input: String): Double { * Default position: gontrodestraat */ fun getObservatory(name: String = "Default place name", latitude: Double = 51.027930, longitude: Double = 3.753585): Observatory { - val time = ZonedDateTime.of(2018, 10, 5, 16, 0, 0, 0, ZoneId.of("UTC")) //Date and time in UTC + val time = ZonedDateTime.of(2018, 10, 5, 19, 0, 0, 0, ZoneId.of("UTC")) //Date and time in UTC val place = Place(name, latitude, Pole.NORTH, longitude, Pole.EAST, TimeZone.getTimeZone("Asia/Calcutta"), "", "") return Observatory(place, time) } /** - * Convert 2.39483 degrees to X:Y:Z, X hours, Y minutes, Z seconds + * Convert 21.9384 hours to X:Y:Z, X hours, Y minutes, Z seconds */ -fun convertDegreesToHoursMinutesSeconds(degrees: Double): String { - val hours = Math.floor(degrees).toInt() - val minutesWithRest = (degrees - hours) * 60 +fun convertDecimalHoursToHMS(degrees: Double): String { + // what's the sign? + val sign = if(degrees<0) "-" else "+" + val input = degrees.absoluteValue + val hours = Math.floor(input).toInt() + val minutesWithRest = (input - hours) * 60 val minutes = Math.floor(minutesWithRest).toInt() - val seconds = (minutesWithRest - minutes) * 60 - val result = "$hours:$minutes:$seconds" + val seconds = ((minutesWithRest - minutes) * 60).toInt() + val result = "${sign}$hours:$minutes:$seconds" return result } +/** + * Convert 25.5 degrees to 25 degrees, 5 + */ +fun convertDecimalDegreesToDMS(degrees: Double): String { + return convertDecimalHoursToHMS(degrees) +} fun testEphemeris() { @@ -200,3 +250,7 @@ fun getDistanceFromLatLonInKm(lat1: Double, lon1: Double, lat2: Double, lon2: Do fun deg2rad(deg: Double): Double { return deg * (Math.PI / 180) } + +fun hoursToDms(hours: Double) { + +} diff --git a/src/main/java/TestHoekskes.kt b/src/main/java/TestHoekskes.kt new file mode 100644 index 0000000..313162d --- /dev/null +++ b/src/main/java/TestHoekskes.kt @@ -0,0 +1,7 @@ +fun main(args: Array) { + val h = convertDecimalHoursToHMS(-24.0) + println("h = ${h}") + + val s = convertDecimalDegreesToDMS(-45.2) + println("s = ${s}") +} \ No newline at end of file diff --git a/stars.svg b/stars.svg deleted file mode 100644 index d19307f..0000000 --- a/stars.svg +++ /dev/null @@ -1,4275 +0,0 @@ - - - - - - - - - - - - - - - - - - - - -Caph - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Shedir - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Cih - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Ruchbah - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Almaak - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Polaris - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Algol - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Mirphak - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Alcyone - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Aldebaran - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Hassaleh - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Capella - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Bellatrix - - -Alnath - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Betelgeuse - - - - - - - - - - - - - - -Menkalinan - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Alhena - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Gomeisa - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Castor - - - - - - - - - - - - - - - - - -Procyon - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Pollux - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Alphard - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Ras Elased Australis - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Regulus - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Algieba - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Merak - - - - - - - - - -Dubhe - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Zosma - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Denebola - - - - - - - - - - - - -Groombridge 1830 - - -Phad - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Megrez - - -Gienah Ghurab - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Algorab - - - - - - - - - - - - - - - - - - - - - - - - -Kraz - - - - - - - - - - - - - - - - - - - - - -Porrima - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Alioth - - - - - - - - - -Cor Caroli - - - - - - - - - - - - - - - - - -Vindemiatrix - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Mizar - - - - - -Spica - -Alcor - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Alkaid - - - - - - - - - - - - - - - - - - - - - - - - -Mufrid - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Thuban - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Arcturus - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Izar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Kochab - -Zubenelgenubi - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Zubeneschemali - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Alphekka - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Unukalhai - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Kornephoros - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Rasalgethi - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Rastaban - - - - - - - - - - - - - - - - - - - -Rasalhague - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Cebalrai - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Etamin - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Vega - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Sheliak - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Albireo - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Sadr - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Deneb - - - - - - - - - - - - - -Gienah - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -Alderamin - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -