circlesSoluce.py

#
# PYTHON for DUMMIES 23-24 
# Problème 1
#
# Un cercle roule sans glisser autour d'un autre cercle.
#
# Vincent Legat 
# (avec l'aide bienveillante de copilotes anonymes)
#
# -------------------------------------------------------------------------
# 

import numpy as np

# ============================================================
# FONCTIONS A MODIFIER [begin]
#
# -1- Création d'un cercle... 
#     radius : rayon du cercle
#     n : nombre de points répartis entre [0,2*pi] pour tracer le cercle
#     il y aura donc n-1 arcs de cercles :-)
#          
#     theta : tableau numpy contenant les angles pour chaque point
#     x,y : tableaux numpy contenant les coordonnées x,y pour chaque point
#

def circlesCreate(radius,n) :
    theta = np.linspace(0,2*np.pi,n)
    x = radius * np.cos(theta)
    y = radius * np.sin(theta)
    return theta,x,y

#
# -2- Calcul des angles où le petit cercle aura retrouvé sa position initiale
#     ratio : rapport entre le rayon du cercle intérieur et le rayon du cercle extérieur
#          
#     thetas : tableau numpy contenant les angles où le cercle intérieur aura retrouvé sa position initiale


def circlesAngles(ratio) :
    thetas = np.zeros(ratio+1)
    for i in range(0,ratio+1) :
        thetas[i] = 2 * np.pi * i / (ratio+1)
    return thetas
#
# -3- Animation des deux cercles...
#     theta : angle du point de contact du petit cercle avec le grand cercle
#     x_rolling,y_rolling : tableaux numpy contenant les coordonnées x,y pour les points du cercle roulant
#     ratio : rapport entre le rayon du cercle intérieur et le rayon du cercle extérieur
#
#     x,y : tableaux numpy contenant les coordonnées x,y pour les points du cercle roulant pour l'angle theta
#

def circlesAnimate(theta,x_rolling,y_rolling,ratio) :
    x_rotated = x_rolling * np.cos(theta*ratio) - y_rolling * np.sin(theta*ratio)
    y_rotated = x_rolling * np.sin(theta*ratio) + y_rolling * np.cos(theta*ratio)
    x_rotated = x_rotated + (ratio + 1.0)

    x = x_rotated * np.cos(theta) - y_rotated * np.sin(theta)
    y = x_rotated * np.sin(theta) + y_rotated * np.cos(theta)
    return x,y

#
#
# FONCTIONS A MODIFIER [end]
# ============================================================
#