이산적 무게중심

473 days ago by namy0727

@interact def moments(Point1 = input_box(default=(3,3)), Mass1 = input_box(default=8), Point2 = input_box(default=(-3,3)), Mass2 = input_box(default=4), Point3 = input_box(default=(-3,-3)), Mass3 = input_box(default=3), Point4 = input_box(default=(3,-3)), Mass4 = input_box(default=3)): pts = [Point1,Point2, Point3, Point4] mass=[Mass1, Mass2, Mass3, Mass4] m = sum(mass) My = [mass[i]*pts[i][0] for i in range(4)]; My = sum(My) Mx = [mass[i]*pts[i][1] for i in range(4)]; Mx = sum(Mx) xbar = My/m ybar = Mx/m xcenter = (xbar,0) ycenter = (0,ybar) center = (xbar,ybar) xmc = point(xcenter,size = 30, color='green') ymc = point(ycenter,size = 30, color='green') mc = point(center,size = 30, color='red') p = Graphics() for k in range(4): p+= point(pts[k],size = 50) txt1 = text('%s'%(Mass1), (pts[0][0]+0.2,pts[0][1]+0.2), fontsize=15) txt2 = text('%s'%(Mass2), (pts[1][0]+0.2,pts[1][1]+0.2), fontsize=15) txt3 = text('%s'%(Mass3), (pts[2][0]+0.2,pts[2][1]+0.2), fontsize=15) txt4 = text('%s'%(Mass4), (pts[3][0]+0.2,pts[3][1]+0.2), fontsize=15) p+= xmc+ymc+mc+txt1+txt2+txt3+txt4 p.show(xmin=-4,xmax=4,ymin=-4,ymax=4, frame =True, gridlines=True, aspect_ratio=1) print "Moment of the system about the y-axis =", My print "Moment of the system about the x-axis =", Mx print "Center of mass =", center 
       
Point1 
Mass1 
Point2 
Mass2 
Point3 
Mass3 
Point4 
Mass4 

Click to the left again to hide and once more to show the dynamic interactive window