- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试在 matplotlib 中制作一个“封闭”圆柱体,但我不知道如何去做。到目前为止,我有一个两端敞开的圆柱体,其代码如下:
#make a cylinder without the ends closed
import numpy as np
from matplotlib import cm
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from scipy.linalg import norm
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
import numpy as np
import math
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
origin = [0,0,0]
#radius = R
p0 = np.array(origin)
p1 = np.array([8, 8, 8])
origin = np.array(origin)
R = 4
#vector in direction of axis
v = p1 - p0
#find magnitude of vector
mag = norm(v)
#unit vector in direction of axis
v = v / mag
#make some vector not in the same direction as v
not_v = np.array([1, 0, 0])
if (v == not_v).all():
not_v = np.array([0, 1, 0])
#make vector perpendicular to v
n1 = np.cross(v, not_v)
#normalize n1
n1 /= norm(n1)
#make unit vector perpendicular to v and n1
n2 = np.cross(v, n1)
#surface ranges over t from 0 to length of axis and 0 to 2*pi
t = np.linspace(0, mag, 600)
theta = np.linspace(0, 2 * np.pi, 100)
#use meshgrid to make 2d arrays
t, theta = np.meshgrid(t, theta)
#generate coordinates for surface
X, Y, Z = [p0[i] + v[i] * t + R * np.sin(theta) * n1[i] + R * np.cos(theta) * n2[i] for i in [0, 1, 2]]
#make the color for the faces
col1 = plt.cm.autumn(np.ones(600)) # linear gradient along the t-axis
col1 = np.repeat(col1[np.newaxis,:, :], 100, axis=0) # expand over the theta-axis
ax.plot_surface(X, Y,Z, facecolors = col1, shade = True,edgecolors = "None", alpha = 0.4, linewidth = 0)
plt.show()
如何用实心圆(即圆盘)封闭圆柱体的两端?
最佳答案
与其他代码类似的一种快速简单的方法是使用从 r=0
到 r=R
的 strip 生成表面。在 plt.show()
之前添加以下行:
R = np.array([0,R])
# cap at t=0
X, Y, Z = [p0[i] + np.outer(R, np.sin(theta)) * n1[i] + np.outer(R, np.cos(theta))*n2[i] for i in [0, 1, 2]]
ax.plot_surface(X, Y, Z, edgecolors = "r", alpha=.4, linewidth = .1)
# cap at t=mag
X, Y, Z = [p0[i] + v[i]*mag + np.outer(R, np.sin(theta)) * n1[i] + np.outer(R, np.cos(theta))*n2[i] for i in [0, 1, 2]]
ax.plot_surface(X, Y, Z, edgecolors = "r", alpha=.4, linewidth = .1)
关于python - 如何在 matplotlib 中闭合圆柱体的末端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38109960/
我正在对发生在自身包裹的方形网格上的事物进行建模(即,如果您向上走过最高点,您最终会到达最低点,就像一个圆柱体;如果您向右走,您只是击中边界)。我需要跟踪各种代理的位置,不同点的资源量,并根据一定的规
我正在尝试显示具有 3 个圆柱体和 3 种不同颜色的轴。这是我的代码; glDisable(GL_LIGHTING); glClear(GL_COLOR_BUFFER_BIT); glColor3f(
我正在 Matlab 中做一个数学实验,结果应该是 x,y 平面上的一个圆。但有时,圆圈开始螺旋上升。我现在正在尝试将 x,y 平面弯曲成圆柱体(如下图所示)。目前我只有点的 x 和 y 坐标。 我试
我正在尝试在 3D 空间中创建一个圆柱体。我在 3D 中获得起点和终点并放置顶点,我需要为圆柱体的底部和顶部创建 2 个圆。我考虑制作一个坐标为 (1,0,0) 的 vector u 并计算方向 ve
我有以下代码可以在 View 中显示 3D 圆柱体。在设备上查看时,手势会在 x 轴(上下滑动手势)和 y 轴(左右滑动)上旋转圆柱体,但 z 轴被锁定。我相信这是 allowsCameraContr
我需要对我的圆柱体进行纹理处理,我有texture.png并且我已经做了一个多边形网格(带有三角形)。 如果您需要的话,这是代码 pastebin import pyglet import pygle
我是新的 opengl 学习者。我知道有内置函数可以在过剩的情况下绘制圆柱体,比如 GLUquadricObj *quadratic; quadratic=gluNewQuadric(); gluCy
我试图在我的 React 组件中添加圆柱体 3D 图表。但是,我遇到了这个错误。 Error: Highcharts error #17: www.highcharts.com/errors/17/?
我的第一篇文章在这里。 :)我目前正在用 C 语言为我的学校项目编写光线追踪器。我已经可以显示带有一些灯光效果的球体、三角形和平面。现在我想显示圆柱体(然后是圆锥体,但首先是圆柱体!)。我选择有一个平
我正在开发一个小项目,其中我必须从图像中检测 aruco 标记,然后制作覆盖所有白色框的 3d 圆柱体或立方体。 在下面的代码中,它们是一个 detector_marker() 函数,其中我必须返回
我已经计算了索贝尔梯度的大小和方向。但我一直不知道如何进一步使用它来进行形状检测。 图像>灰度>索贝尔过滤>索贝尔梯度和方向计算>下一步? 使用的 Sobel 内核是: Kx = ([[1, 0, -
我想将 Canvas 呈现为圆柱形锥体,您可以像轮子一样在两个方向上旋转。这在 JS/CSS3 中完全可行吗? 最佳答案 您应该看看这个新的 CSS3 功能:自定义过滤器/CSS 着色器。 这里有一些
我是一名优秀的程序员,十分优秀!