Advertisement
aPisC

Hexagon radius approximation

May 29th, 2022
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. import numpy as np
  3.  
  4. f = np.linspace(0, np.pi *2,num= 100)
  5.  
  6. x = np.sin(f)
  7. y = np.cos(f)
  8.  
  9. z = np.zeros(100) # approximation of f from coordinates
  10. scale2 = np.zeros(100)
  11.  
  12. for i in range(100):
  13. yy = np.abs(y[i])
  14. xx = np.abs(x[i])
  15. if xx > yy:
  16. temp = yy/xx
  17. z[i] = -(0.97239411 + -0.19194795 * temp * temp) * temp + np.pi/2
  18. else:
  19. temp = xx/yy
  20. z[i] = (0.97239411 + -0.19194795 * temp * temp) * temp
  21.  
  22. w = z[i]
  23. ww = w*w
  24. sinw = w * (1 - ww *(1 / 6 - ww/120 ))
  25. sin3w = 3*sinw - 4* sinw* sinw* sinw
  26. scale2[i] = 1 - np.abs(sin3w) * (1-np.cos( np.pi / 6))
  27. #scale2 = 1 - np.abs(np.sin(nofpoints/2*z))* (1-np.cos( np.pi / nofpoints))
  28.  
  29.  
  30.  
  31.  
  32. plt.figure(figsize=(10,10))
  33.  
  34. f2 = np.linspace(0, np.pi *2,num= 7)
  35. plt.plot(np.sin(f2), np.cos(f2))
  36.  
  37. plt.plot(np.multiply(x, scale2), np.multiply(y, scale2))
  38. plt.plot(np.multiply(x, scale2)*1.25, np.multiply(y, scale2)*1.25)
  39.  
  40.  
  41. plt.xlim([-1.5, 1.5])
  42. plt.ylim([-1.5, 1.5])
  43.  
  44. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement