Advertisement
bolverk

projection playground

Sep 1st, 2015
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.36 KB | None | 0 0
  1. def sample_points_sphere():
  2.  
  3.     import numpy
  4.  
  5.     q_list = numpy.random.uniform(0,numpy.pi,1000)
  6.     f_list = numpy.random.uniform(0,2*numpy.pi,len(q_list))
  7.     radius = 1
  8.     return numpy.array(
  9.         [radius*numpy.sin(q_list)*numpy.cos(f_list),
  10.          radius*numpy.sin(q_list)*numpy.sin(f_list),
  11.          radius*numpy.cos(q_list)]).T
  12.  
  13. def sample_points_paraboloid():
  14.  
  15.     import numpy
  16.  
  17.     r_list = numpy.random.uniform(0,10,1000)
  18.     f_list = numpy.random.uniform(0,2*numpy.pi,len(r_list))
  19.     return numpy.array(
  20.         [r_list*numpy.cos(f_list),
  21.          r_list*numpy.sin(f_list),
  22.          0.5*r_list**2-1]).T
  23.  
  24. def zx_rotation(points, q):
  25.  
  26.     import numpy
  27.  
  28.     x_list = points.T[0]
  29.     y_list = points.T[1]
  30.     z_list = points.T[2]
  31.     xt_list = x_list*numpy.cos(q)+z_list*numpy.sin(q)
  32.     yt_list = y_list
  33.     zt_list = z_list*numpy.cos(q)-x_list*numpy.sin(q)
  34.  
  35.     return numpy.array([xt_list,yt_list,zt_list]).T
  36.  
  37. def test_inclinator():
  38.    
  39.     import numpy
  40.     import random
  41.     import matplotlib.pyplot as plt
  42.     from mpl_toolkits.mplot3d import Axes3D
  43.     from pyhull.convex_hull import ConvexHull
  44.  
  45.     original = sample_points_paraboloid()
  46.     rotated1 = zx_rotation(original, numpy.pi/3.0)
  47.     rotated2 = zx_rotation(original, numpy.pi/2.0)
  48.     hull1 = ConvexHull(numpy.array([rotated1.T[0],
  49.                                     rotated1.T[1]]).T)
  50.     hull2 = ConvexHull(numpy.array([rotated2.T[0],
  51.                                     rotated2.T[1]]).T)
  52.  
  53.     if False:
  54.         fig = plt.figure()
  55.         ax = fig.add_subplot(111, projection='3d')
  56.         ax.scatter(x_list, y_list, z_list, 'b')
  57.         ax.scatter(x_list, y_list, 0*z_list-1, color='r')
  58.         fig.show()
  59.         raw_input()
  60.     if True:
  61.         fig = plt.figure()
  62.         ax = fig.add_subplot(311)
  63.         ax.scatter(hull1.points.T[0],
  64.                    hull1.points.T[1],
  65.                    alpha=0.1)
  66.         for v in hull1.vertices:
  67.             ax.plot([hull1.points[v[0]][0],
  68.                      hull1.points[v[1]][0]],
  69.                     [hull1.points[v[0]][1],
  70.                      hull1.points[v[1]][1]],
  71.                     'k')
  72.        
  73.         ax = fig.add_subplot(312)
  74.         ax.scatter(hull2.points.T[0],
  75.                    hull2.points.T[1],
  76.                    alpha=0.1)
  77.         for v in hull2.vertices:
  78.             ax.plot([hull2.points[v[0]][0],
  79.                      hull2.points[v[1]][0]],
  80.                     [hull2.points[v[0]][1],
  81.                      hull2.points[v[1]][1]],
  82.                     'k')
  83.  
  84.         ax = fig.add_subplot(313)
  85.         for v in hull1.vertices:
  86.             ax.plot([hull1.points[v[0]][0],
  87.                      hull1.points[v[1]][0]],
  88.                     [hull1.points[v[0]][1],
  89.                      hull1.points[v[1]][1]],
  90.                     'b')
  91.         for v in hull2.vertices:
  92.             ax.plot([hull2.points[v[0]][0],
  93.                      hull2.points[v[1]][0]],
  94.                     [hull2.points[v[0]][1],
  95.                      hull2.points[v[1]][1]],
  96.                     'g')
  97.         for v in hull2.vertices:
  98.             ax.plot([0.86*hull2.points[v[0]][0],
  99.                      0.86*hull2.points[v[1]][0]],
  100.                     [hull2.points[v[0]][1],
  101.                      hull2.points[v[1]][1]],
  102.                     'r')
  103.  
  104.         plt.axis('equal')
  105.         plt.show()
  106.  
  107. test_inclinator()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement