当前位置:网站首页>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 )
边栏推荐
- C语言函数参数传递模式入门详解
- How to reinstall Win7 system with U disk?How to reinstall win7 using u disk?
- Win11声卡驱动如何更新?Win11声卡驱动更新方法
- KiCad Common Shortcuts
- 二叉树遍历之后序遍历(非递归、递归)入门详解
- Detailed explanation of Golang garbage collection mechanism
- What should I do if the Win10 system sets the application identity to automatically prompt for access denied?
- CI24R1小模块2.4G收发模块无线通信低成本兼容si24r1/XN297超低功耗
- What should I do if I install a solid-state drive in Win10 and still have obvious lags?
- 【STM32学习1】基础知识与概念明晰
猜你喜欢

Do Windows 10 computers need antivirus software installed?

win10怎么设置不睡眠熄屏?win10设置永不睡眠的方法

How to set the win10 taskbar does not merge icons

win10无法直接用照片查看器打开图片怎么办

Mysql的锁

13.56MHZ刷卡芯片CI521兼容cv520/ci520支持A卡B卡MIFARE协议

Win10 cannot directly use photo viewer to open the picture

使用 腾讯云搭建一个个人博客

二叉树创建之层次法入门详解

推开机电的大门《电路》(一):电压,电流,参考方向
随机推荐
Mapreduce环境详细搭建和案例实现
使用npx -p @storybook/cli sb init安装失败,手把手搭建专属的storybook
How to update Win11 sound card driver?Win11 sound card driver update method
DP4344兼容CS4344-DA转换器
KiCad Common Shortcuts
Letter combination of LeetCode2 phone number
Use libcurl to upload the image of Opencv Mat to the file server, based on two methods of post request and ftp protocol
Win11电脑一段时间不操作就断网怎么解决
FP6296锂电池升压 5V9V12V内置 MOS 大功率方案原理图
Mysql连接错误解决
C语言函数参数传递模式入门详解
2021-10-14
vscode镜像
What should I do if the Win10 system sets the application identity to automatically prompt for access denied?
Cmd Markdown 公式指导手册
【系统设计与实现】基于flink的分心驾驶预测与数据分析系统
ECP2459耐压60V降压BUCK电路用于WIFI模块供电方案原理图
Win7怎么干净启动?如何只加载基本服务启动Win7系统
Network Security Packet Capture
13.56MHZ刷卡芯片CI521兼容cv520/ci520支持A卡B卡MIFARE协议