I'm a master student in my thesis year and I need to inject geometric holes in a 3D model.
This code made by the author of both pymrt and raster_geometry, norok2, was of great help to generate spheres:
import numpy as np
def sphere(shape, radius, position):
# assume shape and position are both a 3-tuple of int or float
# the units are pixels / voxels (px for short)
# radius is a int or float in px
semisizes = (radius,) * 3
# genereate the grid for the support points
# centered at the position indicated by position
grid = [slice(-x0, dim - x0) for x0, dim in zip(position, shape)]
position = np.ogrid[grid]
# calculate the distance of all points from `position` center
# scaled by the radius
arr = np.zeros(shape, dtype=float)
for x_i, semisize in zip(position, semisizes):
arr += (np.abs(x_i / semisize) ** 2)
# the inner part of the sphere will have distance below 1
return arr <= 1.0
Now I'm having a bit of trouble trying to adapt that code to a function that defines a cone, could you help me in some way?
Thank you very much!