Writing the following equations using numpy

Viewed 40

I want to ensure that I wrote the equations correctly because I still get the wrong results. My code:

def transformation_coord(x, y, l, r):
"""

:param x: x-coordination
:param y: y-coordination
:param l: l=4 is the length of the line
:param r: r=3 is radius
:return:
"""
x_trans = None
y_trans = None
# Equation 2
if x < 0:
    arccos_val = (r - y) / math.sqrt(((x - l) ** 2) + ((y - r) ** 2))
    x_trans = (2 * l) + (r * math.pi) + (r * math.acos(arccos_val))
elif 0 <= x <= l and y < r:
    x_trans = x
elif 0 <= x <= l and y >= r:
    x_trans = (2 * l) + (r * math.pi) - x
elif x > l:
    arccos_val = (r - y) / math.sqrt((x ** 2) + ((y - r) ** 2))
    x_trans = l + (r * math.acos(arccos_val))

# Equation 2
if x < 0:
    y_trans = math.sqrt((x ** 2) + ((y - r) ** 2)) - r
elif 0 <= x <= l:
    y_trans = math.sqrt(((y - r) ** 2)) - r
elif x > l:
    y_trans = math.sqrt(((x - l) ** 2) + ((y - r) ** 2)) - r

return x_trans, y_trans

The equations: enter image description here

The following mathematical equations are written as they should be The x and y coordination: enter image description here

The transformed coordination (expected results): enter image description here

What I got: enter image description here

0 Answers
Related