1

I have a certain function which takes inputs as milling parameters and then generates a surface . Within this function I have a for loop which stores the co-ordinates of the center point of my tool. I wanted to know how can i store the X and Y coordinates of my center point CP in an array so that i can use these values for further manipulations? for further manipulation i need to access each value of X-Coordinate of my CP variable using a for loop , multiply the value of X coordinate with some factor and then make this as my new CP x-coordinates for the next iteration of loop. How do i do this?

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

So I just wanted to know how can i store and print out the values of my variable cp?

  • If your function doesn't return anything yet, you can simply return the cp variable out of the function, if that's what you seek. – user2464424 Jun 08 '17 at 20:46

1 Answers1

0

You can use a list to store values in. As an example, you can initiate an empty list storage = [] and then append values to it, using storage.append(value).

storage = []
for i in range(10):
    cp = [2*i, -i/2]
    storage.append(cp)
    # do other things with cp

You can also use the last stored value to calculate the next one, e.g.,

storage = [[1,1]]
for i in range(10):
    cp = storage[-1]
    cp = [cp[0]+i, -cp[1]/2.]
    storage.append(cp)

You may then print the complete list print(storage), or only some value of interest out of it print(storage[3]). You can also let your function return the list,

def func():
    storage = []
    #....
    return storage
ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712