4.1 绘制平面图形
4.1.1 绘制三角形
解题思路:
- 使用直尺和圆规,首先绘制一条直线作为三角形的底边。
- 在底边的两端分别作圆,半径大于底边长度的一半。
- 两个圆的交点即为三角形的顶点。
- 连接三个顶点,得到所求三角形。
示例代码:
import matplotlib.pyplot as plt
import numpy as np
# 定义底边长度
base_length = 5
# 绘制底边
plt.plot([0, base_length], [0, 0], 'b')
# 绘制圆
theta = np.linspace(0, 2 * np.pi, 100)
plt.plot(base_length / 2 * np.cos(theta), base_length / 2 * np.sin(theta), 'r')
# 求交点
intersection_points = plt.ginput(2)
# 连接顶点
plt.plot([intersection_points[0][0], intersection_points[1][0]], [intersection_points[0][1], intersection_points[1][1]], 'g')
plt.show()
4.1.2 绘制正方形
解题思路:
- 使用直尺和圆规,首先绘制一条直线作为正方形的一边。
- 在直线的两端分别作圆,半径等于边长。
- 两个圆的交点即为正方形的顶点。
- 连接四个顶点,得到所求正方形。
示例代码:
import matplotlib.pyplot as plt
import numpy as np
# 定义边长
side_length = 5
# 绘制边
plt.plot([0, side_length], [0, 0], 'b')
# 绘制圆
theta = np.linspace(0, 2 * np.pi, 100)
plt.plot(side_length / 2 * np.cos(theta), side_length / 2 * np.sin(theta), 'r')
# 求交点
intersection_points = plt.ginput(2)
# 连接顶点
plt.plot([intersection_points[0][0], intersection_points[1][0]], [intersection_points[0][1], intersection_points[1][1]], 'g')
plt.show()
4.2 绘制空间图形
4.2.1 绘制球体
解题思路:
- 使用直尺和圆规,首先绘制一个圆作为球体的底面。
- 在圆的中心处作一个点,作为球体的球心。
- 以球心为圆心,半径为球体半径的圆,表示球体的侧面。
- 连接球心与圆上的点,得到所求球体。
示例代码:
import matplotlib.pyplot as plt
import numpy as np
# 定义球体半径
radius = 5
# 绘制底面圆
theta = np.linspace(0, 2 * np.pi, 100)
plt.plot(radius * np.cos(theta), radius * np.sin(theta), 'b')
# 绘制侧面圆
theta = np.linspace(0, 2 * np.pi, 100)
plt.plot(radius * np.cos(theta), radius * np.sin(theta), 'r')
# 连接球心与圆上的点
plt.plot([0, radius], [0, 0], 'g')
plt.show()
4.2.2 绘制圆柱体
解题思路:
- 使用直尺和圆规,首先绘制一个圆作为圆柱体的底面。
- 在圆的中心处作一个点,作为圆柱体的球心。
- 以球心为圆心,半径为圆柱体半径的圆,表示圆柱体的侧面。
- 连接球心与圆上的点,得到所求圆柱体。
示例代码:
import matplotlib.pyplot as plt
import numpy as np
# 定义圆柱体半径和高
radius = 5
height = 10
# 绘制底面圆
theta = np.linspace(0, 2 * np.pi, 100)
plt.plot(radius * np.cos(theta), radius * np.sin(theta), 'b')
# 绘制侧面圆
theta = np.linspace(0, 2 * np.pi, 100)
plt.plot(radius * np.cos(theta), radius * np.sin(theta), 'r')
# 连接球心与圆上的点
plt.plot([0, radius], [0, 0], 'g')
# 绘制圆柱体的高
plt.plot([0, 0], [0, height], 'y')
plt.show()
