我想使用 Python 在 3D 空間中繪制一個具有指定傾斜角度的圓。類似于下圖:

X和Y部分是否也需要修改?我應該怎么辦?
更新:與其他軸傾斜的圓

uj5u.com熱心網友回復:
讓i = (1, 0, 0),j = (0, 1, 0)。這些分別是 x 軸和 y 軸的方向向量。這兩個向量構成了水平面的正交基。這里的“正交”意味著兩個向量是正交的并且長度都是 1。
水平面上的圓心C和半徑r包含所有可以寫為的點C r * (cos(theta) * i sin(theta) * j),對于范圍內的所有 theta 值[0, 2 pi]。請注意,這適用于i和j,但它同樣適用于水平面的任何其他正交基。
任何其他平面中的圓都可以用完全相同的方式描述,只需用構成該平面正交基的兩個向量替換i和即可。j
根據您的影像,“角度傾斜平面tilt”具有以下正交基礎:
a = (cos(tilt), 0, sin(tilt))
b = (0, 1, 0)
您可以檢查它們是否是您平面中的兩個向量,它們是正交的并且它們都具有范數 1。因此它們確實是您平面的正交基。
因此,您平面上的一個圓,圓心為 C,半徑為 r,可以描述為所有點C r * (cos(theta) * a sin(theta) * b),其中theta在范圍內[0, 2 pi]。
就 x、y、z 而言,這轉化為以下三個引數方程組:
x = x_C r * cos(theta) * x_a r * sin(theta) * x_b
y = y_C r * cos(theta) * y_a r * sin(theta) * y_b
z = z_C r * cos(theta) * z_a r * sin(theta) * z_b
這簡化了很多,因為 x_b、y_a、z_b 都等于 0:
x = x_C r * cos(theta) * x_a # sin(theta) * x_b, but x_b == 0
y = y_C r * sin(theta) * y_b # cos(theta) * y_a, but y_a == 0
z = z_C r * cos(theta) * z_a # sin(theta) * z_b, but z_b == 0
用它們的值替換 x_a、y_b 和 z_a:
x = x_C r * cos(tilt) * cos(theta)
y = y_C r * sin(theta)
z = z_C r * sin(tilt) * cos(theta)
在蟒蛇中:
import numpy as np
import matplotlib.pyplot as plt
# parameters of circle
r = 5.0 # radius
x_C, y_C, z_C = (0.0, 0.0, 0.0) # centre
tilt = np.pi / 6 # tilt of plane around y-axis
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
ax.set_xlim(-10,10)
ax.set_ylim(-10,10)
ax.set_zlim(-10,10)
theta = np.linspace(0, 2 * np.pi, 300) #to make a full circle
x = x_C r * np.cos(tilt) * np.cos(theta)
y = y_C r * np.sin(theta)
z = z_C r * np.sin(tilt) * np.cos(theta)
ax.plot(x, y, z )
plt.show()

轉載請註明出處,本文鏈接:https://www.uj5u.com/net/535658.html
