Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Каплун Сергей 1110 Группа 4 задача(графика) вариант №20
- #include <iostream>
- #include <windows.h>
- #include "resource.h"
- #include <stdlib.h>
- # include <math.h>
- #define F 50
- #define g 9.8
- using namespace std;
- int x[F], y[F], t[F];
- double x11[F], y11[F], t11[F];
- double R, v, a0;
- double min1, max2 =2*R, min2, max1 = 0;
- int WINAPI DlgProc(HWND hDlg, WORD wMsg, WORD wParam, DWORD) {
- PAINTSTRUCT ps;
- if (wMsg == WM_CLOSE || wMsg == WM_COMMAND && wParam == IDOK) {
- EndDialog(hDlg, 0);
- }
- else
- if (wMsg == WM_INITDIALOG) {
- RECT rc;
- GetClientRect(hDlg, &rc);
- int dx = rc.right - rc.left;
- int dy = rc.bottom - rc.top;
- min2 = -R;
- min1 = 0;
- for (int i = 0; i < F; i++) {
- if (x11[i] < min2) min2 = x11[i];
- if (x11[i] > max2) max2 = x11[i];
- if (y11[i] < min2) min2 = y11[i];
- if (y11[i] > max2) max2 = y11[i];
- if (t11[i] < min1) min1 = t11[i];
- if (t11[i] > max1) max1 = t11[i];
- }
- for (int i = 0; i < F; i++) {
- x[i] = (int)((x11[i] - min2)*dy / (max2 - min2));
- y[i] = (int)((y11[i] - min2)*dy / (max2 - min2));
- t[i] = (int)((t11[i] - min1)*dx / (max1 - min1));
- }
- }
- else
- if (wMsg == WM_PAINT) {
- BeginPaint(hDlg, &ps);
- HPEN hPenx = (HPEN)CreatePen(PS_SOLID, 1, RGB(0, 0, 255));
- HPEN hPeny = (HPEN)CreatePen(PS_SOLID, 1, RGB(0, 255, 0));
- HPEN hOldPenx = (HPEN)SelectObject(ps.hdc, hPenx);
- POINT ptOld;
- for (int i = 0; i < F - 1; i++) {
- MoveToEx(ps.hdc, t[i], x[i], &ptOld);
- LineTo(ps.hdc, t[i + 1], x[i + 1]);
- }
- HPEN hOldPeny = (HPEN)SelectObject(ps.hdc, hPeny);
- for (int i = 0; i < F - 1; i++) {
- MoveToEx(ps.hdc, t[i], y[i], &ptOld);
- LineTo(ps.hdc, t[i + 1], y[i + 1]);
- }
- SelectObject(ps.hdc, hOldPenx);
- DeleteObject(hPenx);
- SelectObject(ps.hdc, hOldPeny);
- DeleteObject(hPeny);
- EndPaint(hDlg, &ps);
- }
- return 0;
- }
- void main() {
- double a[F];
- double J,w,m,R,E,dt,v;
- cout << "vvedite nachalnii ugol,massu,radius,vremya" << endl << flush;
- cin >> a[0]>>m>>R>>v;
- dt = v / F;
- J = m*R*R;
- E = -m*g*R*sin(a[0]) / J;
- w = 0;
- t11[0] = 0;
- x11[0] = R*sin(a[0]);
- y11[0] = R - R*cos(a[0]);
- for (int i = 1; i < F; i++) {
- a[i] = a[i - 1] + w*dt + E*dt*dt / 2;
- w = w + E*dt;
- if (a[i] > 0) E = -1 * m*g*R*sin(a[i]) / J;
- if (a[i] == 0) E = 0;
- else E = m*g*R*sin(a[i]) / J;
- x11[i] = R*sin(a[i]);
- y11[i] = R - R*cos(a[i]);
- t11[i] = i*dt;
- }
- DialogBox(NULL, MAKEINTRESOURCE(IDD_DIALOG1), NULL, (DLGPROC)DlgProc);
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement