30.01.2020
Aktueller Code für Blender 3D:
import bpy from random import * from math import * class Sphere: def __init__(self, pos, radius): self.pos = pos self.radius = radius def punktInKugel(self, p): if (abstandPunkte(self.pos,p) < self.radius): print(">> Punkt in Kugel") else: print(">> Punkt außerhalb Kugel") def abstandPunkte(p1,p2): a = sqrt(((p1[0]-p2[0])**2) + ((p1[1]-p2[1])**2) + ((p1[2]-p2[2])**2)) return a def genPunkt(pos): verts = [(0.1,0.1,0.1),(-0.1,0.1,0.1),(-0.1,-0.1,0.1),(0.1,-0.1,0.1) ,(0.1,0.1,-0.1),(-0.1,0.1,-0.1),(-0.1,-0.1,-0.1),(0.1,-0.1,-0.1)] faces = [(0,1,2,3),(4,5,6,7),(0,1,4,5),(1,2,4,5),(2,3,6,7),(3,0,7,4)] generateObj("Punkt",verts,faces,pos) def generateObj(name,verts,faces,loc): mymesh = bpy.data.meshes.new(name) myobject = bpy.data.objects.new(name,mymesh) myobject.location = loc #(0,0,0) #bpy.context.scene.cursor.location bpy.context.collection.objects.link(myobject) mymesh.from_pydata(verts,[],faces) mymesh.update(calc_edges=True) #v = [(-10,0,0),(10,10,0),(10,-10,0),(0,0,10)] #f = [(0,1,2),(1,2,3),(2,3,0),(3,0,1)] #generateObj("tetraeder", v, f) # Variablen anzahlKerne = 10 # anzahl der Kerne, die generiert werden sollen ker = [] # Liste mit zufälligen Kernen drin # Setup Kerne for i in range(0, anzahlKerne): x = randint(0,10); y = randint(0,10); z = randint(0,10); ker.append((x,y,z)) print(ker) for i in ker: genPunkt(i) # Überprüfung, ob Kerne auf einem Kreis -> dann diese Tetraeder bauen for i in range(0, len(ker)): for j in range(i+1, len(ker)): for k in range(j+1, len(ker)): for l in range(k+1, len(ker)): verts = (ker[i], ker[j], ker[k], ker[l]) faces = [(0,1,2),(1,2,3),(2,3,0),(3,0,1)] generateObj("Tetraeder", verts, faces, (0,0,0))