简体   繁体   中英

How to make plot from file WinAPI

We have txt file with numbers:

60 0

120 4

180 20

60 -28

180 28

30 -28

30 28

30 -28

60 0

I need a plot with first column in horizontal coordinate line and the second column in vertical coordinate line like on this picture . But now I have smth like this

std::ifstream omega_file("test.txt");

MoveToEx(hdc, 0, 0, NULL); // start point
double T_new = 0;
while (!omega_file.eof())
{
    omega_file >> T >> Omega;

    T_new = T_new + T;

    LineTo(hdc, T_new / 60 * horizontal_step_grid, - Omega * vertical_step_grid);
    MoveToEx(hdc, T_new / 60 * horizontal_step_grid, - Omega * vertical_step_grid, NULL);
}

You will need to draw two lines (horizontal, then vertical) instead of one per one coordinate.

Also note that LineTo() sets the current position, so MoveToEx() to the same coordinate is redundant.

Try this:

std::ifstream omega_file("test.txt");

MoveToEx(hdc, 0, 0, NULL); // start point
int currentY = 0;
double T_new = 0;
while (omega_file >> T >> Omega)
{

    T_new = T_new + T;

    int x = T_new / 60 * horizontal_step_grid;
    int nextY = - Omega * vertical_step_grid;
    LineTo(hdc, x, currentY);
    LineTo(hdc, x, nextY);
    currentY = nextY;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM