Domanda

Come posso aggiungere una costante accelerazione a questo pendolo nel suo insieme usando questo codice? Il codice in questo momento sta descrivendo un pendolo, come lo modificherei per descrivere un pendolo in un treno in movimento (dove il treno ha un'accelerazione costante)? Qualsiasi aiuto sarebbe apprezzato, grazie in anticipo.

from math import sin, pi

from time import sleep

from turtle import *


GA = 9.80665 # Gravitational Acceleration (meters per second squared)

FORM = 'Time={:6.3f}, Angle={:6.3f}, Speed={:6.3f}'

def main():

    length = 10.0            # Of pendulum (meters)
    ngol = - GA / length    # Negative G over L
    total_time = 0.0        # Seconds
    angle = 1.0             # Initial angle of pendulum (radians)
    speed = 0.0             # Initial angular velocity (radians/second)
    time_step = 0.05        # Seconds
    acc = 1
    while total_time < 30.0:
        total_time += time_step
        speed += ngol * sin(angle) * time_step
        angle += speed * time_step
        #print(FORM.format(total_time, angle, speed))
        if draw(angle, length): break
        sleep(time_step)

def init():

    setup()
    mode('logo')
    radians()
    speed(0)
    hideturtle()
    tracer(False)
    penup()

def draw(angle, length):

    if speed() != 0: return True
    clear()
    setheading(angle + pi)
    pensize(max(round(length), 1))
    pendown()
    forward(length * 25)
    penup()
    dot(length * 10)
    home()
    update()

if __name__ == '__main__':

    init()
    main()
    bye()

Nessuna soluzione corretta

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top