I am trying to generate a 3D matrix with a tube structure running through it. I can make the tube straight by copying a 2D numpy
array with a circle centered at (x,y)
inside, and I can make the tube slanted by adding an int
to either the x or y axis for each slice I generate. My question is, how can I move the (x,y)
coordinates so that they can form a curve? I can't add step sizes of curved functions like sine and cosine to the coordinates since to index the numpy
array it must be an integer. What is a smart way to generate a curved tube from 2D slices by shifting the center coordinates?
Here is the code I am using to generate a straight tube as a 3D matrix:
import numpy as np
import cv2
import matplotlib.pyplot as plt
slice_2d = np.zeros((128,128))
circle_center = (50,50)
radius=10
slice_2d = cv2.circle(slice_2d, circle_center, radius, color=1, thickness=-1)
plt.imshow(slice_2d)
# then we repeat the slice 128 times to create a straight tube in a 3D matrix of 128,128,128
tube_matrix = []
for i in range(0,128):
tube_matrix.append(slice_2d)
tube_matrix = np.array(tube_matrix)