This lab is due by Thursday, November 19, 2020, 11:59 PM.
As with all labs you may, and are encouraged, to pair program a solution to this lab. If you choose to pair program a solution, be sure that you individually understand how to generate the correct solution.
Concepts
This assignment exercises your skills for working with input & output file streams to process data to be graphically displayed.
Instructions
Your task for this lab is to read a data file containing star information, modify the information read, and write the new data to the terminal. In the assignment, you will use the new data and draw a star map similar to the one shown here (ahhhh - cool!):
Data File
To begin, create an empty project and place the stars.txt file in the appropriate directory. As previously mentioned, an input file needs to be placed at the project level. You should see both your input file AND a main.cpp file in the same directory.
Your job is to read the data that is within this file, make modifications to the data in order to draw the data, and write the new data out to a file. Each line of the data file contains information of one star, with each field separated by a tab. The meaning of each field (column) is described below. Note that data files often contain more information than is needed for a given purpose and that data files may contain outlying values that are also not needed for a given purpose. We suggest you take a look at the stars.txt as you read the following details about your input file.
- The first three fields are the
x
,y
, andz
coordinates for the star. You will need to store thex
andy
coordinates (after modification, see below), but will not need thez
coordinate. Thus, in your output, only write the modifiedx
andy
coordinates. The coordinate system is described in more detail below. - The fourth field is the
brightness
of each star. We only want to plot stars with abrightness
between0.0
and8.0
, so only write those stars to the output. - The fifth and sixth fields are the Henry Draper and Harvard Revised numbers for the star. These are numbers used in different star catalog systems, so they can be ignored for this assignment. Thus, you do not want to write these numbers to the output.
All output should be written to a new file named ModifiedStars.txt
.
Coordinates
Each axis in the star coordinate system goes from -1.0
to +1.0
and the
origin (0
, 0
) is at the center. Thus, the x
and y
coordinate values for each star
will all be numbers in the range -1.0
to +1.0
.
The coordinate system used in our graphics library (SFML)
has the origin (0
, 0
) in the upper-left corner
of the picture, and the maximum x
and y
values are the
width and height of the window, in pixels.
Thus, to determine the location of each star to draw in our graphics library,
you need to convert from the -1.0
to +1.0
range of the star
coordinate system to the (0
, 0
) to (WIDTH
, HEIGHT
)
range of the graphics library coordinate system. Declare
WIDTH
and HEIGHT
as constants in your program, with both values
set to 640 (which are defined for your screen size).
More specifically, if xStar
is a double variable holding a star's x-coordinate
in the range -1.0
to +1.0
, to convert it to an integer pixel value in the
range 0
to WIDTH
, you would use the following:
int xPixel = (int)( ( xStar + 1 ) * WIDTH / 2 );
Similarly, if yStar
is a double variable holding a star's y-coordinate in the
range -1.0
to +1.0
, to convert it to an integer pixel value in the range 0
to HEIGHT
, you would use the following:
int yPixel = (int)( ( -yStar + 1 ) * HEIGHT / 2 );
Note the minus sign on the yPixel equation. We encourage you to plug a few coordinates into these equations, e.g., (-0.5,0.5) and (-0.5,-0.5), to ensure the equations are correct.
To verify the modifications are correct, the first line of the stars.txt file is:
0.994772 -0.023164 -0.099456 4.610000 28 3
The first line of your output should be:
638 327 4.61
Putting It All Together
Even though we are only using the x
, y
, and brightness
values, you will need to read all six values on each line of the data file.
Make sure you read each of these into an appropriate type variable.
Each line in the output has the following fields:
- the first two fields should be the modified (x,y) coordinates for the star;
- the third field should be the brightness;
- and all fields should be tab separated (
'\t'
).
As discussed, do not include a line in your output if the star brightness is greater than 8.0. Also, be sure to check your input file opens appropriately and close it when you are done with it.
Lab Submission
You will submit your solution to this lab with the rest of Set7. Detailed instructions for doing this are posted in Assignment 7.
This lab is due by Thursday, November 19, 2020, 11:59 PM.
As with all labs you may, and are encouraged, to pair program a solution to this lab. If you choose to pair program a solution, be sure that you individually understand how to generate the correct solution.