Last active
June 8, 2025 14:10
-
-
Save pozitron57/a332460837a1ab289b4c3d4fc76d0e82 to your computer and use it in GitHub Desktop.
Plot friction force vs. angle
This file contains hidden or 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 numpy as np | |
# Triginometry {{{ | |
def cos(x): return round( np.cos( np.radians(x) ), 10 ) | |
def sin(x): return round( np.sin( np.radians(x) ), 10 ) | |
def tg(x): return round( np.tan( np.radians(x) ), 10 ) | |
#}}} | |
# Plot setup {{{ | |
from matplotlib import pyplot as plt | |
from matplotlib import rc, rcParams | |
rcParams['font.size'] = 20. | |
rc('axes', linewidth=1.2) | |
rc('xtick.major', size=4, width=1.1) | |
rc('ytick.major', size=4, width=1.1) | |
plt.rcParams.update({ | |
"text.usetex": False, | |
"mathtext.fontset": "custom", | |
"mathtext.it": "STIX Two Text:italic", | |
"mathtext.rm": "STIX Two Text", | |
"mathtext.sf": "STIX Two Text", | |
"font.sans-serif": "STIX Two Text", | |
}) | |
fig, ax = plt.subplots(figsize=(8,8)) | |
fig.subplots_adjust(left=.15, bottom=.15, right=.95, top=.83) | |
#}}} | |
# Initial parameters (SI units) | |
m = 1 | |
g = 10 | |
mu = tg(35) | |
alpha = np.linspace(0, 90, 1500) | |
mus = np.linspace(0, 1.0, 500) | |
for mu in mus: | |
Ftr=[] | |
for a in alpha: | |
if mu > tg(a): | |
Ftr = np.append(Ftr, m*g*sin(a)) | |
else: | |
Ftr = np.append(Ftr, mu*m*g*cos(a)) | |
ax.set_xlim([0,90]) | |
ax.set_ylim([0,10.5]) | |
ax.set_xlabel('$\\alpha$ [$^{\\circ}$]') | |
#ax.set_ylabel('$F_\\textrm{тр}$ [\\textrm{Н}]') | |
#ax.plot(alpha, Ftr, lw=2.5, label='$F_\\textrm{тр}$', zorder=4) | |
ax.set_ylabel(r'$F_{\rm тр}$ [Н]') | |
ax.plot(alpha, Ftr, lw=2.5, label=r'$F_{\rm тр}$', zorder=4) | |
# Add mu=... to the legend | |
#ax.plot([], [], ' ', label='$\\mu={}$'.format("{:.2f}".format(mu)).replace('.', '{,}') ) | |
ax.plot([], [], ' ', label='$~$' ) | |
ax.text(23, 11.281, '$\\mu={}$'.format("{:.2f}".format(mu)).replace('.', '{,}'), zorder=99 ) | |
# Plot full mgsina | |
Ftr=[] | |
for a in alpha: | |
Ftr = np.append(Ftr, m*g*sin(a)) | |
ax.plot(alpha, Ftr, ':', label='$mg\\sin{\\alpha}$', c='orange') | |
# Plot full μmgcosa | |
Ftr=[] | |
for a in alpha: | |
Ftr = np.append(Ftr, mu*m*g*cos(a)) | |
ax.plot(alpha, Ftr, '--', label='$\\mu mg\\cos{\\alpha}$', c='green') | |
ax.set_axisbelow(True) | |
ax.grid() | |
ax.legend(loc='upper center', bbox_to_anchor=(0.5, 1.23), shadow=True, ncol=2, handlelength=1.5) | |
plt.savefig('plots/' + str(mu)+'.png', dpi=303, bbox_inches='tight') | |
plt.cla() | |
## Then create video using ffmpeg: | |
# ffmpeg -framerate 30 -pattern_type glob -i "*.png" -c:v libx264 -r 30 -pix_fmt yuv420p output.mp4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment