Introduction
起源于某同学今年打研究生数学建模竞赛。绘制飞机航迹图。
通过中心点坐标c(x,y,z)
、端点坐标1p1(x,y,z)
和端点坐标2p2(x,y,z)
,绘制三维圆弧。
起初以为很简单,接锅后发现事情不简单。。。
Method
主要思路为:通过将圆弧端点c,p1,p2
旋转到XOY
平面,插值后,再旋转回原平面。
主要步骤如下:
- 计算
c, p1, p2
三点共面的平面法向量cp
- 通过平面法向量
cp
,计算其与z
轴夹角sita
及旋转轴roteAxis
- 通过旋转轴
roteAxis
和sita
计算旋转矩阵roteMatrix
和逆向旋转矩阵roteBackMatrix
- 将
c,p1,p2
旋转到XOY
平面,根据step
插值得到弧线点坐标roteArc
- 利用
roteBackMatrix
将roteArc
旋转到原坐标系, 得到圆弧曲线坐标arc
Code
arc.py
1 | #!/usr/bin/python3 |
Example
可通过下载 GitHub 上的代码使用该函数, 使用方法如下:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19from arc import get_arc_points
import matplotlib.pyplot as plt
# key points of arc.
P1=[0,1,1]
P2=[1,0,1]
C=[0,0,0]
# get points of arc
arc=get_arc_points(C,P1,P2,0.01)
# show the result
fig=plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot3D(arc[0,:],arc[1,:],arc[2,:])
ax.set_zlabel('Z')
ax.set_ylabel('Y')
ax.set_xlabel('X')
ax.scatter3D(P1[0],P1[1],P1[2])
ax.scatter3D(P2[0], P2[1], P2[2])
ax.scatter3D(C[0], C[1], C[2])
plt.show()
Others
Email: cug.xia@gmail.com