Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- auto findYEllipse(float x)
- {
- const float x0 = -9.5305f;
- const int y0 = -7;
- const int a = 31;
- const int b = 38;
- const int a2 = 961;
- struct r { float yp; float yn; };
- float yOffensive = b * sqrt(1 - (x - x0) * (x - x0) / a2);
- return r{ y0 + yOffensive, y0 - yOffensive };
- };
- auto findYCircle(float x)
- {
- const int x0 = 1;
- const float y0 = 10.9839f;
- const int r2 = 961;
- float yOffensive = sqrt(r2 - (x - x0) * (x - x0));
- struct r { float yp; float yn; };
- return r{ y0 + yOffensive, y0 - yOffensive };
- };
- float rightpoint(float x)
- {
- return (findYCircle(x).yn - findYEllipse(x).yn);
- };
- float leftpoint(float x)
- {
- return (findYCircle(x).yp - findYEllipse(x).yp);
- };
- float recursive(float start, float stop, float step, float accuracy, int divstep, float (*workfunc)(float))
- {
- float prevdiffer = (*workfunc)(start);
- float differ;
- while (true)
- for (float i = (start + step); i <= stop; i += step)
- {
- differ = (*workfunc)(i);
- if (abs(differ) <= accuracy)
- return i;
- if ((prevdiffer > 0) != (differ > 0))
- {
- stop = i;
- start = i - step;
- step /= divstep;
- break;
- }
- else
- prevdiffer = differ;
- };
- };
- float startrecursive(float start, float stop, float step, float accuracy, int divstep, float (*workfunc)(float))
- {
- if (stop < start)
- {
- float t = stop;
- stop = start;
- start = t;
- };
- stop = start + ((int)((stop - start) / step)) * step;
- return recursive(start, stop, step, accuracy, divstep, workfunc);
- };
- int main()
- {
- setlocale(LC_ALL, "RU");
- std::cout << "Выполнил: Ивченко Д.Я. (КЗИ-21-1Б)" << std::endl << std::endl;
- float x = startrecursive(10, 28.45f, 1, 0.0001f, 10, &rightpoint);
- std::cout << "Первая точка: ( " << x << " ; " << findYCircle(x).yn << " )" << std::endl;
- x = startrecursive(-30, 0, 1, 0.0001f, 10, &leftpoint);
- std::cout << "Вторая точка: ( " << x << " ; " << findYCircle(x).yp << " )" << std::endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement