Created
November 2, 2019 10:20
-
-
Save hugo4715/5422799302cc807526410d29a86b2b14 to your computer and use it in GitHub Desktop.
sin matplotlib
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import matplotlib | |
import numpy as np | |
import matplotlib.pyplot as plt | |
fig = plt.figure() | |
ax1 = fig.add_subplot(111) | |
increment = 0.01 | |
# affichage du sin | |
t = np.arange(0, 10.0, increment) | |
s1 = np.sin(t) | |
ax1.set_xlabel('time (s)') | |
ax1.set_ylabel('sin') | |
ax1.plot(t, s1, 'b-') | |
for i in range(0, 10, 2): | |
rx = i# + random.random() | |
# affichage du haut du rayon | |
ry = s1[(int)(rx/increment)] | |
line = matplotlib.pyplot.Line2D([rx, rx], [2,ry], color=[1,0,0,1]) | |
ax1.add_line(line) | |
# affichage du rebond | |
pente = np.cos(rx) | |
print("cos(" + str(rx) + " )=" + str(pente)) | |
vec1 = np.array([0, 0, -1]) | |
vec2 = np.array([1, pente, 0]) | |
result = np.cross(vec2, vec1) | |
print(result) | |
rebond = matplotlib.pyplot.Line2D([rx, rx + result[0]], [ry, ry + result[1]], color=[1, 0, 0, 1]) | |
# Affichage de la tangente en rx | |
t2 = np.arange(rx-.5, rx+.5, .1) | |
lignePente = pente*t2 - rx*pente + ry | |
ax1.plot(t2, lignePente, 'g-') | |
ax1.plot([rx+vec2[0]], [ry+vec2[1]], 'y.') | |
ax1.plot([rx+result[0]], [ry+result[1]], 'y.') | |
ax1.add_line(rebond) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment