ArcSegment绘制及计算

给定起始点、终止点和 bulge 值计算弧线中心点和半径,绘制ArcSegment

Arc

import math
def calculate_arc_center_and_radius(x1, y1, x2, y2, bulge):
    angle=4*math.atan(bulge)
    # 计算弦中点
    mid_x = (x1 + x2) / 2
    mid_y = (y1 + y2) / 2

    # 计算弦长的一半
    d = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)/2

    # 计算弦高
    H = d /( math.tan(angle/2))

    # 计算垂直平分线方向向量
    vx = -(y2 - y1)
    vy = x2 - x1
    v_length = math.sqrt(vx ** 2 + vy ** 2)
    vx = vx / v_length
    vy = vy / v_length

    # 计算中心点
    center_x = mid_x + H* vx
    center_y = mid_y + H* vy

    # 计算半径
    radius = d / math.sin(angle/2)
    
    return center_x, center_y, radius


# 示例调用
x1, y1 = 39564665.788517535, 4750770.424909098
x2, y2 = 39564473.427429944, 4750676.86151416
bulge = 0.6132243710677102
center_x, center_y, radius = calculate_arc_center_and_radius(x1, y1, x2, y2, bulge)
print(f"中心点: ({center_x}, {center_y}), 半径: {radius}")

#中心点: (39564593.40816512, 4750674.711354235), 半径: 120.0000000018731

相关链接

  1. https://blog.csdn.net/mrbaolong/article/details/143597382?spm=1001.2014.3001.5501
Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐