arc7tomask.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. def draw_ellipse_arc(xc, yc, a, b, theta, phi1, phi2, num_points=200):
  4. """
  5. »æÖÆÍÖÔ²»¡
  6. Args:
  7. xc, yc (float): ÍÖÔ²ÖÐÐÄ×ø±ê
  8. a, b (float): ³¤¶Ì°ëÖá (a >= b)
  9. theta (float): ÍÖÔ²ÄæÊ±ÕëÐýת½Ç¶È£¨»¡¶È£©
  10. phi1, phi2 (float): »¡Ï߯ðʼ½Ç£¨»¡¶È£©£¬Çø¼ä [0, 2¦Ð)
  11. num_points (int): »æÖƾ«¶È
  12. """
  13. # Éú³É»¡Ïß²ÎÊý
  14. phi = np.linspace(phi1, phi2, num_points)
  15. # ÍÖÔ²±ê×¼·½³ÌÉϵĵã
  16. x = a * np.cos(phi)
  17. y = b * np.sin(phi)
  18. # Ðýת¾ØÕó
  19. cos_t = np.cos(theta)
  20. sin_t = np.sin(theta)
  21. xr = x * cos_t - y * sin_t + xc
  22. yr = x * sin_t + y * cos_t + yc
  23. # »æÍ¼
  24. plt.figure(figsize=(6,6))
  25. plt.plot(xr, yr, 'r-', linewidth=2)
  26. plt.scatter([xc], [yc], color='blue', label='Center')
  27. plt.axis('equal')
  28. plt.title("Ellipse Arc")
  29. plt.grid(True)
  30. plt.show()
  31. if __name__ == "__main__":
  32. """
  33. Tensor(shape=(7,), dtype=torch.float32, device=cpu, values=[1025.0, 560.0, 131.87399291992188, 116.3759994506836, -0.5879999995231628, 2.1936283111572266, 3.825697898864746])Tensor(shape=(7,),
  34. dtype=torch.float32, device=cpu, values=[721.0, 527.0, 121.36299896240234, 134.70399475097656, -0.02500000037252903, 2.0525598526000977, 4.132845878601074])
  35. 111values=[1022.0, 443.0, 88.08300018310547, 118.55699920654297, 2.7829999923706055, 5.329736709594727, 0.142518550157547])
  36. values=[1123.0, 923.0, 158.6739959716797, 182.2220001220703, 0.6779999732971191, 0.8875003457069397, 2.6391656398773193])
  37. Tensor(shape=(7,), dtype=torch.float32, device=cpu, values=[618.0, 542.0, 128.01300048828125, 141.08799743652344, 0.37400001287460327, 1.150931477546692, 5.289559364318848])\
  38. Tensor(shape=(7,), dtype=torch.float32, device=cpu, values=[850.0, 365.0, 159.79400634765625, 121.38099670410156, -3.078000068664551, 4.8650922775268555, 5.932548522949219])
  39. """
  40. # ʾÀý£º´Ó tensor ÖлñÈ¡µÄÖµ
  41. xc, yc, a, b, theta, phi1, phi2 = [
  42. 1022.0, 443.0, 88.08300018310547, 118.55699920654297, 2.7829999923706055, 5.329736709594727, 0.142518550157547
  43. ]
  44. draw_ellipse_arc(xc, yc, a, b, theta, phi1, phi2)