Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 中心点坐标_Python 2.7_Numpy_Matplotlib - Fatal编程技术网

Python 2.7 中心点坐标

Python 2.7 中心点坐标,python-2.7,numpy,matplotlib,Python 2.7,Numpy,Matplotlib,我有一个特定的函数,它将输入作为铣削参数,然后生成曲面。 在这个函数中,我有一个for循环,用于存储刀具中心点的坐标。 我想知道如何存储中心点CP的X和Y坐标 在数组中,以便我可以使用这些值进行进一步的操作? 为了进一步操作,我需要使用for循环访问CP变量X坐标的每个值,将X坐标的值与某个因子相乘,然后将其作为下一次循环迭代的新CP X坐标。 我该怎么做 def Milling(xdim, ydim, resolution, feed, infeed, radius ): """ Die Fu

我有一个特定的函数,它将输入作为铣削参数,然后生成曲面。 在这个函数中,我有一个for循环,用于存储刀具中心点的坐标。 我想知道如何存储中心点CP的X和Y坐标 在数组中,以便我可以使用这些值进行进一步的操作? 为了进一步操作,我需要使用for循环访问CP变量X坐标的每个值,将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的值。

您可以使用列表来存储值。例如,您可以启动一个空列表
storage=[]
,然后使用
storage.append(value)
向其追加值

您还可以使用最后一个存储值来计算下一个值,例如

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

可以使用列表在中存储值。例如,您可以启动一个空列表
storage=[]
,然后使用
storage.append(value)
向其追加值

您还可以使用最后一个存储值来计算下一个值,例如

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

如果你的函数还没有返回任何东西,你可以简单地从函数中返回cp变量,如果这是你想要的。如果你的函数还没有返回任何东西,你可以简单地从函数中返回cp变量,如果这是你想要的。谢谢你的回答。我对我的问题稍加修改。请检查。@anshuman我编辑了答案以包含对变量的操作。任何投票都只基于答案。现在我更新了投票结果,因为答案已经被编辑过,并且有了很大的改进。谢谢你的回答。我对我的问题稍加修改。请检查。@anshuman我编辑了答案以包含对变量的操作。任何投票都只基于答案。我更新了投票结果,因为答案已被编辑,并有了很大的改进。