Вот видео о приложении Python: https://www.youtube.com /watch?v=Wt4AYMXqAkU
В версии C++ он работает точно до 10^12 Mass1 и 1 для Mass2.
Как я могу сделать его более точным?
< pre class="lang-c++ Prettyprint-override">
Код: Выделить всё
#include
#include
#include
struct patrat {
float greutate; //mass
sf::RectangleShape shape;
float viteza; //velocity
}patrat1,patrat2;
int main()
{
patrat1.greutate = 1000000000000.0f; //10^12 = 3141430
patrat1.shape.setSize(sf::Vector2f(200.0, 200.0));
patrat1.shape.setFillColor(sf::Color::Blue);
patrat1.shape.setPosition(500.0f, 250.0f);
patrat1.viteza = -0.1f;
patrat2.greutate = 1.0f;
patrat2.shape.setSize(sf::Vector2f(100.0f, 100.0f));
patrat2.shape.setFillColor(sf::Color::Red);
patrat2.shape.setPosition(200.0f, 350.0f);
patrat2.viteza = 0.0f;
sf::RectangleShape shape(sf::Vector2f(200, 200));
shape.setPosition(150.0f, 250.0f);
shape.setFillColor(sf::Color::Blue);
sf::RectangleShape shape1(sf::Vector2f(100, 100));
shape1.setPosition(50.0f, 350.0f);
shape1.setFillColor(sf::Color::Red);
sf::RenderWindow window(sf::VideoMode(900, 500), "SFML works!");
sf::RectangleShape lineV(sf::Vector2f(5, 500));
lineV.setPosition(50, 0);
lineV.setFillColor(sf::Color::White);
sf::RectangleShape lineH(sf::Vector2f(900, 5));
lineH.setPosition(0, 450);
lineH.setFillColor(sf::Color::White);
int pi = 0;
float dt, fps = 700.0,sem;
window.setFramerateLimit(fps);
dt = 1 / fps;
float min = patrat2.viteza;
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
window.clear();
if(patrat1.shape.getPosition().x
Подробнее здесь: [url]https://stackoverflow.com/questions/78308312/why-is-this-python-code-running-faster-and-more-accurate-than-the-c-code[/url]