偏置圓柱體相貫線的空間座標計算

兩個圓柱形管的相貫存在4種形式,正交、偏置、斜交和偏置斜交。
在這裏插入圖片描述
本文僅討論偏置情況下的計算方法。

建立如下座標系,圓柱1的軸線爲Z軸,圓柱2的軸線與Y軸平行,通過右手法則確定X軸,圓柱2的軸線在XOY平面上。圓柱1半徑爲a,圓柱2半徑爲b,圓柱2的軸線相較於Y軸偏移距離爲ΔX,其中b > a
在這裏插入圖片描述
採用極座標系表示兩個圓柱面和法線矢量:

1\sum_1x1=acosθx_1 = a\cos \thetay1=asinθy_1 = a\sin \thetaz1=uz_1 = u
法向量:nx1=cosθ,ny1=sinθ,nz1=0n_{x1} = \cos \theta, n_{y1} = \sin \theta, n_{z1}=0

2\sum_2x2=Δx+bcosφx_2 = \Delta x +b\cos \varphiy2=vy_2 = vz2=bsinφz_2 = b \sin \varphi
法向量:nx2=cosφ,ny2=0,nz2=sinφn_{x2} = \cos \varphi, n_{y2} =0, n_{z2}= \sin \varphi

相貫線同時位於兩個圓柱面上,即滿足
x1=x2,y1=y2,z1=z2 x_1=x_2, y_1=y_2, z_1=z_2

由於a, b, Δx\Delta x爲已知,且a < b,則θ\theta的取值範圍爲(02π0-2\pi),根據需要的點距可以選擇不同的步長。

可解出相貫線的空間座標關於θ\theta的方程如下:

x=acosθx = a \cos \theta
y=asinθy = a \sin \theta
z=b2(xΔx)2z = \sqrt{b^2-(x-\Delta x)^2}

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()

繪製結果如下:
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章