Skip to content

Instantly share code, notes, and snippets.

# pozitron57/ftr-a-mu.py

Created February 7, 2022 20:04
Plot friction force vs. angle
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 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 ) def arctg(x): return np.degrees( np.arctan(x) ) def sins(x): return round( np.sin( np.radians(x) )**2, 10 ) def asin(x): return np.degrees( np.arcsin(x) ) #}}} def sqrt(x): return x**(1./2) # Plot setup {{{ from matplotlib import pyplot as plt from matplotlib import rc, rcParams rcParams['font.size'] = 20. rcParams['text.usetex'] = True #rc('text.latex', preamble=r'\usepackage{esvect}') rcParams['font.sans-serif'] = ['Computer Modern'] rc('text.latex', preamble=r'\usepackage[T2A]{fontenc} \usepackage[utf8]{inputenc} \usepackage{bm}') #rc('text.latex', preamble=r'\usepackage[utf8]{inputenc}') rc('axes', linewidth=1.2) rc('xtick.major', size=4, width=1.1) rc('ytick.major', size=4, width=1.1) 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.5, 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) # Add mu=... to the legend ax.plot([], [], ' ', label='$\\mu={}$'.format("{:.2f}".format(mu) ) ) # 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) plt.savefig('plots/' + str(mu)+'.pdf', bbox_inches='tight') plt.cla() #plt.show() # convert -delay 0.01 -loop 0 *.pdf ftr_a_mu.gif
to join this conversation on GitHub. Already have an account? Sign in to comment