求解拱上各像素x、y坐标并编写对应Python函数的方法咨询

以下是适配常规抛物线拱的Python函数,可直接输出拱上所有点的x、y坐标:
默认坐标规则:
- 坐标原点设为拱左侧底部支座点,x轴水平向右,y轴竖直向上
- 右支座坐标为
(L, 0),拱顶最高点坐标为(L/2, f),其中L为拱总跨度,f为拱高,对应图中标注的核心参数
import numpy as np def get_arch_coordinates(span_L: float, rise_f: float, step: float = 1.0) -> list: """ 获取拱结构上所有点的坐标 :param span_L: 拱的总跨度长度 :param rise_f: 拱的拱顶高度 :param step: x方向采样步长,和像素单位对应即可,默认为1(1个步长对应1像素) :return: 存储所有(x,y)坐标的列表 """ # 生成x方向所有采样点 x_coords = np.arange(0, span_L + step, step) # 抛物线拱方程计算对应y坐标 y_coords = (4 * rise_f / (span_L ** 2)) * x_coords * (span_L - x_coords) # 组合成坐标列表,保留两位小数可按需调整精度 return [(round(x, 2), round(y, 2)) for x, y in zip(x_coords, y_coords)] # 调用示例,可按需替换参数 if __name__ == "__main__": arch_points = get_arch_coordinates(span_L=100, rise_f=20, step=1) # 打印前10个点验证结果 print(arch_points[:10])
如果你的拱是圆弧类型而非抛物线,替换y坐标的计算逻辑为对应圆弧方程即可。
内容的提问来源于stack exchange,提问作者Xor0x
相关产品推荐
相关产品推荐

