Ich habe ein Vogelgitter, dass als Numpy Array dargestellt ist. Ich gebe meiner Funktion nun die Koordinaten, x, y, z den Radius und einen Wert. Ich möchte nun dass der Wert jedem Punkt auf einem Teil der Oberfläche einer Kugel mit dem Radius R um den Punkt x,y,z hinzuaddiert wird. Der Polarwinkel soll bei mir nur von 2/3pi-pi laufen. Ich habe bis jetzt zwei Methoden kennengelernt, leider sind beide sehr langsam. Hat jemand eine Idee wie ich es schneller hinbekomme ? Ps. Meine Z-Achse hat im Vooxelgitter eine Auflösung von 1:
Code: Alles auswählen
def spheric Surface (x, y, z, r, value):
phi = 0
while phi <= (2*math.pi):
eta = math.pi * 2 / 3
while eta <= math.pi:
xx = x + r * math.sin(eta) * math.cos(phi)
yy = y + r * math.sin(eta) * math.sin(phi)
zz = z + r * math.cos(eta)
xx = int(xx*resoultion+0.5)
yy = int(yy*resolution+0.5)
zz = int(zz*resolution+0.5)
voxelGrid[xx][yy][zz] += value
eta += 1/10 * math.pi
phi += 1/10 * math.pi
Code: Alles auswählen
def sphericSurface(x, y, z, r, value):
tol = 0.6
grenz = math.pi * 2 / 3
mask = (np.logical_and(np.logical_and((sx[:, None, None] - x) ** 2 + (sy[None, :, None] - y) ** 2 + (sz[None, None, :] - z) ** 2 <= (r + tol)**2,
(sx[:, None, None] - x) ** 2 + (sy[None, :, None] - y) ** 2 + (sz[None, None, :] - z) ** 2 >= (r - tol)**2),
(sz[None, None, :] - z) <= (r*math.cos(grenz))))
x, y, z = np.where(mask==True)
z *= 2
voxelGrid[x,y,z] += value