当前位置:网站首页>Detailed introduction to drawing complex surfaces using the plot_surface command
Detailed introduction to drawing complex surfaces using the plot_surface command
2022-08-02 15:32:00 【Yang Laotou Soft Worker】
一、引言
The 3 d geometry in,Often need to draw the complex curved surface,For example, the closed space curved surface.Based on the drawing by planez=1,旋转抛物面z=x^2 + y^2And parabolicy=2xIn the closed surface, for example,In detail usingPython命令plot_surfaceThe process of drawing complex curved surface.
二、Draw a closed surface
1、First draw rotating parabolicz=x^2 + y^2
Consider rotating parabolic function domain is a circle domain,So using polar coordinates to indicate the graphic abscissa and ordinate,Let get some graphics look better on the vision.
具体的步骤为:
1)First of all make graphics window,And with the provisions of the three-dimensional coordinate system
2)Determine the extremely diameter and Angle of the grid coordinates
3)According to the relationship of rectangular coordinates and polar coordinates gets the abscissa of rotating paraboloid、Axis and the vertical coordinates of
4)利用plot_surfaceFunction mapping rotating parabolic
5)Increase each coordinate axis labels,Determine the Angle of 3 d graphics
参考代码如下:
import matplotlib.pyplot as plt
import numpy as np
import math
fig = plt.figure() #建立图形窗口
ax = fig.gca( projection = '3d' ) #Using 3 d coordinate
theta = np.arange( 0, 2 * math.pi, 0.05 )
rou = np.arange( 0, 1, 0.005 )
T, R = np.meshgrid( theta, rou ) #Polar Angle and diameter of the grid coordinates
Xp = R * np.cos(T) #Abscissa based on polar coordinates calculation
Yp = R * np.sin(T) #Based on polar coordinates to calculate the vertical
Zp = Xp**2 + Yp**2 #The abscissa and ordinate generation into the rotating parabolic function to get the vertical coordinates
ax.plot_surface( Xp, Yp, Zp, cstride = 1, rstride = 2, edgecolor = 'b' ) #Draw the rotating parabolic
ax.set_xlabel( 'x' )
ax.set_ylabel( 'y' )
ax.set_zlabel( 'z' )
ax.view_init( 20, 45 )
上述代码运行结果为:
2、Draw the parabolicy=x^2
With the above drawing of rotating paraboloid experience,此处直接上代码.
fig = plt.figure() #建立图形窗口
ax = fig.gca( projection = '3d' ) #三维坐标系
Xc, Zc = np.meshgrid( np.arange(-1, 1, 0.005), np.arange(0, 1, 0.005 ) )#Independent variable grid coordinates
Yc = Xc**2
ax.plot_surface( Xc, Yc, Zc, cstride = 1, rstride = 2, edgecolor = 'y' )#绘图
ax.set_xlabel( 'x' )
ax.set_ylabel( 'y' )
ax.set_zlabel( 'z' )
ax.view_init( 20, 45 )
上述代码运行结果为:
3、Draw with rotating parabolic plane with the same domainz=1
With the above drawing of rotating paraboloid experience,此处直接上代码.
fig = plt.figure() #建立图形窗口
ax = fig.gca( projection = '3d' ) #三维坐标系
[ m, n ] = np.shape( Xp )
Zf = np.ones( Xp.shape )
ax.plot_surface( Xp, Yp, Zf, cstride = 1, rstride = 2, edgecolor = 'r' )
ax.set_xlabel( 'x' )
ax.set_ylabel( 'y' )
ax.set_zlabel( 'z' )
ax.view_init( 20, 45 )
上述代码运行结果为:
4、The above code into a running can get the graphic below:
注意:Need to draw the parabolic and code in the following two statements to delete
fig = plt.figure() #建立图形窗口
ax = fig.gca( projection = '3d' ) #三维坐标系
5、Delete redundant on each graphic primitives
从上图可以看出,结果不尽人意,If you can remove the surface spare parts,You can get better closed surface.So speak the following code is used to delete respectively select paraboloid、On the surface of the parabolic peace redundant data,Just need to make extra the vertical coordinate components of the primitive value ofNone即可.
1)Delete the parabolic redundant data(This method is of low efficiency)
[ mc, nc ] = np.shape( Xc )
for i in range( mc ):
for j in range( nc ):
if Zc[ i, j ] < Xc[ i, j ] * Xc[ i, j ] + Yc[ i, j ] * Yc[ i, j ]:
Zc[ i, j ] = None
```
2)Delete selected paraboloid and redundant data(This method is of low efficiency)
```python
[ m, n ] = np.shape( Xp )
Zf = np.ones( Xp.shape )
for i in range( m ):
for j in range( n ):
if Yp[ i, j ] < Xp[ i, j ] * Xp[ i, j ]:
Zf[ i, j ] = None
Zp[ i, j ] = None
So you can get the following visual effect in good shape:
6、The complete drawing closed surface code
import matplotlib.pyplot as plt
import numpy as np
import math
#建立图形窗口
fig = plt.figure()
ax = fig.gca( projection = '3d' )#Axes3D( fig )
#旋转抛物面 Paraboloid 的图形数据
theta = np.arange( 0, math.pi, 0.01 )
rou = np.arange( 0, 1, 0.01 )
T, R = np.meshgrid( theta, rou )
Xp = R * np.cos(T)
Yp = R * np.sin(T)
Zp = Xp**2 + Yp**2
#抛物柱面 Parabolic Cylinder 的图形数据
Xc, Zc = np.meshgrid( np.arange(-1, 1, 0.01), np.arange(0, 1, 0.01 ) )
Yc = Xc**2
[ mc, nc ] = np.shape( Xc )
#Delete the parabolic redundant data
for i in range( mc ):
for j in range( nc ):
if Zc[ i, j ] < Xc[ i, j ] * Xc[ i, j ] + Yc[ i, j ] * Yc[ i, j ]:
Zc[ i, j ] = None
#平面 flat surface 的图形数据
Zf = np.ones( Xp.shape )
[ m, n ] = np.shape( Xp )
#Deletes data plane and rotating parabolic redundant
for i in range( m ):
for j in range( n ):
if Yp[ i, j ] < Xp[ i, j ] * Xp[ i, j ]:
Zf[ i, j ] = None
Zp[ i, j ] = None
#绘图
ax.plot_surface( Xc, Yc, Zc, cstride = 1, rstride = 1, edgecolor = 'y' )
ax.plot_surface( Xp, Yp, Zp, cstride = 1, rstride = 1, edgecolor = 'b' )
ax.plot_surface( Xp, Yp, Zf, cstride = 1, rstride = 1, edgecolor = 'r' )
ax.set_xlabel( 'x' )
ax.set_ylabel( 'y' )
ax.set_zlabel( 'z' )
ax.view_init( 20, 30 )
边栏推荐
- GMP scheduling model of golang
- win10怎么设置不睡眠熄屏?win10设置永不睡眠的方法
- yolov5官方代码解读——前向传播
- Win11没有本地用户和组怎么解决
- Article pygame drag the implementation of the method
- Fast advanced TypeScript
- Open the door to electricity "Circuit" (3): Talk about different resistance and conductance
- Please make sure you have the correct access rights and the repository exists.问题解决
- 深入理解Golang之Map
- Publish module to NPM should be how to operate?Solutions to problems and mistake
猜你喜欢
Win10 computer can't read U disk?Don't recognize U disk how to solve?
关于c语言的调试技巧
yolov5官方代码解读——前向传播
开心一下,9/28名场面合集
Flink + sklearn - use JPMML implement flink deployment on machine learning model
FP5207电池升压 5V9V12V24V36V42V大功率方案
Win7遇到错误无法正常开机进桌面怎么解决?
推开机电的大门《电路》(一):电压,电流,参考方向
Redis常见面试题
Win11 system cannot find dll file how to fix
随机推荐
DP1332E刷卡芯片支持NFC内置mcu智能楼宇/终端poss机/智能门锁
使用 腾讯云搭建一个个人博客
用U盘怎么重装Win7系统?如何使用u盘重装系统win7?
What should I do if I install a solid-state drive in Win10 and still have obvious lags?
Win10安装了固态硬盘还是有明显卡顿怎么办?
KiCad常用快捷键
mysql的索引结构为什么选用B+树?
Win11 system cannot find dll file how to fix
总结计算机网络超全面试题
FP6195耐压60V电流降压3.3V5V模块供电方案
13.56MHZ刷卡芯片CI521兼容cv520/ci520支持A卡B卡MIFARE协议
What is Win10 God Mode for?How to enable God Mode in Windows 10?
Article pygame drag the implementation of the method
镜像法求解接地导体空腔电势分布问题
MATLAB绘图函数ezplot入门详解
GMP scheduling model of golang
轻量化AlphaPose
Cmd Markdown 公式指导手册
Mysql之MVCC
win11一直弹出用户账户控制怎么解决