兩個圓柱形管的相貫存在4種形式,正交、偏置、斜交和偏置斜交。
本文僅討論偏置情況下的計算方法。
建立如下座標系,圓柱1的軸線爲Z軸,圓柱2的軸線與Y軸平行,通過右手法則確定X軸,圓柱2的軸線在XOY平面上。圓柱1半徑爲a
,圓柱2半徑爲b
,圓柱2的軸線相較於Y軸偏移距離爲ΔX
,其中b > a
。
採用極座標系表示兩個圓柱面和法線矢量:
: , ,;
法向量:
:,,
法向量:
相貫線同時位於兩個圓柱面上,即滿足
由於a, b, 爲已知,且a < b
,則的取值範圍爲(),根據需要的點距可以選擇不同的步長。
可解出相貫線的空間座標關於的方程如下:
用python
實現如下:
import math
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
# 圓柱1半徑:radius_1; 偏置距離:offset
# 圓柱2半徑:rasius_2; (直徑大)
# 點距: theta;(按弧度)
class IntersectingLine():
def __init__(self):
self.radius_1 = 8.0
self.radius_2 = 30.0
self.center_offset = 10.0
self.step_theta = 0.04
# 計算空間座標,保存在 ndarray中
def calculate_coordinates(self, r1, r2, offset, theta):
shape = ((int)(math.pi * 2 / theta), 3)
coords = np.zeros(shape, dtype=float)
for i in range(shape[0]):
coords[i][0] = r1 * math.cos(i*theta)
coords[i][1] = r1 * math.sin(i*theta)
coords[i][2] = math.sqrt(r2*r2 - math.pow((coords[i][0] - offset), 2))
return coords
# 根據座標點繪製三維散點圖
def plot_coordinates(self, coordinates):
fig = plt.figure()
ax = Axes3D(fig)
ax.view_init(elev=45, azim=135)
ax.scatter3D(coordinates[:,0], coordinates[:,1], coordinates[:,2], cmap='Blues')
plt.show()
繪製結果如下: