from visual import * from __future__ import division # Input 3x3 matrix temp1 = raw_input ("Enter first row seperated by spaces ") temp2 = raw_input("Enter second row seperated by spaces ") temp3 = raw_input("Enter third row seperated by spaces ") row = [[0,0,0],[0,0,0],[0,0,0]] row[0] = temp1.split() row[1] = temp2.split() row[2] = temp3.split() fluxsum =0 print row #Convert the matrix to integers and find the sum of the elements for a in range(0,3): for b in range(0,3): row[b][a] = int(row[b][a]) fluxsum += row[b][a] #Calculate scale and draw spheres scale = fluxsum for a in range(0,3): for b in range(0,3): sphere(pos = (a*scale,-b*scale,0), radius = row[b][a], color = color.yellow) scene.center = (scale,-scale,0) #Calculate the center of mass xcom = ((row[0][2]+row[1][2]+row[2][2])-(row[0][0]+row[1][0]+row[2][0]))/fluxsum ycom = (row[0][0]+row[0][1]+row[0][2] - (row[2][0]+row[2][1]+row[2][2]))/fluxsum #Draw sphere at center of mass sphere(pos = (scale*(1+xcom),scale*(ycom-1),0), radius = scale/4.5, color = color.red) print xcom,ycom