Ai
1 Star 0 Fork 0

zq_online/python-math

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
pingxingxian2.py 1.87 KB
一键复制 编辑 原始数据 按行查看 历史
zq_online 提交于 2024-01-27 13:11 +08:00 . Initial commit
import matplotlib.pyplot as plt
import math
def draw_parallel_lines_and_angles(corresponding_angles, alternate_interior_angles):
# 定义两条平行线及其交于第三条直线的位置
x1 = -5
y1 = 0
x2 = 5
y2 = 0
x3 = 0
y3 = 3
fig, ax = plt.subplots(figsize=(6, 6))
# 绘制两条平行线
ax.plot([x1, x2], [y1, y1], 'k-', label='Parallel Line 1')
ax.plot([x1, x2], [y3, y3], 'k--', label='Parallel Line 2')
# 绘制与平行线相交的第三条直线
ax.plot([x1, x3], [y1, y3], 'r-', label='Transversal')
# 计算并标注角度
for i in range(2):
# 同位角标注
angle_corresponding_rad = corresponding_angles[i]
x4 = x3 + 1.5 * math.cos(angle_corresponding_rad)
y4 = y3 + 1.5 * math.sin(angle_corresponding_rad)
ax.plot([x3, x4], [y3, y4], 'b-')
ax.annotate(f'{math.degrees(angle_corresponding_rad):.1f}°', xy=(x4, y4),
xytext=(x4 + 0.5, y4 + 0.5),
arrowprops=dict(facecolor='black', shrink=0.05))
# 内错角标注
angle_alternate_rad = alternate_interior_angles[i]
x5 = x2 if i == 0 else x1
y5 = y3 + 1.5 * math.sin(angle_alternate_rad)
ax.plot([x5, x3], [y3, y5], 'g-')
ax.annotate(f'{math.degrees(angle_alternate_rad):.1f}°', xy=(x3, y5),
xytext=(x3 + 0.5, y5 + 0.5),
arrowprops=dict(facecolor='black', shrink=0.05))
# 添加图例和坐标轴标签
ax.legend()
ax.set_xlim([-6, 6])
ax.set_ylim([-1, 6])
ax.axis('off')
# 显示图形
plt.show()
# 示例数据:假设两组同位角和内错角都是相等的
corresponding_angles = [math.pi / 4, math.pi / 4] # 同位角
alternate_interior_angles = [math.pi / 3, math.pi / 3] # 内错角
draw_parallel_lines_and_angles(corresponding_angles, alternate_interior_angles)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/createmaker/python-math.git
git@gitee.com:createmaker/python-math.git
createmaker
python-math
python-math
master

搜索帮助