Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SFML/Graphics.hpp>
- #include <iostream>
- #include <math.h>
- #include <cmath>
- #include <sstream>
- #include <ctime>
- #include <windows.h>
- #include <conio.h>
- #include <stdio.h>
- #define PI 3.14159265
- const int size = 20;
- const double g = 9.8;
- const int indent = 50; //отступ при рисовании (раньше было 30)
- const int size_angle_point = 5; //размер отметки поворота на круге
- const int len = 600;
- using namespace sf;
- using namespace std;
- int main()
- {
- setlocale(LC_ALL, "Russian");
- CircleShape shape(10);
- CircleShape angle_point(10);
- Font fnt;
- fnt.loadFromFile("CyrilicOld.ttf");
- Text txt1("", fnt, 30);
- txt1.setColor(Color::Red);
- txt1.setStyle(Text::Bold);
- Text txt2("", fnt, 30);
- txt2.setColor(Color::Red);
- txt2.setStyle(Text::Bold);
- Text txt3("", fnt, 30);
- txt3.setColor(Color::Red);
- txt3.setStyle(Text::Bold);
- Text txt4("", fnt, 30);
- txt4.setColor(Color::White);
- txt4.setStyle(Text::Bold);
- Text txt5("", fnt, 30);
- txt5.setColor(Color::White);
- txt5.setStyle(Text::Bold);
- Text txt6("", fnt, 30);
- txt6.setColor(Color::White);
- txt6.setStyle(Text::Bold);
- Text txt7("", fnt, 30);
- txt7.setColor(Color::White);
- txt7.setStyle(Text::Bold);
- RectangleShape line(Vector2f(len, 5));
- shape.setFillColor(Color::Green);
- angle_point.setFillColor(Color::Red);
- double x = 0, y = 0;
- int type = 0;
- while((type < 1) || (type > 3))
- {
- cout << "Введите тип тела (1 - обруч, 2 - цилиндр, 3 - шар) : ";
- cin >> type;
- }
- double mas = -1.0;
- while(mas <= 0)
- {
- cout << "Введите вес (кг, больше 0) : ";
- cin >> mas;
- }
- double rad = -1.0;
- double flag_pointer = false;
- while ((rad > 50) || (rad <= 0))
- {
- cout << "Введите радиус (метры, больше 0 и до 50) : ";
- cin >> rad;
- }
- shape.setRadius(rad);
- if ((rad / 2) >= size_angle_point)
- {
- angle_point.setRadius(size_angle_point);
- flag_pointer = true;
- }
- int alpha = -1;
- while ((alpha >= 90) || (alpha <= 0))
- {
- cout << "Введите угол наклонной плоскости (градусы, от 0 до 90) : ";
- cin >> alpha;
- }
- line.rotate(alpha);
- shape.setPosition(indent, indent);
- line.setPosition(indent + rad - rad*sin(alpha * PI / 180), indent + rad + rad*cos(alpha * PI / 180));
- double I;
- if (type == 1) I = mas * rad * rad;
- if (type == 2) I = mas * rad * rad / 2;
- if (type == 3) I = 2 * mas * rad * rad / 5;
- double a = (mas * g * sin(alpha * PI / 180)) / ((I / (rad * rad)) + mas);
- double ax = a * cos(alpha * PI / 180);
- double ay = a * sin(alpha * PI / 180);
- double angle = 0; //in rad
- double angle_deg = 0;
- angle_point.setPosition
- (indent + rad + (rad * cos(angle) / 2) - size_angle_point,
- indent + rad + (rad * sin(angle) / 2) - size_angle_point);
- double E = a / rad;
- double t = 0.0;
- double V = 0.0;
- RenderWindow window(VideoMode(1100, 1000), "WORK", Style::Fullscreen);
- while (window.isOpen())
- {
- Event event;
- while (window.pollEvent(event))
- {
- if (event.type == Event::Closed)
- window.close();
- }
- ostringstream astring;
- ostringstream estring;
- ostringstream xstring;
- ostringstream ystring;
- ostringstream angstring;
- ostringstream angdegstring;
- ostringstream speedstring;
- ostringstream istring;
- double i_out = floor(I * 100) / 100.0;
- double a_out = floor(a * 10) / 10.0;
- double x_out = floor(x * 10) / 10.0;
- double y_out = floor(y * 10) / 10.0;
- double E_out = floor(E * 1000) / 1000.0;
- double angle_out = floor(angle * 10) / 10.0;
- double angle_deg_out = floor(angle_deg * 10) / 10.0;
- double V_out = floor(V * 10) / 10.0;
- istring << i_out;
- astring << a_out;
- xstring << x_out;
- estring << E_out;
- ystring << y_out;
- angstring << angle_out;
- angdegstring << angle_deg_out;
- speedstring << V_out;
- txt1.setString("Момент инерции = " + istring.str() + " " + "кг*м^2");
- txt1.setPosition(870, 50);
- txt2.setString("Ускорение = " + astring.str() + " " + "м/с^2");
- txt2.setPosition(870, 150);
- txt3.setString("Угловое ускорение = " + estring.str());
- txt3.setPosition(870, 250);
- txt4.setString("Координаты (" + xstring.str() + ";" + ystring.str() + ")");
- txt4.setPosition(870, 350);
- txt5.setString("Угол поворота = " + angstring.str() + " " + "рад");
- txt5.setPosition(870, 450);
- txt6.setString("Угол поворота = " + angdegstring.str() + " " + "°");
- txt6.setPosition(870, 550);
- txt7.setString("Скорость = " + speedstring.str() + " " + "м/c");
- txt7.setPosition(870, 650);
- if ((x < len * cos(alpha * PI / 180)) && !(Keyboard::isKeyPressed(Keyboard::Space)))
- {
- t = t + 0.01;
- x = ax * t * t / 2;
- y = ay * t * t / 2;
- V = a * t;
- shape.setPosition(indent + (ax * t * t / 2), indent + (ay * t * t / 2));
- angle = E * t * t / 2;
- while (angle > 2 * PI) angle = angle - 2 * PI;
- angle_deg = angle * 180 / PI;
- angle_point.setPosition
- (indent + (ax * t * t / 2) + rad + (rad * cos(angle) / 2) - size_angle_point,
- indent + (ay*t*t/2) + rad + (rad * sin(angle) / 2) - size_angle_point);
- }
- window.clear();
- window.draw(txt1);
- window.draw(txt2);
- window.draw(txt3);
- window.draw(txt4);
- window.draw(txt5);
- window.draw(txt6);
- window.draw(txt7);
- window.draw(shape);
- if(flag_pointer)
- {
- window.draw(angle_point);
- }
- window.draw(line);
- window.display();
- Sleep(10);
- if(Keyboard::isKeyPressed(Keyboard::Escape)) break;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement