Help with equations inside of code? Newb...

I need help calculating the (x,y) position at each time step I was provided with in the .txt file. As well as displaying it on the screen, these are the equations I have to work with. https://imgur.com/a/sm2ywwU
Should I put them inside the while loop?

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
#include <iostream>
#include <vector>
#include <fstream>
#include <string>
using namespace std;
int main() {
    ifstream inData("HW01data.txt");
    
    if (!inData)
    {
        cout << "File not open\n";
        return 0;
    }
    
    vector <float> t;
    vector <float> o1;
    vector <float> o2;
    
    string line;
    float a, b, c;
    
    while(!inData.eof()) {
        a = 0.0f;
        b = 0.0f;
        c = 0.0f;
        inData >> a;
        inData >> b;
        inData >> c;
        
        t.push_back(a);
        o1.push_back(b);
        o2.push_back(c);
    }
    return 0;
}
Yes, it would seem that the equations should go in the loop.

Can you show the first few lines of the txt file and explain what a, b, c (and t, o1, o2) are?
Last edited on
Yeah of course.. There are quite a few values but here are the first 5 and last 5.
0.0000000e+00 1.6418175e+01 1.6915159e+01
1.0000000e-01 1.6418175e+01 1.6915159e+01
2.0000000e-01 1.6416387e+01 1.6916946e+01
3.0000000e-01 1.6412289e+01 1.6917663e+01
4.0000000e-01 1.6407815e+01 1.6921339e+01
.
.
.
8.6000000e+00 1.6381349e+01 1.6945634e+01
8.7000000e+00 1.6381036e+01 1.6946175e+01
8.8000000e+00 1.6393067e+01 1.6946085e+01
8.9000000e+00 1.6388345e+01 1.6949406e+01
9.0000000e+00 1.6391376e+01 1.6948039e+01
Also this was the second page we were given and where the question was asked. It would probably be useful since it has the values for L and D... Lol
https://imgur.com/a/NSQ1wrr
But honestly I'm just stuck on where the equation would go... I feel like I could figure out the "math" part for the equation itself but I'm lost when it comes to calculating in loops for each value step.
Last edited on
You need to loop over the vectors

1
2
3
4
5
6
7
8
9
10
11
12
    ...
    float pos_x = 0.f, pos_y = 0.f;

    for (int i = 0; i < (int)t.size(); ++i)
    {
         tmp_pos_x =    // Here comes
         tmp_pos_y =    // the code of the formula.

         pos_x += tmp_pos_x, pos_y += tmp_pos_y;

         cout << "After "<< t[i] << " seconds, the robot is at position ("<<pox_x<<","<<pos_y<<").\n";
    }
Last edited on
Topic archived. No new replies allowed.