An example of the problem is this:
I have the coordinates of the starting point of the R line on the second image and i have it's direction, i also have the distance of the m1 line and its direction relative to the R line, and i used a formula to calculate the coordinates of the endpoint of the m1 line:
x' = x + (d * cos(a))
y' = y + (d * sin(a))
where x and y are the coordinates of the R starting point and x' and y' are the calculated ending coordinates of m1 and a is the angle the m1 line makes with the horizontal axis, it works if the angle is an acute angle, that is it gives a positive coordinate, but fails if larger than an acute angle as one of the coordinates x' or y' turns up as negative because of the sin(a) or cos(a) and there is no negative pixel coordinate on an image.
Like i just want to find the line (ending coordinates) from R to M1 in the second image as it is in the first image taking into account the rotation of the Reference line.