constellations -0.581457 -0.294806 -0.536543 -0.205755 -0.536543 -0.205755 -0.54
ID: 3602265 • Letter: C
Question
constellations
-0.581457 -0.294806 -0.536543 -0.205755
-0.536543 -0.205755 -0.544292 -0.130741
-0.544292 -0.130741 -0.54293 -0.036595
-0.54293 -0.036595 -0.591873 0.015941
-0.591873 0.015941 -0.535916 0.138997
-0.535916 0.138997 -0.459109 0.115042
-0.54293 -0.036595 -0.459109 0.115042
0.010128 0.007897 -0.007201 -0.059107
-0.007201 -0.059107 -0.043974 -0.131365
-0.043974 -0.131365 -0.11818 -0.175304
-0.11818 -0.175304 -0.200728 -0.185075
-0.200728 -0.185075 -0.199642 -0.239467
-0.199642 -0.239467 -0.106414 -0.221875
-0.106414 -0.221875 -0.11818 -0.175304
COMP163 Star Chart Astronomers collect lots of data about stars and there are many catalogs that identify the locations of stars. In this assignment, you will use data in a star catalog to create a picture that plots the locations of stars.1 The file stars.txt contains one line for each star that is represented in the catalog. The meaning of each field (column) is described below The first three fields are the x, y and z coordinates for the star. Each axis in the coordinate system goes from -1 to +1, and the center point is 0,0. (See the figure below.) The fourth field is the Henry Draper number, which is simply a unique identifier for the star that is unnecessary for this program The fifth field is the magnitude (or brightness) of the star. The smaller the number, the brighter the star The sixth field is Harvard Revised number, another identifier that is unnecessary for this program · Your program will have to read each data item in the file even if it will not be used. The coordinate system used for pixels in a picture has position (0,0) in the upper left corner of the picture, and the maximum x and y values are the height and width of the picture in pixels. In this assignment, al pictures will be square with a maximum height and width of 900 pixels. See below for a comparison of the two coordinate systems. 0,0 0,900 5 -1 0.5 0.0 Pixel Coordinate System 0.5 -1 Star Catalog Coordinate Systenm 900, 0 The first step is to write a method that will convert from coordinate numbers to a pixel location. Note the same method will work for both X and Y coordinates. The method will have the header int coord2pixel ( double coord)Explanation / Answer
-------------------------------Stars.java-------------------------------
import java.util.*;
import java.io.*;
public class Stars {
public void drawStars(java.awt.Graphics sky) throws java.io.FileNotFoundEception {
FileInputStream fstream = new FileInputStream("stars.txt");
Scanner s = new Scanner(fstream);
sky.setColor(Color.WHITE);
while(s.hasNextLine()){
string line = s.nextLine();
String[] word = line.split("\s");
double x = Double.parseDouble(word[0]);
double y = Double.parseDouble(word[1]);
double z = Double.parseDouble(word[2]);
double magnitude = Double.parseDouble(word[4]);
int size = (int)(5.0 - magnitude) + 1;
sky.drawRect(coord2pixel(x), coord2pixel(y), size, size);
}
}
private int coord2pixel(double coord){
return 450+(450*coord);
}
public static void main(String [] args){
StarFrame window = new StarFrame();
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.