如何绘制多项式函数绕y轴的旋转实心? [英] How to draw a solid of revolution of a polynomial function around the y-axis?

查看:105
本文介绍了如何绘制多项式函数绕y轴的旋转实心?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

函数y = x**2绕y轴旋转的固体可以使用以下代码绘制:

A solid of revolution of a function y = x**2 around the y-axis can be plotted using the code below:

import numpy as np
import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d.axes3d as axes3d
from matplotlib import cm

np.seterr(divide='ignore', invalid='ignore')

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')


ll, ul = 0, 1 
u = np.linspace(ll, ul, 60)
v = np.linspace(0, 2*np.pi, 60)
U, V = np.meshgrid(u, v)

Z = U

X = np.sqrt(Z)*np.cos(V)
Y = np.sqrt(Z)*np.sin(V)

ax.set_xlabel('Y axis')
ax.set_ylabel('X axis')
ax.set_zlabel('Z axis')

ax.plot_surface(X, Y, Z, cmap=plt.cm.YlGnBu_r)

plt.show()

此代码仅绘制函数x = sqrt(y)的旋转实数,该实数是y = x**2的反函数.但是,如何为以下函数绘制旋转实体:

This code just plots the solid of revolution of the function x = sqrt(y) which is the inverse of y = x**2. But how to draw the solid of revolution for a function as:

y = x**5 + x**4 + x**3 + x**2 + x

?

推荐答案

(U,V)参数空间到(X,Y,Z)坐标的映射可以非常灵活. 通常选择Unp.linspace(ll, ul, 100)之类的值,并使其等于Y(如果y为旋转轴).但是您不必那样使用U. 取而代之的是U可以代表半径:

The mapping from (U,V) parameter space to (X,Y,Z) coordinates can be very flexible. Often U is chosen to be something like np.linspace(ll, ul, 100) and is taken to be equal to Y (if y is the axis of rotation). But you don't have to use U that way. Instead U could represent the radius:

ll, ul = 0, 1 
u = np.linspace(ll, ul, 100)
v = np.linspace(0, 2*np.pi, 60)
U, V = np.meshgrid(u, v)

,然后可以根据半径U定义XYZ:

and then X, Y, Z can be defined in terms of the radius, U:

Y = U**5 + U**4 + U**3 + U**2 + U
X = U*np.cos(V)
Z = U*np.sin(V)


import numpy as np
import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d.axes3d as axes3d
from matplotlib import cm

np.seterr(divide='ignore', invalid='ignore')

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

ll, ul = 0, 1 
u = np.linspace(ll, ul, 100)
v = np.linspace(0, 2*np.pi, 60)
U, V = np.meshgrid(u, v)

Y = U**5 + U**4 + U**3 + U**2 + U
X = U*np.cos(V)
Z = U*np.sin(V)

ax.set_xlabel('Y axis')
ax.set_ylabel('X axis')
ax.set_zlabel('Z axis')

ax.plot_surface(X, Y, Z, cmap=plt.cm.YlGnBu_r)

plt.show()

这篇关于如何绘制多项式函数绕y轴的旋转实心?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆