[PYTHON] Maybe it can be recursed

at first

I wrote an article about kinematics itself before, but when I was thinking that there was a wise way to write it when dealing with the n-axis, I thought that it might be possible to recurse.

Processing that you want to recurse

arm.py


    x1 = L1 * np.cos(deg1)
    y1 = L1 * np.sin(deg1)
    x2 = x1 + L2 * np.cos(deg1+deg2)
    y2 = y1 + L2 * np.sin(deg1+deg2)
    x3 = x2 + L3 * np.cos(deg1+deg2+deg3)
    y3 = y2 + L3 * np.sin(deg1+deg2+deg3)

There is no atmosphere that seems to be recursion ???

I tried to recurse

arm.py


def test(x,y,deg,L,n):
    if n < len(x)-1:
        x[n] = L[n]*math.cos(deg[n]) + x[n-1]
        y[n] = L[n]*math.sin(deg[n]) + y[n-1]
        return test(x,y,deg,L,n+1)
    elif n >= len(x)-1:
        x[n] = L[n]*math.cos(deg[n]) + x[n-1]
        y[n] = L[n]*math.sin(deg[n]) + y[n-1]
        return x,y

_x = [0]*3
_y = [0]*3
deg = [0.0,math.pi*0.5,0.0]
L = [1,1,1]

print(test(_x,_y,deg,L,0))

([1.0, 1.0, 2.0], [0.0, 1.0, 1.0])

I had a hard time unexpectedly, but it took shape.

Recommended Posts

Maybe it can be recursed
It seems that Skeleton Tracking can be done with RealSense
Can I be a data scientist?
Maybe it works! Let's try scraping!
"Obake" can be sung by "you"
requirements.txt can be commented out with #
Confirmation that rkhunter can be installed