Пример #1
0
def getPointsPath(x1,y1,x2,y2,step,width,height,p1=1,p2=1):
	# start with empty path
	path=[]

	lastpoint=(-1,-1)

	# calculate straight line distance between coords
	delta_x=x2-x1
	delta_y=y2-y1
        delta_p=p2-p1
	h=math.hypot(abs(delta_x),abs(delta_y))

	# if distance between is too small, just return coord 2
	if h < step*2:
		path.append((x2,y2,p2))
		return path

	# calculate intermediate coords
	intermediate_points=numpy.arange(step,h,step)
	for point in intermediate_points:
		newx=int(x1+(delta_x*point/h))
		newy=int(y1+(delta_y*point/h))
                newp=p1+(delta_p*point/h)
		# make sure coords fall in widht and height restrictions
		if newx>=0 and newx<width and newy>=0 and newy<height:
			# only add point if it was different from previous one
			if newx!=lastpoint[0] or newy!=lastpoint[1]:
			  lastpoint=(newx,newy,newp)
			  path.append(lastpoint)

	if x2>=0 and x2<width and y2>=0 and y2<height:
		path.append((x2,y2,p2))

	return path
Пример #2
0
def getPointsPath(x1,y1,x2,y2,linestep,width,height,p1=1,p2=1):
	# start with a blank list
	path=[]

	lastpoint=(x1,y1)

	# calculate straight line distance between coords
	delta_x=x2-x1
	delta_y=y2-y1
	delta_p=p2-p1

	h=math.hypot(abs(delta_x),abs(delta_y))

	# calculate intermediate coords
	intermediate_points=numpy.arange(linestep,h,linestep)
	if len(intermediate_points)==0:
		return path
	pstep=delta_p/len(intermediate_points)
	newp=p1

	for point in intermediate_points:
		newx=x1+(delta_x*point/h)
		newy=y1+(delta_y*point/h)
		newp=newp+pstep

		# make sure coords fall in widht and height restrictions
		if newx>=0 and newx<width and newy>=0 and newy<height:
			# make sure we don't skip a point
			#if step==0 int(newx)!=int(lastpoint[0]) and int(newy)!=int(lastpoint[1]):
			#	print "skipped from point:", lastpoint, "to:", newx,newy
			# only add point if it was different from previous one
			#if int(newx)!=int(lastpoint[0]) or int(newy)!=int(lastpoint[1]):
			lastpoint=(newx,newy,newp)
			path.append(lastpoint)

	return path
Пример #3
0
def print_NumPy():
    x = np.arange(12, 38)
Пример #4
0
#_*_encoding:utf-8_*_
#!/usr/bin/env python

import NumPy as np

a = np.arange(15).reshape(3, 5)

print a
    print(Z)

# Exercise 4
    # How to get the documentation of the numpy add function
    # from the command line
    python -c "import numpy; numpy.info(numpy.add)"

# Exercise 5
    # Create a null vector of size 10 but the fifth value which is 1
    Z = np.zeros(10)
    Z[4]=1
    print(Z)

# Exercise 6
    # Create a vector with values ranging from 10 to 49
    Z = np.arange(10, 50)
    print(Z)

# Exercise 7
    # Reverse a vector (first element becomes last)
    Z = np.arange(0,10)
    Z[::-1]

# Exercise 8
    # Create a 3 x 3 matrix with values ranging from 0 to 8
    Z = np.arange(9)
    Z.reshape(3,3)
        # or
    Z = np.arange(9).reshape(3,3)
    print(Z)