使用matplotlib绘制直角坐标系,画两个三角形,大三角形的坐标是(-5,0),(0,10),(5,0),小三角形的坐标是(-1,1),(0,5),(1,1),小三角形以(1,1)为中心顺时针转动
时间: 2024-03-31 16:37:42 浏览: 40
好的,我可以使用Python中的matplotlib库帮你绘制。代码如下:
```python
import matplotlib.pyplot as plt
import math
# 绘制大三角形
x1 = [-5, 0, 5, -5] # 大三角形的x坐标
y1 = [0, 10, 0, 0] # 大三角形的y坐标
plt.plot(x1, y1, color='blue')
# 绘制小三角形
theta = math.pi/4 # 旋转角度,单位为弧度
center_x, center_y = 1, 1 # 中心点坐标
x2 = [-1, 0, 1, -1] # 小三角形的x坐标
y2 = [1, 5, 1, 1] # 小三角形的y坐标
# 将小三角形绕中心点顺时针旋转theta角度
for i in range(len(x2)):
x2[i] = center_x + (x2[i] - center_x) * math.cos(theta) + (y2[i] - center_y) * math.sin(theta)
y2[i] = center_y - (x2[i] - center_x) * math.sin(theta) + (y2[i] - center_y) * math.cos(theta)
plt.plot(x2, y2, color='red')
# 设置坐标轴范围
plt.xlim(-6, 6)
plt.ylim(-1, 11)
# 设置坐标轴标签
plt.xlabel('X')
plt.ylabel('Y')
# 显示图形
plt.show()
```
运行上述代码后,你将得到一个窗口,其中包含了绘制出来的直角坐标系和两个三角形,其中小三角形已经顺时针旋转了45度,如下图所示:
![matplotlib坐标系图2](https://img-blog.csdnimg.cn/20210628111603306.png)
请注意,这个图只是示意图,实际上它并不是按照真实的比例绘制的。如果你需要更为精确的图像,可以使用专业的绘图软件或者手工绘制。