plt.style.use('seaborn-whitegrid')# global style for plotting
classSuspendedObjectLab:
"""
This class embeds all the necessary code to create a virtual lab to study the static equilibrium of an object suspended on a clothesline with a counterweight.
#plt.ioff() # deactivate interactive mode until we actually decide to show it
#plt.clf() # clear any previously drawn figure
# Create the figure and subplots in it
self.fig=plt.figure(num='Suspended Object Lab',constrained_layout=False,figsize=(10,4))# hack for interactive backend: num is the title which appears above the canvas
# Let's check that there is actually a counterweight
ifm_counterweight>0:
# Then we compute the ratio of masses
ratio=0.5*self.m_object/m_counterweight
# Check that the ratio of masses is in the domain of validity of arcsin ([-1;1])
ifabs(ratio)<1:
alpha=np.arcsin(ratio)
returnmin(alpha_default,alpha)
defget_object_coords(self,angle):
"""
Computes the position of the object on the cable taking into account the angle determined by the counterweight and the dimensions of the hanging system.
By default:
- the object is supposed to be suspended exactly in the middle of the cable
- the object is on considered the ground for all values of the angle
:angle: angle that the cable makes with the horizon
:returns: coordinates of the point at which the object are hanged
"""
# the jean is midway between the poles
x_object=self.x_origin+0.5*self.distance
# default y value: the jean is on the ground
y_object=self.y_origin
# we check that the angle is comprised between horizontal (greater than 0) and vertical (smaller than pi/2)
ifangle>0andangle<(np.pi/2):
# we compute the delta between the horizon and the point given by the angle
delta=(0.5*self.distance*np.tan(angle))
# we check that the delta is smaller than the height of the poles (otherwise it just means the jean is on the ground)
ifdelta<=self.height:
y_object=self.y_origin+self.height-delta
return[x_object,y_object]
# Event handler
defm_counterweight_event_handler(self,change):
self.m_counterweight=change.new
# Compute new values with the counterweight selected by the user