#计算中桩坐标 import math #直曲表 sheet_align = sheet("alignment_table") #坐标计算表 sheet_coord = sheet("coord_calc") row1 = 4 row2 = 2 with sheet_align: ss1 = 0 while not sheet_coord[row2, 1].empty(): lxzh = sheet_coord[row2, 1].value #待计算点桩号 xjd = cell(row1, 1).value #交点x坐标 yjd = cell(row1, 2).value #交点y坐标 kjd = cell(row1, 3).value #jd点桩号 a0 = cell(row1, 20).value #后切线方位角 if cell(row1, 13).empty(): x = xjd - (kjd - lxzh) * math.cos(a0) y = yjd - (kjd - lxzh) * math.sin(a0) sheet_coord[row2, 2].value = x sheet_coord[row2, 3].value = y sheet_coord[row2, 4].value = a0 else: a1 = cell(row1 + 1, 20).value #前切线方位角 r = cell(row1, 6).value #圆曲线半径 ls1 = cell(row1, 7).value #第一缓和曲线长 ls2 = cell(row1, 8).value #第二缓和曲线长 t1 = cell(row1, 9).value #第一切线长 t2 = cell(row1, 10).value #第二切线长 ll = cell(row1, 11).value #曲线长 ly = ll - ls1 - ls2 #圆曲线长 kzh = cell(row1, 13).value #zh点桩号 khy = cell(row1, 14).value #hy点桩号 kqz = cell(row1, 15).value #qz点桩号 kyh = cell(row1, 16).value #yh点桩号 khz = cell(row1, 17).value #hz点桩号 zy = cell(row1, 21).value #路线左右偏代码 if lxzh <= kzh: #直线段上的点 l = kzh - lxzh x = xjd - (t1 + l) * math.cos(a0) y = yjd - (t1 + l) * math.sin(a0) sheet_coord[row2, 2].value = x sheet_coord[row2, 3].value = y sheet_coord[row2, 4].value = a0 elif lxzh > kzh and lxzh < khy: #第一回旋线上的点 if ss1 != 3: x1 = xjd - t1 * math.cos(a0) y1 = yjd - t1 * math.sin(a0) ss1 = 3 l = lxzh - kzh xp = l - l ** 5 / (40 * (r * ls1) ** 2) + l ** 9 / (3456 * (r * ls1) ** 4) yp = l ** 3 / (6 * r * ls1) - l ** 7 / (336 * (r * ls1) ** 3) + l ** 11 / (42240 * (r * ls1) ** 5) x = x1 + xp * math.cos(a0) - zy * yp * math.sin(a0) y = y1 + xp * math.sin(a0) + zy * yp * math.cos(a0) b = a0 + zy * l * l / (2 * r * ls1) b %= math.pi * 2 sheet_coord[row2, 2].value = x sheet_coord[row2, 3].value = y sheet_coord[row2, 4].value = b elif lxzh >= khy and lxzh <= kyh: #圆曲线上的点 if ss1 != 4: x1 = xjd - t1 * math.cos(a0) y1 = yjd - t1 * math.sin(a0) q1 = ls1 / 2 - ls1 ** 3 / (240 * r ** 2) + ls1 ** 5 / (34560 * r ** 4) p1 = ls1 ** 2 / (24 * r) - ls1 ** 4 / (2688 * r ** 3) + ls1 ** 6 / (506880 * r ** 5) ss1 = 4 l = lxzh - kzh tp = (2 * l - ls1) / 2 / r xp = r * math.sin(tp) + q1 yp = r * (1 - math.cos(tp)) + p1 x = x1 + xp * math.cos(a0) - zy * yp * math.sin(a0) y = y1 + xp * math.sin(a0) + zy * yp * math.cos(a0) b = a0 + zy * tp b %= math.pi * 2 sheet_coord[row2, 2].value = x sheet_coord[row2, 3].value = y sheet_coord[row2, 4].value = b elif lxzh > kyh and lxzh < khz: #第二回旋线上的点 if ss1 != 5: x1 = xjd + t2 * math.cos(a1) y1 = yjd + t2 * math.sin(a1) ss1 = 5 l = khz - lxzh xp = l - l ** 5 / (40 * (r * ls2) ** 2) + l ** 9 / (3456 * (r * ls2) ** 4) yp = l ** 3 / (6 * r * ls2) - l ** 7 / (336 * (r * ls2) ** 3) + l ** 11 / (42240 * (r * ls2) ** 5) x = x1 - xp * math.cos(a1) - zy * yp * math.sin(a1) y = y1 - xp * math.sin(a1) + zy * yp * math.cos(a1) b = a1 - zy * l * l / (2 * ls2 * r) b %= math.pi * 2 sheet_coord[row2, 2].value = x sheet_coord[row2, 3].value = y sheet_coord[row2, 4].value = b else: ss1 = 10 row1 += 1 row2 -= 1 row2 += 1 sheet_coord.fit_content()