-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmass.py
More file actions
56 lines (49 loc) · 1.29 KB
/
Copy pathmass.py
File metadata and controls
56 lines (49 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
def calculateMass(vertices, triangles, DENSITY=''):
#INSERT A PLANET/OBJECT TYPE DICTIONARY HERE
#--
#name of planet type or manmade object : density
#--
#these would be like planets being gas giants, hard rock
#life supporting, ice, etc. We can research densities
#accordingly.
#for now, density = 5.514e+12 kg/km^3, which is earth's density
DENSITY = 5.514*(10**12)
totalVolume = 0
for tri in range(len(triangles)):
ind0,ind1,ind2 = vertices[triangles[tri][2]],vertices[triangles[tri][1]],vertices[triangles[tri][0]]
x1,y1,z1 = ind0[0],ind0[1],ind0[2]
x2,y2,z2 = ind1[0],ind1[1],ind1[2]
x3,y3,z3 = ind2[0],ind2[1],ind2[2]
totalVolume += abs((1/6) * ( -(x3*y2*z1)+(x2*y3*z1)+(x3*y1*z2)-(x1*y3*z2)-(x2*y1*z3)+(x1*y2*z3) ))
mass = abs(totalVolume)*DENSITY
print(mass)
return mass
##
##vertices = (
## (1, -1, -1),
## (1, 1, -1),
## (-1, 1, -1),
## (-1, -1, -1),
## (1, -1, 1),
## (1, 1, 1),
## (-1, 1, 1),
## (-1, -1, 1)
## )
##
##tris = (
## (0,1,2),
## (0,3,2),
## (0,4,5),
## (0,1,5),
## (0,4,7),
## (0,3,7),
## (6,2,1),
## (6,5,1),
## (6,2,3),
## (6,7,3),
## (6,7,4),
## (6,5,4)
## )
##
##
##calculateMass(vertices,tris)