2

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!

Max Crous
  • 411
  • 2
  • 11

1 Answers1

1

Try this 3D truncated cone in python The equations for a simple (not truncated) cone are given by https://mathworld.wolfram.com/Cone.html

intotecho
  • 4,925
  • 3
  • 39
  • 54