我有一个功能,它将输入作为铣削参数,然后生成一个曲面。 在这个函数中,我有一个for循环,它存储我工具中心点的坐标。 我想知道如何存储中心点CP的X和Y坐标 在数组中,以便我可以使用这些值进行进一步的操作? 为了进一步操作,我需要使用for循环访问我的CP变量的X-Coordinate的每个值,将X坐标的值乘以某个因子,然后将其作为下一次循环迭代的新CP x坐标。 我该怎么做?
def Milling(xdim, ydim, resolution, feed, infeed, radius ):
"""
Die Funktion gibt eine Punktwolke zurück (x1 y1 z1)
xdim, ydim: gemessenes Feld [mm] \n
resolution: Messpunktauflösung [1/mm] \n
feed: Bahnabstand [mm] \n
infeed: vertikale Zustellung [mm] \n
"""
tstart = time.time()
surface = np.zeros((xdim*resolution+1, ydim*resolution+1)) #inititalisation of the array
i = 0 # Run index for the milling paths
phi = np.arccos(1-infeed/radius) # angle between ball cutter center point and extreme trimming edge on the path
print("np.zeros(): ", (time.time()-tstart)*1000)
for i in range(0,int((xdim+radius)//feed)): #Here is a post-checked-loop, a milling operation is always executed
cp = [feed*i,-infeed+radius] # Center point location of the spherical cutter
if radius*np.sin(phi) > i*feed:
x0 = 0 # Milling path has a wide range of x0 to x1.
else:
x0 = cp[0]-radius*np.sin(phi) #if X0 is outside surface set it 0 , i.e at staarting point of workpiece
if cp[0]+radius*np.sin(phi) > xdim:
x1 = xdim #if x1 exeeds XDIM set it as last point of workpeice
else:
x1 = cp[0]+radius*np.sin(phi)
for x in range(int(np.round(x0*resolution)),int(np.round(x1*resolution))): # Ball Mill# represents the discretized points on between X0 &x1..remember res is 1/res**
phi_ = np.arcsin((cp[0]-x/resolution)/radius)
z = cp[1] - radius * np.cos(phi_) #this y should be actually a temperory value along Z...
if surface[x,0] > z:
surface[x,0] = z
所以我只想知道如何存储和打印变量cp的值?
答案 0 :(得分:0)
您可以使用列表来存储值。例如,您可以使用storage = []
启动空列表storage.append(value)
,然后为其附加值。
storage = []
for i in range(10):
cp = [2*i, -i/2]
storage.append(cp)
# do other things with cp
您还可以使用最后存储的值来计算下一个值,例如
storage = [[1,1]]
for i in range(10):
cp = storage[-1]
cp = [cp[0]+i, -cp[1]/2.]
storage.append(cp)
然后,您可以打印完整列表print(storage)
,或仅打印一些感兴趣的值print(storage[3])
。您也可以让您的函数返回列表,
def func():
storage = []
#....
return storage