Cykloida na cykloidzie

0

Witam,

Muszę napisać program który rysuje cykloidę na cykloidzie. Coś w tym stylu:

https://www.geogebra.org/m/hzdcNSU6?fbclid=IwAR2r_BfaDhpC1rExIcxeghlO-4zAZcYv8L_U-hw0-oimerLMabqPMEOhTFs

Tylko krzywą jest cykloida.

Mam taki wstępny program,


import numpy as np
import matplotlib.pyplot as plt
import math

from matplotlib import animation

#r = float(input('write r\n'))
#R = float(input('write R\n'))
r = 1
R  = 1
x  = []
y  = []
x2 = []
y2 = []
x3 = []
y3 = []

length=[0]

fig, ax = plt.subplots()
ln, = plt.plot([], [], 'r', animated=True)
f = np.linspace(0, 10*r*math.pi, 1000)


def init():
ax.set_xlim(-r,  12*r*math.pi)
ax.set_ylim(-4*r, 4*r)
return ln,

def update2(frame):
    #parametric equations of cycloid
    x0 = r * (frame - math.sin(frame))
    y0 = r * (1 - math.cos(frame))
    x.append(x0)
    y.append(y0)

#derivative of cycloid
dx = r * (1 - math.cos(frame))
dy = r * math.sin(frame)

#center of circle
a = dy * dy + dx * dx
b = (-2 * x0 * dy) - (2 * frame * dy * dy) + (2 * y0 * dx) - (2 * frame * dx * dx)
c = (x0 * x0) + (2 * frame * x0 * dy) + (frame * frame * dy * dy) + (y0 * y0) - (2 * frame * y0 * dx) + (frame * frame * dx * dx) -1
t1 = (-b - math.sqrt(b * b - 4 * a * c)) / (2 * a)
#t2 = (-b + math.sqrt(b * b - 4 * a * c)) / (2 * a)

center1x=(x0-dy*(t1-x0))*R
center1y=(y0+dx*(t1-x0))*R
#center2x=(x0-dy*(t2-x0))*R
#center2y=(y0+dx*(t2-x0))*R

#length of cycloid
length.append(math.sqrt(x0*x0 + y0*y0))
dl=sum(length)
param = dl / R

W1x = center1x + R * math.cos(-param)
W1y = center1y + R * math.sin(-param)
#W2x = center2x + R * math.cos(-param)
#W2y = center2y + R * math.sin(-param)

x2.append(W1x)
y2.append(W1y)
#x3.append(W2x)
#y3.append(W2y)

ln.set_data([x, x2], [y, y2])
return ln,


ani = animation.FuncAnimation(fig, update2, frames=f,init_func=init, blit=True, interval = 0.1, repeat = False)
plt.show()

Jak to narysować?

Pozdrawiam

1

Chodzi o narysowanie cykloidy na cykloidzie. Typowa cykloida jest rysowana na linii prostej a mu chodzi o narysowanie jej na krzywej (na drugiej cykloidzie).

1 użytkowników online, w tym zalogowanych: 0, gości: 1