答案 0 :(得分:0)
使用matplotlib:
def plot_spherical_cap(ax, b, opening_angle, radius=1.0):
r = elevation
phi = numpy.linspace(0, 2 * numpy.pi, 30)
theta = numpy.linspace(0, opening_angle, 20)
X = r * numpy.stack([
numpy.outer(numpy.cos(phi), numpy.sin(theta)),
numpy.outer(numpy.sin(phi), numpy.sin(theta)),
numpy.outer(numpy.ones(numpy.size(phi)), numpy.cos(theta)),
], axis=-1)
# rotate X such that [0, 0, 1] gets rotated to `c`;
# <https://math.stackexchange.com/a/476311/36678>.
a = numpy.array([0.0, 0.0, 1.0])
a_x_b = numpy.cross(a, b)
a_dot_b = numpy.dot(a, b)
if a_dot_b == -1.0:
X_rot = -X
else:
X_rot = (
X +
numpy.cross(a_x_b, X) +
numpy.cross(a_x_b, numpy.cross(a_x_b, X)) / (1.0 + a_dot_b)
)
ax.plot_surface(
X_rot[..., 0], X_rot[..., 1], X_rot[..., 2],
rstride=3, cstride=3,
color='#1f77b4',
alpha=0.5,
linewidth=0
)
return