SRI2024032814-4point.py 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. """
  2. 大 小 英文 中文 常用指代意义
  3. Α α alpha 阿尔法 角度、系数、角加速度、第一个、电离度、转化率
  4. Β β beta 贝塔 磁通系数、角度、系数
  5. Γ γ gamma 伽玛 电导系数、角度、比热容比
  6. Δ δ delta 得尔塔 变化量、焓变、熵变、屈光度、一元二次方程中的判别式、化学位移
  7. Ε ε epsilon 艾普西隆 对数之基数、介电常数、电容率
  8. Ζ ζ zeta 泽塔 系数、方位角、阻抗、相对黏度
  9. Η η eta 伊塔 迟滞系数、机械效率
  10. Θ θ theta 西塔 温度、角度
  11. Ι ι iota 约(yāo)塔 微小、一点
  12. Κ κ kappa 卡帕 介质常数、绝热指数
  13. ∧ λ lambda 拉姆达 波长、体积、导热系数 普朗克常数
  14. Μ μ mu 谬 磁导率、微、动摩擦系(因)数、流体动力黏度、货币单位,莫比乌斯函数
  15. Ν ν nu 纽 磁阻系数、流体运动粘度、光波频率、化学计量数
  16. Ξ ξ xi 克西 随机变量、(小)区间内的一个未知特定值
  17. Ο ο omicron 奥米克戎 高阶无穷小函数
  18. ∏ π pi 派 圆周率、π(n)表示不大于n的质数个数、连乘
  19. Ρ ρ rho 柔 电阻率、柱坐标和极坐标中的极径、密度、曲率半径
  20. ∑ σ,ς sigma 西格马 总和、表面密度、跨导、正应力、电导率
  21. Τ τ tau 陶 时间常数、切应力、2π(两倍圆周率)
  22. Υ υ upsilon 阿普西龙 位移
  23. Φ φ phi 斐 磁通量、电通量、角、透镜焦度、热流量、电势、直径、空集、欧拉函数
  24. Χ χ chi 希 统计学中有卡方(χ^2)分布
  25. Ψ ψ psi 普西 角速、介质电通量、ψ函数、磁链
  26. Ω ω omega 欧米伽 欧姆、角速度、角频率、交流电的电角度、化学中的质量分数、不饱和度
  27. """
  28. import math
  29. import numpy
  30. import json
  31. # 道路名称列表
  32. path_name_list = [
  33. 'MN',
  34. 'KL',
  35. 'IJ',
  36. 'GH',
  37. 'EF',
  38. 'CD',
  39. 'AB',
  40. ]
  41. def get_path_name_by_pot_name(pot_name):
  42. """
  43. 根据罐名获取道路名称
  44. """
  45. s1, s2 = pot_name.split('.')
  46. for item in path_name_list:
  47. if s1 in item:
  48. return item
  49. def get_two_end_point_by_theta_and_delta(start_point=(1, 1), theta=45, delta=1.1):
  50. """
  51. 获取指定偏移量的两个点
  52. """
  53. start_point_x = start_point[0]
  54. start_point_y = start_point[1]
  55. theta = degrees_to_radians(theta)
  56. x1 = start_point_x + (delta * numpy.cos(theta))
  57. y1 = start_point_y + (delta * numpy.sin(theta))
  58. x2 = start_point_x - (delta * numpy.cos(theta))
  59. y2 = start_point_y - (delta * numpy.sin(theta))
  60. # print(f"dubug.136: p1: {(x1, y1)}, p2: {(x2, y2)}")
  61. return (x1, y1), (x2, y2)
  62. def get_distance_by_two_point(A=(1, 1), B=(1, 1)):
  63. """
  64. 求两点之间的距离
  65. """
  66. A_x = float(A[0])
  67. A_y = float(A[1])
  68. B_x = float(B[0])
  69. B_y = float(B[1])
  70. distance = ((A_x - B_x) ** 2 + ((A_y - B_y) ** 2)) ** (1 / 2)
  71. # print(f"dubug.53: 点{A}、点{B},距离为{s}")
  72. return distance
  73. # def get_point_by_k_and_s(k=3, s=10):
  74. # """
  75. # 已知一个点坐标,和一条线斜率,求顺着这条线指定距离后的坐标
  76. # """
  77. # # 计算倾斜角度 theta | θ = arctan(k)
  78. # theta = numpy.arctan(k)
  79. #
  80. # # 计算新点坐标 (x2, y2)
  81. # x2 = x1 + (s * math.cos(theta))
  82. # y2 = y1 + (s * math.sin(theta))
  83. # # print(f"dubug.67: 增加{s}单位长度后的新点坐标 ({x2}, {y2})")
  84. # return x2, y2
  85. def get_a_and_b_by_c_and_min_theta(c=13.7, min_theta=1):
  86. """
  87. 根据直角三角形最小角和斜边,计算直角三角形直角边a、b
  88. """
  89. a = c * numpy.sin(degrees_to_radians(min_theta))
  90. b = c * numpy.cos(degrees_to_radians(min_theta))
  91. return a, b
  92. # def calc_theta():
  93. # """
  94. # 计算倾斜角度
  95. # """
  96. # import math
  97. #
  98. # # 已知函数 y = 3x + 2
  99. # def f(x):
  100. # return 3 * x + 2
  101. #
  102. # # 已知点的坐标 (x1, y1)
  103. # x1 = 1
  104. # y1 = f(x1)
  105. #
  106. # # 计算斜率 k
  107. # k = 3
  108. #
  109. # # 计算倾斜角度 theta | θ = arctan(k)
  110. # theta = math.atan(k)
  111. #
  112. # # 计算新点坐标 (x2, y2)
  113. # delta_x = 10 * math.cos(theta)
  114. # delta_y = 10 * math.sin(theta)
  115. #
  116. # x2 = x1 + delta_x
  117. # y2 = y1 + delta_y
  118. #
  119. # print("已知点坐标 (x1, y1) =", (x1, y1))
  120. # print("增加 10 个单位长度后的新点坐标 (x2, y2) =", (x2, y2))
  121. def get_k_and_b_by_points(A, B):
  122. """
  123. 计算k与b
  124. pip install sympy==1.12
  125. """
  126. x1 = A[0]
  127. y1 = A[1]
  128. x2 = B[0]
  129. y2 = B[1]
  130. from sympy import symbols, Eq, solve, Symbol
  131. k = Symbol('k')
  132. b = Symbol('b')
  133. eqs = [Eq(k * x1 + b, y1), Eq(k * x2 + b, y2)]
  134. result = solve(eqs, [k, b])
  135. k = result.get(k)
  136. b = result.get(b)
  137. # print(f"dubug.119: y = {k}x + {b}")
  138. return k, b
  139. def get_theta_by_k(k):
  140. """
  141. 根据斜率计算夹角
  142. """
  143. theta = numpy.arctan(float(k))
  144. # print(f"dubug.128: theta: {radians_to_degrees(theta)}")
  145. return theta
  146. def degrees_to_radians(degrees):
  147. """角度转弧度"""
  148. return numpy.radians(degrees)
  149. def radians_to_degrees(radians):
  150. """弧度转角度"""
  151. return numpy.degrees(radians)
  152. def get_pi():
  153. """圆周率"""
  154. return numpy.pi
  155. def get_radians_for_90():
  156. """获取90度对应的弧度"""
  157. return numpy.pi / 2
  158. def main(MN01, MN31, A01, A31):
  159. """
  160. """
  161. # --- fill v1 巷道间隔距离 ---
  162. distance = get_distance_by_two_point(A01, MN01)
  163. v1 = distance / 7
  164. # print(f"debug.164: 巷道间隔距离: {v1}")
  165. # --- fill v2 坐标系偏移角度 ---
  166. k, b = get_k_and_b_by_points(A01, MN01)
  167. v2 = get_theta_by_k(k)
  168. v2 = radians_to_degrees(v2)
  169. print(f"debug.164: 坐标系偏移角度: {90-v2}")
  170. # --- fill d1 ---
  171. _, KL01 = get_two_end_point_by_theta_and_delta(start_point=MN01, theta=v2, delta=v1)
  172. _, IJ01 = get_two_end_point_by_theta_and_delta(start_point=MN01, theta=v2, delta=v1 * 2)
  173. _, GH01 = get_two_end_point_by_theta_and_delta(start_point=MN01, theta=v2, delta=v1 * 3)
  174. _, EF01 = get_two_end_point_by_theta_and_delta(start_point=MN01, theta=v2, delta=v1 * 4)
  175. _, CD01 = get_two_end_point_by_theta_and_delta(start_point=MN01, theta=v2, delta=v1 * 5)
  176. _, AB01 = get_two_end_point_by_theta_and_delta(start_point=MN01, theta=v2, delta=v1 * 6)
  177. # print(f"debug.164: MN01: {MN01}")
  178. # print(f"debug.164: KL01: {KL01}")
  179. # print(f"debug.164: IJ01: {IJ01}")
  180. # print(f"debug.164: GH01: {GH01}")
  181. # print(f"debug.164: EF01: {EF01}")
  182. # print(f"debug.164: CD01: {CD01}")
  183. # print(f"debug.164: AB01: {AB01}")
  184. # print(f"debug.164: A01: {A01}")
  185. d1 = {
  186. 'MN.1': MN01,
  187. 'KL.1': KL01,
  188. 'IJ.1': IJ01,
  189. 'GH.1': GH01,
  190. 'EF.1': EF01,
  191. 'CD.1': CD01,
  192. 'AB.1': AB01,
  193. }
  194. # --- fill v3 巷道间隔距离 ---
  195. distance = get_distance_by_two_point(A31, MN31)
  196. v3 = distance / 7
  197. # print(f"debug.188: 巷道间隔距离: {v3}")
  198. # --- fill v4 坐标系偏移角度 ---
  199. k, b = get_k_and_b_by_points(A31, MN31)
  200. v4 = get_theta_by_k(k)
  201. v4 = radians_to_degrees(v4)
  202. print(f"debug.194: 坐标系偏移角度: {90-v4}")
  203. # --- fill d2 ---
  204. _, KL31 = get_two_end_point_by_theta_and_delta(start_point=MN31, theta=v4, delta=v3)
  205. _, IJ31 = get_two_end_point_by_theta_and_delta(start_point=MN31, theta=v4, delta=v3 * 2)
  206. _, GH31 = get_two_end_point_by_theta_and_delta(start_point=MN31, theta=v4, delta=v3 * 3)
  207. _, EF31 = get_two_end_point_by_theta_and_delta(start_point=MN31, theta=v4, delta=v3 * 4)
  208. _, CD31 = get_two_end_point_by_theta_and_delta(start_point=MN31, theta=v4, delta=v3 * 5)
  209. _, AB31 = get_two_end_point_by_theta_and_delta(start_point=MN31, theta=v4, delta=v3 * 6)
  210. # print(f"debug.233: MN31: {MN31}")
  211. # print(f"debug.233: KL31: {KL31}")
  212. # print(f"debug.233: IJ31: {IJ31}")
  213. # print(f"debug.233: GH31: {GH31}")
  214. # print(f"debug.233: EF31: {EF31}")
  215. # print(f"debug.233: CD31: {CD31}")
  216. # print(f"debug.233: AB31: {AB31}")
  217. # print(f"debug.233: A31: {A31}")
  218. d2 = {
  219. 'MN.31': MN31,
  220. 'KL.31': KL31,
  221. 'IJ.31': IJ31,
  222. 'GH.31': GH31,
  223. 'EF.31': EF31,
  224. 'CD.31': CD31,
  225. 'AB.31': AB31,
  226. }
  227. # --- fill pot_point_list ---
  228. pot_point_list = list()
  229. for i in list(['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N']):
  230. for j in list(range(31)):
  231. # --- set ---
  232. pot_name = f"{i}.{j + 1}" # 罐位名称
  233. path_name = get_path_name_by_pot_name(pot_name)
  234. XX01 = d1.get(f"{path_name}.1")
  235. XX31 = d2.get(f"{path_name}.31")
  236. # --- get v5 ---
  237. distance = get_distance_by_two_point(XX01, XX31)
  238. v5 = distance / 30
  239. # --- get v6 ---
  240. k, b = get_k_and_b_by_points(XX01, XX31)
  241. v6 = radians_to_degrees(get_theta_by_k(k))
  242. # --- get road_center ---
  243. road_center, _ = get_two_end_point_by_theta_and_delta(start_point=XX01, theta=v6, delta=v5 * (j + 1 - 1))
  244. road_center_x = road_center[0] # 道路中心坐标
  245. road_center_y = road_center[1] # 道路中心坐标
  246. # --- update ---
  247. data_string = f"{pot_name}|{0}|{0}|{road_center_x}|{road_center_y}"
  248. # print(data_string)
  249. pot_point_list.append(data_string)
  250. # --- check ---
  251. print(f"debug.300: total: {len(pot_point_list)}")
  252. if len(pot_point_list) != 434:
  253. raise "Error: 数据不全"
  254. # --- fill json_data_dict ---
  255. json_data_dict = {
  256. "title": "渣罐坐标数据",
  257. "pot_name|pot_x|pot_y|road_center_x|road_center_y": pot_point_list,
  258. "total": len(pot_point_list),
  259. }
  260. # --- save 渣罐坐标数据 ---
  261. with open('渣罐坐标数据.json', "w", encoding='utf-8') as f:
  262. json.dump(json_data_dict, f, indent=4, sort_keys=True, ensure_ascii=False)
  263. # --- get v7 转弯半径 ---
  264. distance = get_distance_by_two_point(A01, MN01)
  265. v7 = distance / 14
  266. # print(f"debug.309: 转弯半径: {v7}")
  267. # --- fill d5 ---
  268. _, LMhead = get_two_end_point_by_theta_and_delta(start_point=MN01, theta=v2, delta=v7)
  269. _, JKhead = get_two_end_point_by_theta_and_delta(start_point=MN01, theta=v2, delta=v7 * 3)
  270. _, HIhead = get_two_end_point_by_theta_and_delta(start_point=MN01, theta=v2, delta=v7 * 5)
  271. _, FGhead = get_two_end_point_by_theta_and_delta(start_point=MN01, theta=v2, delta=v7 * 7)
  272. _, DEhead = get_two_end_point_by_theta_and_delta(start_point=MN01, theta=v2, delta=v7 * 9)
  273. _, BChead = get_two_end_point_by_theta_and_delta(start_point=MN01, theta=v2, delta=v7 * 11)
  274. _, Ahead = get_two_end_point_by_theta_and_delta(start_point=MN01, theta=v2, delta=v7 * 13)
  275. # print(f"debug.327: LMhead: {LMhead}")
  276. # print(f"debug.327: JKhead: {JKhead}")
  277. # print(f"debug.327: HIhead: {HIhead}")
  278. # print(f"debug.327: FGhead: {FGhead}")
  279. # print(f"debug.327: DEhead: {DEhead}")
  280. # print(f"debug.327: BChead: {BChead}")
  281. # print(f"debug.327: Ahead: {Ahead}")
  282. d5 = {
  283. 'LM.head': LMhead,
  284. 'JK.head': JKhead,
  285. 'HI.head': HIhead,
  286. 'FG.head': FGhead,
  287. 'DE.head': DEhead,
  288. 'BC.head': BChead,
  289. 'A.head': Ahead,
  290. }
  291. # print(f"debug.355: 转弯半径: {d5}")
  292. # --- test ---
  293. # print(f"debug.339: 最小角度: {90 - v2}")
  294. # print(f"debug.339: 斜边 c: {v7}")
  295. # short, long = get_a_and_b_by_c_and_min_theta(v7, 90 - v2)
  296. # print(f"debug.339: 直角边 a: {short}")
  297. # print(f"debug.339: 直角边 b: {long}")
  298. # --- fill centers_list ---
  299. centers_list = list()
  300. for k, v in d5.items():
  301. # --- set ---
  302. center_x, center_y = v
  303. short, long = get_a_and_b_by_c_and_min_theta(v7, 90 - v2)
  304. data_string = f"{k}|{center_x}|{center_y}"
  305. # --- get center_3_x center_3_y --- 顺时针偏移一定角度
  306. center_3_x = center_x + long
  307. center_3_y = center_y - short
  308. data_string += f"|{center_3_x}|{center_3_y}"
  309. # --- get center_9_x center_9_y --- 顺时针偏移一定角度
  310. center_9_x = center_x - long
  311. center_9_y = center_y + short
  312. data_string += f"|{center_9_x}|{center_9_y}"
  313. # --- get center_12_x center_12_y --- 顺时针偏移一定角度
  314. center_12_x = center_x + short
  315. center_12_y = center_y + long
  316. data_string += f"|{center_12_x}|{center_12_y}"
  317. # --- get center_6_x center_6_y --- 顺时针偏移一定角度
  318. center_6_x = center_x - short
  319. center_6_y = center_y - long
  320. data_string += f"|{center_6_x}|{center_6_y}"
  321. # --- append ---
  322. centers_list.append(data_string)
  323. # --- get v201 转弯半径 ---
  324. distance = get_distance_by_two_point(A31, MN31)
  325. v201 = distance / 14
  326. print(f"debug.309: 转弯半径: {v201}")
  327. # --- fill tail_center_dict ---
  328. _, LMtail = get_two_end_point_by_theta_and_delta(start_point=MN31, theta=v4, delta=v201)
  329. _, JKtail = get_two_end_point_by_theta_and_delta(start_point=MN31, theta=v4, delta=v201 * 3)
  330. _, HItail = get_two_end_point_by_theta_and_delta(start_point=MN31, theta=v4, delta=v201 * 5)
  331. _, FGtail = get_two_end_point_by_theta_and_delta(start_point=MN31, theta=v4, delta=v201 * 7)
  332. _, DEtail = get_two_end_point_by_theta_and_delta(start_point=MN31, theta=v4, delta=v201 * 9)
  333. _, BCtail = get_two_end_point_by_theta_and_delta(start_point=MN31, theta=v4, delta=v201 * 11)
  334. _, Atail = get_two_end_point_by_theta_and_delta(start_point=MN31, theta=v4, delta=v201 * 13)
  335. # print(f"debug.397: LMtail: {LMtail}")
  336. # print(f"debug.397: MN31: {MN31}")
  337. tail_center_dict = {
  338. 'LM.tail': LMtail,
  339. 'JK.tail': JKtail,
  340. 'HI.tail': HItail,
  341. 'FG.tail': FGtail,
  342. 'DE.tail': DEtail,
  343. 'BC.tail': BCtail,
  344. 'A.tail': Atail,
  345. }
  346. # print(f"debug.355: 转弯半径: {d5}")
  347. # --- fill centers_list ---
  348. for k, v in tail_center_dict.items():
  349. # --- set ---
  350. center_x, center_y = v
  351. short, long = get_a_and_b_by_c_and_min_theta(v201, 90 - v4)
  352. data_string = f"{k}|{center_x}|{center_y}"
  353. # --- get center_3_x center_3_y --- 顺时针偏移一定角度
  354. center_3_x = center_x + long
  355. center_3_y = center_y - short
  356. data_string += f"|{center_3_x}|{center_3_y}"
  357. # --- get center_9_x center_9_y --- 顺时针偏移一定角度
  358. center_9_x = center_x - long
  359. center_9_y = center_y + short
  360. data_string += f"|{center_9_x}|{center_9_y}"
  361. # --- get center_12_x center_12_y --- 顺时针偏移一定角度
  362. center_12_x = center_x + short
  363. center_12_y = center_y + long
  364. data_string += f"|{center_12_x}|{center_12_y}"
  365. # --- get center_6_x center_6_y --- 顺时针偏移一定角度
  366. center_6_x = center_x - short
  367. center_6_y = center_y - long
  368. data_string += f"|{center_6_x}|{center_6_y}"
  369. # --- append ---
  370. centers_list.append(data_string)
  371. # --- fill json_data_dict ---
  372. json_data_dict = {
  373. "title": "圆心坐标数据",
  374. "name|center_x|center_y|center_3_x|center_3_y|center_9_x|center_9_y|center_12_x|center_12_y|center_6_x|center_6_y": centers_list,
  375. "total": len(centers_list),
  376. }
  377. # --- save 渣罐坐标数据 ---
  378. with open('圆心坐标数据.json', "w", encoding='utf-8') as f:
  379. json.dump(json_data_dict, f, indent=4, sort_keys=True, ensure_ascii=False)
  380. if __name__ == '__main__':
  381. # --- 自测数据 ---
  382. L1 = 2, 2
  383. L31 = 3, 1
  384. N1 = 3, 3
  385. N31 = 4, 2
  386. # --- 大冶现场数据 ---
  387. """
  388. 18.618844 200.675670 mn-1 "M.1|0|0|18.618844|200.67567",
  389. 14.24217 8.016018 a-1
  390. 179.503282 5.019985 a-31
  391. 183.184822 197.312110 mn-31 "M.31|0|0|183.184822|197.31211",
  392. """
  393. MN01 = 18.618844, 200.675670
  394. A01 = 14.24217, 8.016018
  395. A31 = 179.503282, 5.019985
  396. MN31 = 183.184822, 197.312110
  397. # --- test ---
  398. main(MN01, MN31, A01, A31)