Considera el reloj representado en la siguiente imagen.
En lugar de un reloj estándar, que tiene manecillas de hora y minutos independientes, este reloj conecta la manecilla de minutos al final de la manecilla de la hora. Aquí hay un video que muestra el movimiento del reloj acelerada:
from IPython.display import YouTubeVideo
YouTubeVideo("bowLiSlm_gA",width=640,height=360, mute=1)
El siguiente código es un reloj tradicional animado que utiliza la función como un truco para animar cosas en jupyter:
%matplotlib inline
import matplotlib.pylab as plt
from IPython.display import display, clear_output
import time
def show_animation(delay=0.01):
fig = plt.gcf();
time.sleep(delay) # Sleep for half a second to slow down the animation
clear_output(wait=True) # Clear output for dynamic display
display(fig) # Reset display
fig.clear() # Prevent overlapping and layered plots
Permite ver un reloj analógico estándar funcionando a alta velocidad
import numpy as np
'''
Analog clock plotter with time input as seconds
'''
def analog_clock(tm=0):
#Convert from time to radians
a_minutes = -tm/(60*60) * np.pi * 2
a_hours = -tm/(60*60*12) * np.pi * 2
#Define clock hand sizees
d_minutes = 4
d_hours = 3
arrow_width=0.5
arrow_length=1
# Set up figure
fig = plt.gcf()
ax = fig.gca();
ax.set_xlim([-15,15]);
ax.set_ylim([-10,10]);
ax.scatter(0,0, s=15000, color="navy"); #Background Circle
plt.axis('off');
# Calculation Minute hand transformation matrix
J2 = np.matrix([[np.cos(a_minutes), -np.sin(a_minutes)],
[np.sin(a_minutes), np.cos(a_minutes)]] )
pm = np.matrix([[0,d_minutes], [-arrow_width,d_minutes], [0,arrow_length+d_minutes], [arrow_width,d_minutes], [0,d_minutes]] ).T;
pm = np.concatenate((J2*pm, np.matrix([0,0]).T), axis=1 );
ax.plot(pm[0,:].tolist()[0],(pm[1,:]).tolist()[0], color='cyan', linewidth=2);
# Calculation Hour hand transformation matrix
J1 = np.matrix([[np.cos(a_hours), -np.sin(a_hours)],
[np.sin(a_hours), np.cos(a_hours)]] )
ph = np.matrix([[0,d_hours], [0,d_hours], [-arrow_width,d_hours], [0,arrow_length+d_hours], [arrow_width,d_hours], [0,d_hours]]).T;
ph = np.concatenate((J1*ph, np.matrix([0,0]).T), axis=1 );
ax.plot(ph[0,:].tolist()[0],(ph[1,:]).tolist()[0], color='yellow', linewidth=2);
#Run the clock for about 5 hours at 100 times speed so we can see the hands move
for tm in range(0,60*60*5, 100):
analog_clock(tm);
show_animation();
# 'Run' this cell to see the animation
Para las siguientes preguntas, considere la matriz de transformación\(J_1\) redefinida a continuación con un ángulo de 5 horas sobre 12.
Usando código, mostrar que la transposición de\(J_1\) es también la inversa de\(J_1\), luego explicar cómo el código demuestra la respuesta.
#Put your answer here
Pregunta
Dada la identidad trigonométrica\(cos^2(\theta) + sin^2(\theta) = 1\), demuestre por construcción —usando Python o LateX/ Markdown o sympy (si te sientes aventurero )— que la transposición de la\(J_1\) matriz es también la inversa para CUALQUIER ángulo a_horas\(\in[0,2\pi]\).
Ahora considere el siguiente código que intenta conectar las manecillas del reloj juntas para hacer el Reloj Odd que se muestra en el video de arriba.
import numpy as np
def odd_clock(tm=0):
#Convert from time to radians
#a_seconds = -tm/60 * np.pi * 2
a_minutes = -tm/(60*60) * np.pi * 2
a_hours = -tm/(60*60*12) * np.pi * 2
#Define robot geomitry
#d_seconds = 2.5
d_minutes = 2
d_hours = 1.5
arrow_width=0.5
arrow_length=1
# Set up figure
fig = plt.gcf()
ax = fig.gca();
ax.set_xlim([-15,15]);
ax.set_ylim([-10,10]);
plt.axis('off');
#Define the arrow at the end of the last hand
#p = np.matrix([[0,d_minutes,1], [0,0,1]]).T
p = np.matrix([[0,d_minutes,1], [-arrow_width,d_minutes,1], [0,arrow_length+d_minutes,1], [arrow_width,d_minutes,1 ], [0,d_minutes,1 ], [0,0,1]] ).T;
# Calculation Second hand transformation matrix
J2 = np.matrix([[np.cos(a_minutes), -np.sin(a_minutes), 0 ],
[np.sin(a_minutes), np.cos(a_minutes), d_hours ],
[0, 0, 1]])
p = np.concatenate((J2*p, np.matrix([0,0,1]).T), axis=1 )
J1 = np.matrix([[np.cos(a_hours), -np.sin(a_hours), 0 ],
[np.sin(a_hours), np.cos(a_hours), 0 ],
[0, 0, 1]])
p = np.concatenate((J1*p, np.matrix([0,0,1]).T), axis=1 )
ax.scatter(0,0, s=20, facecolors='r', edgecolors='r')
ax.plot(p[0,:].tolist()[0],(p[1,:]).tolist()[0])
#Run the clock for about 5 hours at 100 times speed so we can see the hands move
for tm in range(0,60*60*5, 100):
odd_clock(tm);
show_animation();
# 'Run' this cell to see the animation
Pregunta
Usando el punto (\(p\)) dado escrito en coordenadas de “minutos” (en la línea 26 del código anterior) y las matrices de transformación anteriores (\(J_1\),\(J_2\)), anote la ecuación para\(p\) transformarla en coordenadas mundiales\(p_w\).
Pregunta
Observe que la función odd_clock anterior tiene variables d_seconds y a_seconds comentadas. Use estas variables y modifique el código anterior para agregar una manecilla de “segundos” en la punta de la manecilla de minutos de tal manera que la manecilla de segundos se mueva alrededor de la manecilla de minutos al igual que la manecilla de minutos Si tienes problemas, usa la siguiente celda para explicar tu proceso de pensamiento y dónde te estás quedando atascado.