Возникла задача несложной инверсной кинематики, над которой я уже бьюсь 3 дня и где-то сильно туплю, поэтому не могу решить.

Имеется манипулятор из трёх плеч длинами

. Есть 2 сустава, которые их крутят. Они обозначены синими кружочками. Есть конечная точка

, которая обозначена красным.
Задача в том, чтобы получить аналитический ответ на вопрос: «какими должны быть углы поворота

, чтобы конечная точка оказалась в заданных, известных декартовых координатах.
Ход моего решения:

Возводим оба уравнения в квадрат и складываем:
![$$
\[p_x^2 = r_1^2 \cos^2 \theta_1 + 2r_1\cos\theta_1(r_2\cos\theta_{12}-r_3\sin\theta_{12}) + r_2^2 \cos^2 \theta_{12} - 2r_2r_3 \cos\theta_{12} \sin \theta_{12} + r_3^2\sin^2\theta_{12}\]
\[p_y^2 = r_1^2 \sin^2 \theta_1 + 2r_1\sin\theta_1(r_2\sin\theta_{12}-r_3\cos\theta_{12}) + r_2^2 \sin^2 \theta_{12} + 2r_2r_3 \sin\theta_{12} \cos \theta_{12} + r_3^2\cos^2\theta_{12}\]
\[p_x^2=r_1^2+r_2^2+r_3^2+2r_1r_2\cos\theta_1\cos\theta_{12}-2r_1r_3\cos\theta_1\sin\theta_{12} + 2r_1r_2\sin\theta_1\sin\theta_{12}+2r_1r_3\cos\theta_{12}\]
$$ $$
\[p_x^2 = r_1^2 \cos^2 \theta_1 + 2r_1\cos\theta_1(r_2\cos\theta_{12}-r_3\sin\theta_{12}) + r_2^2 \cos^2 \theta_{12} - 2r_2r_3 \cos\theta_{12} \sin \theta_{12} + r_3^2\sin^2\theta_{12}\]
\[p_y^2 = r_1^2 \sin^2 \theta_1 + 2r_1\sin\theta_1(r_2\sin\theta_{12}-r_3\cos\theta_{12}) + r_2^2 \sin^2 \theta_{12} + 2r_2r_3 \sin\theta_{12} \cos \theta_{12} + r_3^2\cos^2\theta_{12}\]
\[p_x^2=r_1^2+r_2^2+r_3^2+2r_1r_2\cos\theta_1\cos\theta_{12}-2r_1r_3\cos\theta_1\sin\theta_{12} + 2r_1r_2\sin\theta_1\sin\theta_{12}+2r_1r_3\cos\theta_{12}\]
$$](https://dxdy-04.korotkov.co.uk/f/f/4/4/f44e703a4a7e6f9ef24e83f101deea3682.png)
Заменяем

на

в последнем уравнении, и пользуясь формулами синуса и косинуса суммы получаем:

или

А это стандартное уравнение, решение которого:

где A — коэффициент перед сокинусом, B — перед синусом, C — то, что справа.
Всё,

известна, теперь дело за

. Ещё раз распишем:

Домножаем верхнее на

, а нижнее на

и складываем вместе:

Аналогично, если домножать на

и на

, а затем сложить:

В двух последних полученных уравнениях если первое домножить на

, а нижнее на

и сложить, получим:

Берём аркосинус и та да! Казалось бы оба угла известны, всё лепо. Однако если провести элементарную проверку в экселе, становится понятно, что решение не верно. Например, если проверить координаты:

, т.е. разогнутый сустав, угол

равен -90°, что похоже на правду, но вот

какой-то не адекватный и с изменением параметров положения точки P значение

ведёт себя странно.
Уважаемые форумчане, быть может кто-то увидел ошибку в рассуждениях? Выручайте: мой мозг уже вскипел.