4
I need help with problem 133
source link: https://www.codeabbey.com/index/forum_topic/29e8b9f1ba5782379b3540b40c423220
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
I need help with problem 133 |
Back to General discussions forum
Artem Tsatinyan
2022-10-05 20:43:28
So,my code solves the problem from the example correctly, here is a screenshot of the trajectory drawn using sfml
But there are problems with real tasks
And i don't really get why it doesn't work correctly
Help me please
This is my code:
#include <iostream>
#include <cmath>
using namespace std;
int sign(double x) {
if (x >= 0) {
return 1;
}
else return -1;
}
int main() {
double W, H, X, Y, R, Vx, Vy, A, dt = 0.00001, V;
cin >> W >> H >> X >> Y >> R >> Vx >> Vy >> A;
V = sqrt(Vx * Vx + Vy * Vy);
while (V > 0) {
if (X + Vx * dt < R || X + Vx * dt > W - R) Vx = -Vx;
if (Y + Vy * dt < R || Y + Vy * dt > H - R) Vy = -Vy;
X += Vx * dt;
Y += Vy * dt;
V -= A * dt;
double cs = cos(atan(Vx / Vy));
double sn = sin(atan(Vx / Vy));
Vx = V * abs(cs) * sign(Vx);
Vy = V * abs(sn) * sign(Vy);
}
cout << round(X) << " " << round(Y);
}
Please login and solve 5 problems to be able to post at forum
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK