Connecting Rod Mechanism in Python

 In this blog we will learn how to make connecting rod mechanism in  python 

from matplotlib.pyplot import *

from numpy import *

from ipywidgets import interactive

def f(theta): # creating a function that give angle to crank

    xa= 0 # starting point of x cordinate of crank

    ya = 0 # starting point of y cordinate of crank

    xb = 5*cos(radians(theta)) # ending/starting point of x cordinate of crank/connecting rod

    yb = 5*sin(radians(theta))  # ending/starting point of y cordinate of crank/connecting rod

    xc = xb + sqrt(10**2-yb**2) # ending x cordinate of connecting rod

    yc =0 # ending y cordinate of connecting rod

    x =([xa,xb,xc]) 

    y =([ya,yb,yc])

    xlabel ('x cordinate')

    ylabel('y cordinate')

    title('connecting rod mechanism in python')

    plot(x,y)

    axis('equal') #make length  x and y coordinate equal

    print('distance of piston from crankshaft is ',xc)

interactive_plot = interactive(f,theta=(0,360))

interactive_plot


video link :


you can also plot velocity and acceleration diagram in python  as well i will update the code soon


Post a Comment

0 Comments