Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def sample_points_sphere():
- import numpy
- q_list = numpy.random.uniform(0,numpy.pi,1000)
- f_list = numpy.random.uniform(0,2*numpy.pi,len(q_list))
- radius = 1
- return numpy.array(
- [radius*numpy.sin(q_list)*numpy.cos(f_list),
- radius*numpy.sin(q_list)*numpy.sin(f_list),
- radius*numpy.cos(q_list)]).T
- def sample_points_paraboloid():
- import numpy
- r_list = numpy.random.uniform(0,10,1000)
- f_list = numpy.random.uniform(0,2*numpy.pi,len(r_list))
- return numpy.array(
- [r_list*numpy.cos(f_list),
- r_list*numpy.sin(f_list),
- 0.5*r_list**2-1]).T
- def zx_rotation(points, q):
- import numpy
- x_list = points.T[0]
- y_list = points.T[1]
- z_list = points.T[2]
- xt_list = x_list*numpy.cos(q)+z_list*numpy.sin(q)
- yt_list = y_list
- zt_list = z_list*numpy.cos(q)-x_list*numpy.sin(q)
- return numpy.array([xt_list,yt_list,zt_list]).T
- def test_inclinator():
- import numpy
- import random
- import matplotlib.pyplot as plt
- from mpl_toolkits.mplot3d import Axes3D
- from pyhull.convex_hull import ConvexHull
- original = sample_points_paraboloid()
- rotated1 = zx_rotation(original, numpy.pi/3.0)
- rotated2 = zx_rotation(original, numpy.pi/2.0)
- hull1 = ConvexHull(numpy.array([rotated1.T[0],
- rotated1.T[1]]).T)
- hull2 = ConvexHull(numpy.array([rotated2.T[0],
- rotated2.T[1]]).T)
- if False:
- fig = plt.figure()
- ax = fig.add_subplot(111, projection='3d')
- ax.scatter(x_list, y_list, z_list, 'b')
- ax.scatter(x_list, y_list, 0*z_list-1, color='r')
- fig.show()
- raw_input()
- if True:
- fig = plt.figure()
- ax = fig.add_subplot(311)
- ax.scatter(hull1.points.T[0],
- hull1.points.T[1],
- alpha=0.1)
- for v in hull1.vertices:
- ax.plot([hull1.points[v[0]][0],
- hull1.points[v[1]][0]],
- [hull1.points[v[0]][1],
- hull1.points[v[1]][1]],
- 'k')
- ax = fig.add_subplot(312)
- ax.scatter(hull2.points.T[0],
- hull2.points.T[1],
- alpha=0.1)
- for v in hull2.vertices:
- ax.plot([hull2.points[v[0]][0],
- hull2.points[v[1]][0]],
- [hull2.points[v[0]][1],
- hull2.points[v[1]][1]],
- 'k')
- ax = fig.add_subplot(313)
- for v in hull1.vertices:
- ax.plot([hull1.points[v[0]][0],
- hull1.points[v[1]][0]],
- [hull1.points[v[0]][1],
- hull1.points[v[1]][1]],
- 'b')
- for v in hull2.vertices:
- ax.plot([hull2.points[v[0]][0],
- hull2.points[v[1]][0]],
- [hull2.points[v[0]][1],
- hull2.points[v[1]][1]],
- 'g')
- for v in hull2.vertices:
- ax.plot([0.86*hull2.points[v[0]][0],
- 0.86*hull2.points[v[1]][0]],
- [hull2.points[v[0]][1],
- hull2.points[v[1]][1]],
- 'r')
- plt.axis('equal')
- plt.show()
- test_inclinator()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement