'Calculate Point position relative to origin when image is rotated

I have a robot-arm here with a camera attached. The camera is fixed to the arm and takes photos in the arms rotation / position. I use opencv to detect certain points within the image and need to translate my detected coordinates back to the coordinate system of my robot-arm. (To move over them) I'm struggling to figure out how to transform my points (all the given information is: Origin of my arms coordinate system, arm position and point position inside the image) Here is an image (hopefully) explaining what I want to achieve:

Robo Arm Image

In Addition I need to subtract X units from my arms length, since the pickup tool is on the tip of the arm and the camera before it. This however should be possible by transforming the coordinates to angle+length, subtracting X and transforming them back.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source