qberik

Untitled

Oct 23rd, 2022
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.36 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. import math
  3. import matplotlib.pyplot as plt
  4. import numpy as np
  5.  
  6.  
  7. # def graphic(x: int, y: int) -> None:
  8. class graphic():
  9. def __init__(self, x = 0, y = 0):
  10. self.px: float = x
  11. self.py: float = y
  12.  
  13. def run(self):
  14. # calculate dot
  15. x,y = self.px, self.py
  16. self.in_graph = ((y - 4/x <= 0) and ( y + 4/x >= 0 )) and not ( x**1 + y**2 - 25 <= 0 )
  17.  
  18. self.fig = plt.figure()
  19. ax = self.fig.add_subplot(111,aspect='equal')
  20.  
  21. # draw curle
  22. def xy(r,phi):
  23. return r*np.cos(phi), r*np.sin(phi)
  24.  
  25. phis=np.arange(0,6.28,0.01)
  26. r = 5.
  27. ax.plot( *xy(r,phis), c='k',ls='-' )
  28. # TODO: add scaler to menu
  29. ax.set(xlim=(-5,10), ylim=(-10,10))
  30.  
  31. from_a = 0.810728510460184
  32. to_b = 4.93383413607785
  33.  
  34.  
  35. Nx = 1000
  36. x = np.linspace(0,50,Nx)
  37. y = np.sqrt(x)
  38.  
  39. max_x = 10
  40.  
  41. plt.plot(np.linspace(0, from_a, Nx),
  42. np.divide(4, np.linspace(0, -1*from_a, Nx)),
  43. color='k'
  44. )
  45.  
  46. plt.plot(np.linspace(0, from_a, Nx),
  47. np.divide(4, np.linspace(0, from_a, Nx)),
  48. color= 'k'
  49. )
  50.  
  51. plt.plot(np.linspace(to_b, max_x, Nx),
  52. np.divide(4, np.linspace(-to_b, -1*max_x, Nx)),
  53. color='k'
  54. )
  55.  
  56. plt.plot(np.linspace(to_b, max_x, Nx),
  57. np.divide(4, np.linspace(to_b, max_x, Nx)),
  58. color= 'k'
  59. )
  60.  
  61.  
  62.  
  63. plt.plot( np.linspace(0, 0, Nx),
  64. np.linspace(5,max_x, Nx),
  65. color= 'k'
  66. )
  67.  
  68. plt.plot( np.linspace(0, 0, Nx),
  69. np.linspace(-5,-max_x, Nx),
  70. color= 'k'
  71. )
  72.  
  73.  
  74.  
  75. # plt.plot(
  76. # np.linspace(max_x, max_x, Nx),
  77. # np.linspace(0, math.sqrt(max_x), Nx),
  78. # color= 'k'
  79. # )
  80.  
  81. # fill color
  82.  
  83. x = np.arange(0,from_a, max_x / Nx )
  84. c1 = 5 * np.cos ( np.arcsin( x / 5 ) )
  85. c2 =-5 * np.cos ( np.arcsin( x / 5 ) )
  86. s1 = 4 / x
  87. s2 =-4 / x
  88. color = "gray"
  89. ax.fill_between(x, c1, s1 , color=color)
  90. ax.fill_between(x, s2, c2 , color=color)
  91.  
  92.  
  93. x = np.arange(to_b,5, max_x / Nx )
  94. c1 = 5 * np.cos ( np.arcsin( x / 5 ) )
  95. c2 =-5 * np.cos ( np.arcsin( x / 5 ) )
  96. s1 = 4 / x
  97. s2 =-4 / x
  98. color = "gray"
  99. ax.fill_between(x, c1, s1 , color=color)
  100. ax.fill_between(x, s2, c2 , color=color)
  101.  
  102.  
  103. x = np.arange(5,max_x, max_x / Nx )
  104. s1 = 4 / x
  105. s2 =-4 / x
  106.  
  107. ax.fill_between(x, s1, s2 , color=color)
  108.  
  109.  
  110. #ax.fill_between(x, c1, s1 , color=color)
  111. #ax.fill_between(x, s2, c2 , color=color)
  112.  
  113. # ax.fill_between( x, c2, l , color=color)
  114.  
  115. # x = np.arange(4,max_x, max_x / Nx )
  116. # s = np.sqrt( x )
  117. # l = x * 0
  118.  
  119. # ax.fill_between( x, l, s , color=color)
  120.  
  121. # draw dot
  122. point_color = 'b' if self.in_graph else 'r'
  123. plt.plot( self.px ,self.py, color=point_color, marker = 'o', markersize = 10 )
  124.  
  125. plt.show()
  126.  
  127. def close(self):
  128. plt.close()
  129.  
  130.  
  131. def status(self) -> bool:
  132. if self.in_graph:
  133. return True
  134. return False
  135.  
Advertisement
Add Comment
Please, Sign In to add comment