""" 大 小 英文 中文 常用指代意义 Α α alpha 阿尔法 角度、系数、角加速度、第一个、电离度、转化率 Β β beta 贝塔 磁通系数、角度、系数 Γ γ gamma 伽玛 电导系数、角度、比热容比 Δ δ delta 得尔塔 变化量、焓变、熵变、屈光度、一元二次方程中的判别式、化学位移 Ε ε epsilon 艾普西隆 对数之基数、介电常数、电容率 Ζ ζ zeta 泽塔 系数、方位角、阻抗、相对黏度 Η η eta 伊塔 迟滞系数、机械效率 Θ θ theta 西塔 温度、角度 Ι ι iota 约(yāo)塔 微小、一点 Κ κ kappa 卡帕 介质常数、绝热指数 ∧ λ lambda 拉姆达 波长、体积、导热系数 普朗克常数 Μ μ mu 谬 磁导率、微、动摩擦系(因)数、流体动力黏度、货币单位,莫比乌斯函数 Ν ν nu 纽 磁阻系数、流体运动粘度、光波频率、化学计量数 Ξ ξ xi 克西 随机变量、(小)区间内的一个未知特定值 Ο ο omicron 奥米克戎 高阶无穷小函数 ∏ π pi 派 圆周率、π(n)表示不大于n的质数个数、连乘 Ρ ρ rho 柔 电阻率、柱坐标和极坐标中的极径、密度、曲率半径 ∑ σ,ς sigma 西格马 总和、表面密度、跨导、正应力、电导率 Τ τ tau 陶 时间常数、切应力、2π(两倍圆周率) Υ υ upsilon 阿普西龙 位移 Φ φ phi 斐 磁通量、电通量、角、透镜焦度、热流量、电势、直径、空集、欧拉函数 Χ χ chi 希 统计学中有卡方(χ^2)分布 Ψ ψ psi 普西 角速、介质电通量、ψ函数、磁链 Ω ω omega 欧米伽 欧姆、角速度、角频率、交流电的电角度、化学中的质量分数、不饱和度 """ import math import numpy import json # 道路名称列表 path_name_list = [ 'MN', 'KL', 'IJ', 'GH', 'EF', 'CD', 'AB', ] def get_path_name_by_pot_name(pot_name): """ 根据罐名获取道路名称 """ s1, s2 = pot_name.split('.') for item in path_name_list: if s1 in item: return item def get_two_end_point_by_theta_and_delta(start_point=(1, 1), theta=45, delta=1.1): """ 获取指定偏移量的两个点 """ start_point_x = start_point[0] start_point_y = start_point[1] theta = degrees_to_radians(theta) x1 = start_point_x + (delta * numpy.cos(theta)) y1 = start_point_y + (delta * numpy.sin(theta)) x2 = start_point_x - (delta * numpy.cos(theta)) y2 = start_point_y - (delta * numpy.sin(theta)) # print(f"dubug.136: p1: {(x1, y1)}, p2: {(x2, y2)}") return (x1, y1), (x2, y2) def get_distance_by_two_point(A=(1, 1), B=(1, 1)): """ 求两点之间的距离 """ A_x = float(A[0]) A_y = float(A[1]) B_x = float(B[0]) B_y = float(B[1]) distance = ((A_x - B_x) ** 2 + ((A_y - B_y) ** 2)) ** (1 / 2) # print(f"dubug.53: 点{A}、点{B},距离为{s}") return distance # def get_point_by_k_and_s(k=3, s=10): # """ # 已知一个点坐标,和一条线斜率,求顺着这条线指定距离后的坐标 # """ # # 计算倾斜角度 theta | θ = arctan(k) # theta = numpy.arctan(k) # # # 计算新点坐标 (x2, y2) # x2 = x1 + (s * math.cos(theta)) # y2 = y1 + (s * math.sin(theta)) # # print(f"dubug.67: 增加{s}单位长度后的新点坐标 ({x2}, {y2})") # return x2, y2 def get_a_and_b_by_c_and_min_theta(c=13.7, min_theta=1): """ 根据直角三角形最小角和斜边,计算直角三角形直角边a、b """ a = c * numpy.sin(degrees_to_radians(min_theta)) b = c * numpy.cos(degrees_to_radians(min_theta)) return a, b # def calc_theta(): # """ # 计算倾斜角度 # """ # import math # # # 已知函数 y = 3x + 2 # def f(x): # return 3 * x + 2 # # # 已知点的坐标 (x1, y1) # x1 = 1 # y1 = f(x1) # # # 计算斜率 k # k = 3 # # # 计算倾斜角度 theta | θ = arctan(k) # theta = math.atan(k) # # # 计算新点坐标 (x2, y2) # delta_x = 10 * math.cos(theta) # delta_y = 10 * math.sin(theta) # # x2 = x1 + delta_x # y2 = y1 + delta_y # # print("已知点坐标 (x1, y1) =", (x1, y1)) # print("增加 10 个单位长度后的新点坐标 (x2, y2) =", (x2, y2)) def get_k_and_b_by_points(A, B): """ 计算k与b pip install sympy==1.12 """ x1 = A[0] y1 = A[1] x2 = B[0] y2 = B[1] from sympy import symbols, Eq, solve, Symbol k = Symbol('k') b = Symbol('b') eqs = [Eq(k * x1 + b, y1), Eq(k * x2 + b, y2)] result = solve(eqs, [k, b]) k = result.get(k) b = result.get(b) # print(f"dubug.119: y = {k}x + {b}") return k, b def get_theta_by_k(k): """ 根据斜率计算夹角 """ theta = numpy.arctan(float(k)) # print(f"dubug.128: theta: {radians_to_degrees(theta)}") return theta def degrees_to_radians(degrees): """角度转弧度""" return numpy.radians(degrees) def radians_to_degrees(radians): """弧度转角度""" return numpy.degrees(radians) def get_pi(): """圆周率""" return numpy.pi def get_radians_for_90(): """获取90度对应的弧度""" return numpy.pi / 2 def main(MN01, MN31, A01, A31): """ """ # --- fill v1 巷道间隔距离 --- distance = get_distance_by_two_point(A01, MN01) v1 = distance / 7 # print(f"debug.164: 巷道间隔距离: {v1}") # --- fill v2 坐标系偏移角度 --- k, b = get_k_and_b_by_points(A01, MN01) v2 = get_theta_by_k(k) v2 = radians_to_degrees(v2) print(f"debug.164: 坐标系偏移角度: {90-v2}") # --- fill d1 --- _, KL01 = get_two_end_point_by_theta_and_delta(start_point=MN01, theta=v2, delta=v1) _, IJ01 = get_two_end_point_by_theta_and_delta(start_point=MN01, theta=v2, delta=v1 * 2) _, GH01 = get_two_end_point_by_theta_and_delta(start_point=MN01, theta=v2, delta=v1 * 3) _, EF01 = get_two_end_point_by_theta_and_delta(start_point=MN01, theta=v2, delta=v1 * 4) _, CD01 = get_two_end_point_by_theta_and_delta(start_point=MN01, theta=v2, delta=v1 * 5) _, AB01 = get_two_end_point_by_theta_and_delta(start_point=MN01, theta=v2, delta=v1 * 6) # print(f"debug.164: MN01: {MN01}") # print(f"debug.164: KL01: {KL01}") # print(f"debug.164: IJ01: {IJ01}") # print(f"debug.164: GH01: {GH01}") # print(f"debug.164: EF01: {EF01}") # print(f"debug.164: CD01: {CD01}") # print(f"debug.164: AB01: {AB01}") # print(f"debug.164: A01: {A01}") d1 = { 'MN.1': MN01, 'KL.1': KL01, 'IJ.1': IJ01, 'GH.1': GH01, 'EF.1': EF01, 'CD.1': CD01, 'AB.1': AB01, } # --- fill v3 巷道间隔距离 --- distance = get_distance_by_two_point(A31, MN31) v3 = distance / 7 # print(f"debug.188: 巷道间隔距离: {v3}") # --- fill v4 坐标系偏移角度 --- k, b = get_k_and_b_by_points(A31, MN31) v4 = get_theta_by_k(k) v4 = radians_to_degrees(v4) print(f"debug.194: 坐标系偏移角度: {90-v4}") # --- fill d2 --- _, KL31 = get_two_end_point_by_theta_and_delta(start_point=MN31, theta=v4, delta=v3) _, IJ31 = get_two_end_point_by_theta_and_delta(start_point=MN31, theta=v4, delta=v3 * 2) _, GH31 = get_two_end_point_by_theta_and_delta(start_point=MN31, theta=v4, delta=v3 * 3) _, EF31 = get_two_end_point_by_theta_and_delta(start_point=MN31, theta=v4, delta=v3 * 4) _, CD31 = get_two_end_point_by_theta_and_delta(start_point=MN31, theta=v4, delta=v3 * 5) _, AB31 = get_two_end_point_by_theta_and_delta(start_point=MN31, theta=v4, delta=v3 * 6) # print(f"debug.233: MN31: {MN31}") # print(f"debug.233: KL31: {KL31}") # print(f"debug.233: IJ31: {IJ31}") # print(f"debug.233: GH31: {GH31}") # print(f"debug.233: EF31: {EF31}") # print(f"debug.233: CD31: {CD31}") # print(f"debug.233: AB31: {AB31}") # print(f"debug.233: A31: {A31}") d2 = { 'MN.31': MN31, 'KL.31': KL31, 'IJ.31': IJ31, 'GH.31': GH31, 'EF.31': EF31, 'CD.31': CD31, 'AB.31': AB31, } # --- fill pot_point_list --- pot_point_list = list() for i in list(['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N']): for j in list(range(31)): # --- set --- pot_name = f"{i}.{j + 1}" # 罐位名称 path_name = get_path_name_by_pot_name(pot_name) XX01 = d1.get(f"{path_name}.1") XX31 = d2.get(f"{path_name}.31") # --- get v5 --- distance = get_distance_by_two_point(XX01, XX31) v5 = distance / 30 # --- get v6 --- k, b = get_k_and_b_by_points(XX01, XX31) v6 = radians_to_degrees(get_theta_by_k(k)) # --- get road_center --- road_center, _ = get_two_end_point_by_theta_and_delta(start_point=XX01, theta=v6, delta=v5 * (j + 1 - 1)) road_center_x = road_center[0] # 道路中心坐标 road_center_y = road_center[1] # 道路中心坐标 # --- update --- data_string = f"{pot_name}|{0}|{0}|{road_center_x}|{road_center_y}" # print(data_string) pot_point_list.append(data_string) # --- check --- print(f"debug.300: total: {len(pot_point_list)}") if len(pot_point_list) != 434: raise "Error: 数据不全" # --- fill json_data_dict --- json_data_dict = { "title": "渣罐坐标数据", "pot_name|pot_x|pot_y|road_center_x|road_center_y": pot_point_list, "total": len(pot_point_list), } # --- save 渣罐坐标数据 --- with open('渣罐坐标数据.json', "w", encoding='utf-8') as f: json.dump(json_data_dict, f, indent=4, sort_keys=True, ensure_ascii=False) # --- get v7 转弯半径 --- distance = get_distance_by_two_point(A01, MN01) v7 = distance / 14 # print(f"debug.309: 转弯半径: {v7}") # --- fill d5 --- _, LMhead = get_two_end_point_by_theta_and_delta(start_point=MN01, theta=v2, delta=v7) _, JKhead = get_two_end_point_by_theta_and_delta(start_point=MN01, theta=v2, delta=v7 * 3) _, HIhead = get_two_end_point_by_theta_and_delta(start_point=MN01, theta=v2, delta=v7 * 5) _, FGhead = get_two_end_point_by_theta_and_delta(start_point=MN01, theta=v2, delta=v7 * 7) _, DEhead = get_two_end_point_by_theta_and_delta(start_point=MN01, theta=v2, delta=v7 * 9) _, BChead = get_two_end_point_by_theta_and_delta(start_point=MN01, theta=v2, delta=v7 * 11) _, Ahead = get_two_end_point_by_theta_and_delta(start_point=MN01, theta=v2, delta=v7 * 13) # print(f"debug.327: LMhead: {LMhead}") # print(f"debug.327: JKhead: {JKhead}") # print(f"debug.327: HIhead: {HIhead}") # print(f"debug.327: FGhead: {FGhead}") # print(f"debug.327: DEhead: {DEhead}") # print(f"debug.327: BChead: {BChead}") # print(f"debug.327: Ahead: {Ahead}") d5 = { 'LM.head': LMhead, 'JK.head': JKhead, 'HI.head': HIhead, 'FG.head': FGhead, 'DE.head': DEhead, 'BC.head': BChead, 'A.head': Ahead, } # print(f"debug.355: 转弯半径: {d5}") # --- test --- # print(f"debug.339: 最小角度: {90 - v2}") # print(f"debug.339: 斜边 c: {v7}") # short, long = get_a_and_b_by_c_and_min_theta(v7, 90 - v2) # print(f"debug.339: 直角边 a: {short}") # print(f"debug.339: 直角边 b: {long}") # --- fill centers_list --- centers_list = list() for k, v in d5.items(): # --- set --- center_x, center_y = v short, long = get_a_and_b_by_c_and_min_theta(v7, 90 - v2) data_string = f"{k}|{center_x}|{center_y}" # --- get center_3_x center_3_y --- 顺时针偏移一定角度 center_3_x = center_x + long center_3_y = center_y - short data_string += f"|{center_3_x}|{center_3_y}" # --- get center_9_x center_9_y --- 顺时针偏移一定角度 center_9_x = center_x - long center_9_y = center_y + short data_string += f"|{center_9_x}|{center_9_y}" # --- get center_12_x center_12_y --- 顺时针偏移一定角度 center_12_x = center_x + short center_12_y = center_y + long data_string += f"|{center_12_x}|{center_12_y}" # --- get center_6_x center_6_y --- 顺时针偏移一定角度 center_6_x = center_x - short center_6_y = center_y - long data_string += f"|{center_6_x}|{center_6_y}" # --- append --- centers_list.append(data_string) # --- get v201 转弯半径 --- distance = get_distance_by_two_point(A31, MN31) v201 = distance / 14 print(f"debug.309: 转弯半径: {v201}") # --- fill tail_center_dict --- _, LMtail = get_two_end_point_by_theta_and_delta(start_point=MN31, theta=v4, delta=v201) _, JKtail = get_two_end_point_by_theta_and_delta(start_point=MN31, theta=v4, delta=v201 * 3) _, HItail = get_two_end_point_by_theta_and_delta(start_point=MN31, theta=v4, delta=v201 * 5) _, FGtail = get_two_end_point_by_theta_and_delta(start_point=MN31, theta=v4, delta=v201 * 7) _, DEtail = get_two_end_point_by_theta_and_delta(start_point=MN31, theta=v4, delta=v201 * 9) _, BCtail = get_two_end_point_by_theta_and_delta(start_point=MN31, theta=v4, delta=v201 * 11) _, Atail = get_two_end_point_by_theta_and_delta(start_point=MN31, theta=v4, delta=v201 * 13) # print(f"debug.397: LMtail: {LMtail}") # print(f"debug.397: MN31: {MN31}") tail_center_dict = { 'LM.tail': LMtail, 'JK.tail': JKtail, 'HI.tail': HItail, 'FG.tail': FGtail, 'DE.tail': DEtail, 'BC.tail': BCtail, 'A.tail': Atail, } # print(f"debug.355: 转弯半径: {d5}") # --- fill centers_list --- for k, v in tail_center_dict.items(): # --- set --- center_x, center_y = v short, long = get_a_and_b_by_c_and_min_theta(v201, 90 - v4) data_string = f"{k}|{center_x}|{center_y}" # --- get center_3_x center_3_y --- 顺时针偏移一定角度 center_3_x = center_x + long center_3_y = center_y - short data_string += f"|{center_3_x}|{center_3_y}" # --- get center_9_x center_9_y --- 顺时针偏移一定角度 center_9_x = center_x - long center_9_y = center_y + short data_string += f"|{center_9_x}|{center_9_y}" # --- get center_12_x center_12_y --- 顺时针偏移一定角度 center_12_x = center_x + short center_12_y = center_y + long data_string += f"|{center_12_x}|{center_12_y}" # --- get center_6_x center_6_y --- 顺时针偏移一定角度 center_6_x = center_x - short center_6_y = center_y - long data_string += f"|{center_6_x}|{center_6_y}" # --- append --- centers_list.append(data_string) # --- fill json_data_dict --- json_data_dict = { "title": "圆心坐标数据", "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, "total": len(centers_list), } # --- save 渣罐坐标数据 --- with open('圆心坐标数据.json', "w", encoding='utf-8') as f: json.dump(json_data_dict, f, indent=4, sort_keys=True, ensure_ascii=False) if __name__ == '__main__': # --- 自测数据 --- L1 = 2, 2 L31 = 3, 1 N1 = 3, 3 N31 = 4, 2 # --- 大冶现场数据 --- """ 18.618844 200.675670 mn-1 "M.1|0|0|18.618844|200.67567", 14.24217 8.016018 a-1 179.503282 5.019985 a-31 183.184822 197.312110 mn-31 "M.31|0|0|183.184822|197.31211", """ MN01 = 18.618844, 200.675670 A01 = 14.24217, 8.016018 A31 = 179.503282, 5.019985 MN31 = 183.184822, 197.312110 # --- test --- main(MN01, MN31, A01, A31)