fig-laba2-nachalo.py 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # -*- coding: utf-8 -*-
  2. """
  3. Лаба 2, рисунок «Начало трассирования»: схема начала трассы от раздельного
  4. пункта (Lст/2 + запас a + участок не менее 500 м) до вершины угла поворота ВУ
  5. с тангенсом T и круговой кривой, вписанной в угол поворота.
  6. Перерисовано векторно вместо низкого разрешения скана методички.
  7. """
  8. import numpy as np
  9. import matplotlib
  10. matplotlib.use('Agg')
  11. import matplotlib.pyplot as plt
  12. import matplotlib.font_manager as fm
  13. fm.fontManager.addfont('C:/Windows/Fonts/GOST2304A.ttf')
  14. matplotlib.rcParams['font.family'] = 'GOST 2.304 type A'
  15. matplotlib.rcParams['mathtext.default'] = 'regular'
  16. matplotlib.rcParams['mathtext.fontset'] = 'custom'
  17. matplotlib.rcParams['mathtext.rm'] = 'GOST 2.304 type A'
  18. matplotlib.rcParams['mathtext.it'] = 'GOST 2.304 type A'
  19. BLACK = '#111111'
  20. fig = plt.figure(figsize=(12.8 / 2.54, 6.4 / 2.54), dpi=300)
  21. ax = fig.add_axes([0, 0, 1, 1])
  22. ax.set_aspect('equal'); ax.axis('off')
  23. ax.set_xlim(0, 10.2); ax.set_ylim(-3.1, 2.5)
  24. # --- трасса: прямая до ВУ и следующее направление под углом 35° вниз -------------
  25. x_vu, phi, T = 7.2, np.radians(50), 1.3
  26. d = np.array([np.cos(-phi), np.sin(-phi)])
  27. x_nk = x_vu - T # начало кривой
  28. p_kk = np.array([x_vu, 0]) + T * d # конец кривой
  29. ax.plot([0.8, x_vu], [0, 0], color=BLACK, lw=1.3)
  30. p_end = np.array([x_vu, 0]) + 1.75 * d
  31. ax.plot([x_vu, p_end[0]], [0, p_end[1]], color=BLACK, lw=1.3)
  32. ax.plot(x_vu, 0, marker='+', ms=9, color=BLACK, mew=1.2)
  33. ax.text(x_vu + 0.12, 0.12, 'ВУ$_1$', fontsize=9, ha='left', va='bottom')
  34. # круговая кривая: R = T / tan(phi/2), центр на перпендикуляре из НК внутрь угла
  35. R = T / np.tan(phi / 2)
  36. o = np.array([x_nk, -R])
  37. t0, t1 = 90, np.degrees(np.arctan2(*(p_kk - o)[::-1]))
  38. arc = np.radians(np.linspace(t0, t1, 80))
  39. ax.plot(o[0] + R * np.cos(arc), o[1] + R * np.sin(arc), color=BLACK, lw=1.1,
  40. ls=(0, (5, 3)))
  41. ax.annotate('Круговая кривая,\nвписанная в угол поворота',
  42. xy=(o[0] + R * np.cos(np.radians(63)), o[1] + R * np.sin(np.radians(63))),
  43. xytext=(6.7, -2.35), fontsize=8, ha='left', va='center',
  44. arrowprops=dict(arrowstyle='->', color=BLACK, lw=0.7, shrinkA=2, shrinkB=2))
  45. # --- размерные линии: Lст/2, a, не менее 500 м (под трассой), T (над трассой) ----
  46. TICK, EXT = 0.08, 0.1
  47. def tick(x, y):
  48. ax.plot([x - TICK, x + TICK], [y - TICK, y + TICK], color=BLACK, lw=1.1,
  49. solid_capstyle='butt')
  50. def hdim(x1, x2, y, txt, above=False):
  51. for x in (x1, x2):
  52. y_end = y + EXT if above else y - EXT
  53. ax.plot([x, x], [0, y_end], color=BLACK, lw=0.5, zorder=1)
  54. tick(x, y)
  55. ax.plot([x1, x2], [y, y], color=BLACK, lw=0.7)
  56. ax.annotate('', xy=(x2, y), xytext=(x1, y),
  57. arrowprops=dict(arrowstyle='<|-|>', color=BLACK, lw=0.7,
  58. mutation_scale=8, shrinkA=0, shrinkB=0))
  59. ax.text((x1 + x2) / 2, y + (0.1 if above else -0.1), txt, fontsize=8,
  60. ha='center', va='bottom' if above else 'top')
  61. hdim(0.8, 3.0, -0.7, 'L$_ст$/2')
  62. hdim(3.0, 4.2, -0.7, 'a')
  63. hdim(4.2, x_nk, -0.7, 'не менее 500 м')
  64. hdim(x_nk, x_vu, 0.55, 'T', above=True)
  65. # --- стрелка севера ----------------------------------------------------------------
  66. cx, cy, r = 1.45, 1.65, 0.42
  67. ax.add_patch(plt.Circle((cx, cy), r, fill=False, color=BLACK, lw=0.8))
  68. ax.annotate('', xy=(cx, cy + r * 0.8), xytext=(cx, cy - r * 0.8),
  69. arrowprops=dict(arrowstyle='-|>', color=BLACK, lw=0.9, mutation_scale=10,
  70. shrinkA=0, shrinkB=0))
  71. fig.savefig('assets/images/laba2-nachalo-trassirovaniya.png', dpi=300, facecolor='white')
  72. print('сохранено: assets/images/laba2-nachalo-trassirovaniya.png')