Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. #Initial setup of the platforms
  2. sqrt3 = math.sqrt(3)
  3. coef = sqrt3/6
  4. coef2 = sqrt3/3
  5. coef3 = sqrt3/2
  6. pi = 3.141592653
  7.  
  8. #0.567,0.076,0.524,1.244
  9. #Size of the equlateral triangle
  10. Sb = 0.567
  11. Sp = 0.076
  12. l = 1.244
  13. L = 0.524
  14.  
  15. Wb = coef * Sb
  16. Ub = coef2 * Sb
  17.  
  18. Wp = coef * Sp
  19. Up = coef2 * Sp
  20.  
  21.  
  22. def calcAngle(e,f,g):
  23. s = e*e + f*f - g*g
  24. if( s < 0 ):
  25. return None #point does not exist
  26. else:
  27. sq = math.sqrt(e*e + f*f - g*g)
  28. t1 = (-f + sq )/ (g-e)
  29. t2 = (-f - sq )/ (g-e)
  30. #is the smaller angle the better solution
  31. o1 = math.degrees(2* math.atan(t1))
  32. o2 = math.degrees(2* math.atan(t2))
  33.  
  34. if(o1 < 90 or o1 > -90):
  35. return o2
  36. else:
  37. return o1
  38.  
  39.  
  40.  
  41. def inverse(x,y,z):
  42. a = Wb - Up
  43. b = Sp*0.5 - coef3 * Wb
  44. c = Wp - 0.5*Wb
  45.  
  46.  
  47. e1 = 2*L*(y+a)
  48. f1 = 2*z*L
  49. g1 = x*x + y*y + z*z + a*a + L*L + 2*y*a - l*l
  50.  
  51. e2 = -L * ( math.sqrt(3) * (x + b) + y + c)
  52. g2 = x*x + y*y + z*z + b*b + c*c + L*L + 2*(x*b + y*c) - l*l
  53.  
  54. e3 = L*(sqrt3*(x-b) - y - c )
  55. g3 = x*x + y*y + z*z + b*b + c*c + L*L + 2*(-x*b + y*c) - l*l
  56.  
  57. return [
  58. calcAngle(e1,f1,g1),
  59. calcAngle(e2,f1,g2),
  60. calcAngle(e3,f1,g3)
  61. ]
  62.  
  63.  
  64. import numpy as np
  65. from mpl_toolkits.mplot3d import Axes3D
  66. import matplotlib.pyplot as plt
  67. from scipy import stats
  68. import matplotlib.axes
  69.  
  70. n = 30
  71.  
  72. X = np.linspace(-2, 2, num=n)
  73. Y = np.linspace(-2, 2, num=n)
  74. Z = np.linspace(-2, 0, num=n)
  75. X, Y, Z = np.meshgrid(X, Y, Z)
  76.  
  77. colors = {True: "blue", False: "white"}
  78. opacity = {True: 50, False: 0}
  79. opacity2 = {True: 1, False: 0}
  80.  
  81. def possibleAngles(t1,t2,t3):
  82. return (t1 < 90 and t1 > -90 ) and (t2 < 90 and t2 > -90 ) and (t3 < 90 and t3 > -90 )
  83.  
  84. def opacityShite(x,y,z):
  85. angles = inverse(x,y,z)
  86. isReal = not any(e is None for e in [angles[0],angles[1],angles[2]]) and possibleAngles(angles[0],angles[1],angles[2])
  87. return opacity[isReal]
  88.  
  89. def densityShite(x,y,z):
  90. angles = inverse(x,y,z)
  91. isReal = not any(e is None for e in [angles[0],angles[1],angles[2]]) and possibleAngles(angles[0],angles[1],angles[2])
  92. return opacity2[isReal]
  93.  
  94. vop = np.vectorize(opacityShite)
  95. dop = np.vectorize(densityShite)
  96.  
  97. fig = plt.figure(figsize=(50,50))
  98.  
  99.  
  100. ax1 = plt.subplot2grid((1, 3), (0,1), projection='3d',aspect=1)
  101.  
  102. ax1.scatter(X,Y,Z,s=vop(X,Y,Z),marker=".")
  103. ax1.view_init(elev=15., azim=20)
  104. ax1.set_xlabel('X Label')
  105. ax1.set_ylabel('Y Label')
  106. ax1.set_zlabel('Z Label')
  107.  
  108.  
  109. # sizes = dop(X,Y,Z)
  110. # density = np.sum(sizes, axis=0)
  111. # X.shape
  112. # X1 = np.linspace(-2, 2, num=50)
  113. # Y1 = np.linspace(-2, 2, num=50)
  114. # X1,Y1 = np.meshgrid(X1,Y1)
  115. # ax2.contourf(X1,Y1,density,zdir='x',stride=0.1,cmap='jet')
  116. # ax2.contour3D(X1,Y1,density,zdir='y',stride=0.1,cmap='jet')
  117. # ax2.plot_wireframe(X1,Y1,density)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement