
Die Darstellung verwendet eine logarithmische Skala, damit Sonne, Erde und Beteigeuze gemeinsam sichtbar dargestellt werden können.
Orion ist eines der auffälligsten und am leichtesten erkennbaren Sternbilder des Nachthimmels. Es ist jetz auf der Nordhalbkugel besonders gut zu beobachten.
Beteigeuze befindet sich an der Schulter des Orion. Es handelt sich um einen roten Überriesen und einen der auffälligsten Sterne des Sternbildes. Seine rötliche Färbung ist bereits mit bloßem Auge erkennbar.
Hier die Java Klasse mit Swing für den Größenvergleich:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
import javax.swing.*; import java.awt.*; import java.text.NumberFormat; import java.util.Locale; /** * Größenvergleich Sonne, Erde und Beteigeuze. * * Die Darstellung verwendet eine logarithmische Skala, * damit Sonne, Erde und Beteigeuze gemeinsam sichtbar * dargestellt werden können. * * @author Thomas Wenzlaff */ public class SpaceSizeComparison extends JFrame { private static final long serialVersionUID = 1L; private static final double SUN_DIAMETER_KM = 1_392_700.0; private static final double EARTH_DIAMETER_KM = 12_742.0; private static final double BETELGEUSE_DIAMETER_KM = 1_950_000_000.0; private final NumberFormat numberFormat = NumberFormat.getNumberInstance(Locale.GERMANY); public SpaceSizeComparison() { super("Größenvergleich: Sonne – Erde – Beteigeuze"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLayout(new BorderLayout()); add(new HeaderPanel(), BorderLayout.NORTH); add(new ComparisonPanel(), BorderLayout.CENTER); add(new InformationPanel(), BorderLayout.SOUTH); setSize(1100, 760); setLocationRelativeTo(null); setMinimumSize(new Dimension(800, 600)); } /** * Kopfbereich. */ private class HeaderPanel extends JPanel { private static final long serialVersionUID = 1L; HeaderPanel() { setBorder(BorderFactory.createEmptyBorder( 15, 20, 10, 20)); JLabel title = new JLabel( "Durchmesservergleich astronomischer Körper"); title.setFont(new Font( Font.SANS_SERIF, Font.BOLD, 26)); add(title); } } /** * Hauptbereich mit den drei Objekten. */ private class ComparisonPanel extends JPanel { private static final long serialVersionUID = 1L; ComparisonPanel() { setBackground(Color.BLACK); setBorder(BorderFactory.createCompoundBorder( BorderFactory.createLineBorder( new Color(80, 80, 80)), BorderFactory.createEmptyBorder( 20, 20, 20, 20))); } @Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g.create(); try { g2.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int width = getWidth(); int height = getHeight(); /* * Mittellinie. */ int centerY = height / 2; /* * Logarithmische Skalierung. * * Dadurch entspricht die sichtbare Größe * dem Logarithmus des tatsächlichen Durchmessers. */ double minLog = Math.log10(EARTH_DIAMETER_KM); double maxLog = Math.log10(BETELGEUSE_DIAMETER_KM); double available = Math.min(width * 0.80, height * 0.70); double maxRadius = available / 2.0; drawObject( g2, "Erde", EARTH_DIAMETER_KM, minLog, maxLog, maxRadius, width / 6, centerY); drawObject( g2, "Sonne", SUN_DIAMETER_KM, minLog, maxLog, maxRadius, width / 2, centerY); drawObject( g2, "Beteigeuze", BETELGEUSE_DIAMETER_KM, minLog, maxLog, maxRadius, width * 5 / 6, centerY); } finally { g2.dispose(); } } private void drawObject( Graphics2D g2, String name, double diameter, double minLog, double maxLog, double maxRadius, int centerX, int centerY) { double valueLog = Math.log10(diameter); double normalized = (valueLog - minLog) / (maxLog - minLog); /* * Mindestgröße für die Sichtbarkeit. */ double radius = 25 + normalized * (maxRadius - 25); int r = (int) Math.round(radius); /* * Farbe. */ if ("Erde".equals(name)) { g2.setColor(new Color(60, 130, 220)); } else if ("Sonne".equals(name)) { g2.setColor(new Color(255, 190, 40)); } else { g2.setColor(new Color(220, 100, 50)); } g2.fillOval( centerX - r, centerY - r, 2 * r, 2 * r); /* * Umrandung. */ g2.setColor(Color.WHITE); g2.drawOval( centerX - r, centerY - r, 2 * r, 2 * r); /* * Name. */ g2.setFont(new Font( Font.SANS_SERIF, Font.BOLD, 20)); FontMetrics fm = g2.getFontMetrics(); int nameX = centerX - fm.stringWidth(name) / 2; g2.drawString( name, nameX, centerY + r + 35); /* * Durchmesser. */ g2.setFont(new Font( Font.SANS_SERIF, Font.PLAIN, 15)); String diameterText = formatKilometers(diameter); fm = g2.getFontMetrics(); int diameterX = centerX - fm.stringWidth( diameterText) / 2; g2.drawString( diameterText, diameterX, centerY + r + 58); } } /** * Informationsbereich. */ private class InformationPanel extends JPanel { private static final long serialVersionUID = 1L; InformationPanel() { setLayout(new GridLayout(4, 1)); setBorder(BorderFactory.createEmptyBorder( 12, 20, 15, 20)); JLabel scaleLabel = new JLabel( "Darstellung: logarithmische Skalierung"); JLabel sunEarth = new JLabel( String.format( Locale.GERMANY, "Sonne / Erde: %.1f : 1", SUN_DIAMETER_KM / EARTH_DIAMETER_KM)); JLabel betelgeuseSun = new JLabel( String.format( Locale.GERMANY, "Beteigeuze / Sonne: %.0f : 1", BETELGEUSE_DIAMETER_KM / SUN_DIAMETER_KM)); JLabel betelgeuseEarth = new JLabel( String.format( Locale.GERMANY, "Beteigeuze / Erde: %.0f : 1", BETELGEUSE_DIAMETER_KM / EARTH_DIAMETER_KM)); scaleLabel.setFont( new Font(Font.SANS_SERIF, Font.BOLD, 15)); add(scaleLabel); add(sunEarth); add(betelgeuseSun); add(betelgeuseEarth); } } /** * Formatiert Kilometerwerte. */ private String formatKilometers(double value) { if (value >= 1_000_000_000) { return String.format( Locale.GERMANY, "%.2f Milliarden km", value / 1_000_000_000.0); } else if (value >= 1_000_000) { return String.format( Locale.GERMANY, "%.2f Millionen km", value / 1_000_000.0); } else { return numberFormat.format(value) + " km"; } } /** * Programmstart. */ public static void main(String[] args) { SwingUtilities.invokeLater(() -> { SpaceSizeComparison application = new SpaceSizeComparison(); application.setVisible(true); }); } } |
