diff options
author | hanemile <emile.hansmaennel@gmail.com> | 2018-03-19 20:47:13 +0100 |
---|---|---|
committer | hanemile <emile.hansmaennel@gmail.com> | 2018-03-19 20:47:13 +0100 |
commit | d0f19b8bc7ab11449cea028106504cacecd94f66 (patch) | |
tree | 8ce0c9298694554a46545731c949fb18332669cb /src/python/spiral | |
parent | 996e5529f566d7c64763c47348fc68fae51ef6a4 (diff) |
cleaned up
Diffstat (limited to 'src/python/spiral')
-rwxr-xr-x | src/python/spiral/average_force.py | 109 | ||||
-rwxr-xr-x | src/python/spiral/cells.py | 62 |
2 files changed, 171 insertions, 0 deletions
diff --git a/src/python/spiral/average_force.py b/src/python/spiral/average_force.py new file mode 100755 index 0000000..a3a3146 --- /dev/null +++ b/src/python/spiral/average_force.py @@ -0,0 +1,109 @@ +#!/usr/bin/env python + +# import stuff +import sys +import matplotlib.pyplot as plt +import numpy as np +import time +from subprocess import call + +# define from where to get the star data +path = "stars/" + sys.argv[1] + ".csv" + +# define a list to store the coordinates +listx = [] +listy = [] +listz = [] +list_force = [] + +# define constants +G = 6.674e-11 + +def glaw(m1, m2, a1, b1): + a = m1 * m2 + b = np.power(a1 - b1, 2) + c = np.sqrt(b) + d = a / c + e = G * d + return e + +# start the timer +start = time.time() + +# open the data file +with open(path) as f: + + # read the individial lines from the data file + data = f.readlines() + + # for each line + for i in range(0, len(data)): + + # parse the first value in each line + v_i_x = data[i].split(", ")[0] + v_i_y = data[i].split(", ")[1] + v_i_z = data[i].split(", ")[2] + + print("{:20}{:20}{:20}".format("v_i_x", "v_j_x", "v_f_x")) + # print it + # print("{:20}{:20}{:20}".format(v_i_x, v_i_y, v_i_z)) + + # append it to lista for further usage + listx.append(v_i_x) + listy.append(v_i_y) + listy.append(v_i_z) + + for j in range(0, len(data)): + v_j_x = data[j].split(", ")[0].strip("\n") + v_j_y = data[j].split(", ")[1].strip("\n") + v_j_z = data[j].split(", ")[2].strip("\n") + + if(v_j_x != v_i_x): + pv_f_x = glaw(int(1), int(2), float(v_i_x), float(v_j_x)) + print("{:20}{:20}{:20}".format(v_i_x.strip("\n"), v_j_x, v_f_x)) + + if(v_j_y != v_i_y): + v_f_y = glaw(int(1), int(2), float(v_i_y), float(v_j_y)) + print("{:20}{:20}{:20}".format(v_i_y.strip("\n"), v_j_y, v_f_y)) + + if(v_j_z != v_i_z): + v_f_z = glaw(int(1), int(2), float(v_i_z), float(v_j_z)) + print("{:20}{:20}{:20}".format(v_i_z.strip("\n"), v_j_z, v_f_z)) + + + print("---\n") + +print("") +end = time.time() +whole_time = end - start +out = ">> Finished calculating the forces in " + str(whole_time) + " seconds\n" +print(out) + +try: + call(["telegram-send", "--pre", str(out) ]) +except Exception: + print("Failed to send telegram message D:") + + +# # initialize some variables +# sum_a = 0 +# avarage_a = 0 +# +# # calculate the average value +# for i in range(0, 40): +# sum_a += float(lista[i]) +# +# # calculate the average +# avarage_a = sum_a / 40 +# +# # print the average +# print("avarage_a: " + str(avarage_a)) + +# sort lista and store the result in listb +# listb = sorted(lista) + +# plot listb using a normal line, red color and round markers +# plt.plot(lista, "-ro") + +# dispaly the plot +# plt.show() diff --git a/src/python/spiral/cells.py b/src/python/spiral/cells.py new file mode 100755 index 0000000..3304296 --- /dev/null +++ b/src/python/spiral/cells.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python + +import numpy as np +from numpy import genfromtxt +import json +import bpy +import time +import sys + +num = 100 # number of stars that should be generated +range_max = 10 # define the range in which the coordinates should be generated +axes = 3 # define the number of axes +data = "galaxy" # define the name of the galaxy +path = "cell_stars/1.csv" # define the path where the galaxy should be saved + +# generate random coordinates +# rand_a = (np.random.rand(num, axes) * 2 * rand_range) - rand_range + + +for i in range(0, num, 1): + + # generate the random star-coordinates + x = np.random.uniform(-range_max, range_max, size=1) + y = np.random.uniform(-range_max, range_max, size=1) + z = np.random.uniform(-range_max, range_max, size=1) + + with open(path, "a") as star_data: + x_a = str(float(x)) + ", " + y_a = str(float(y)) + ", " + z_a = str(float(z)) + + star_data.write(x_a + y_a + z_a + "\n") + +for data in path: + verts = genfromtxt(path, delimiter=', ', skip_header=0, usecols = (0, 1, 2)) + + # create mesh and object + mesh = bpy.data.meshes.new(data) + object = bpy.data.objects.new(data,mesh) + + # set mesh location + object.location = bpy.context.scene.cursor_location + bpy.context.scene.objects.link(object) + + # create mesh from python data + mesh.from_pydata(verts,[],[]) + mesh.update(calc_edges=True) + + bpy.ops.object.select_all(action='SELECT') + +# parsed_json = json.loads(stars) +# print(parsed_json["s1"]) +# +# +# # The Vector array contains vectors describing forces acting inside the cells. +# cell_num = 3 # number of cells +# +# vector_arr = np.zeros((cell_num, cell_num, cell_num)) +# +# vector_arr[0][1][2] = Vector(1, 2, 3) +# +# print(vector_arr[0]) |