- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
I am showing a color map as the facecolors of a sphere using ax.plt_surface. Basically is the example that is available at the pyplot webpages, with some extra code to add the color map. The application generates a complex function f(z)=z^3+1 for z=a+bi where a=[-4,4] and b=[-3,3]. Then the domain color map of the function is done, it is a [200]x[200]x3 numpy array (the typical one). Finally the sphere is created and I want to use the color map as the filling color of the faces of the surface of the sphere, so basically I want to map the color map as the "texture" of the sphere.
def sphere_mapping():
import numpy as np
import matplotlib.pyplot as plt
import skimage, skimage.io
from mpl_toolkits.mplot3d import Axes3D
from math import sqrt, atan2, pi
def hslToRgb(h, s, l):
# Source: https://stackoverflow.com/questions/2353211/hsl-to-rgb-color-conversion
# Converts an HSL color value to RGB. Conversion formula
# adapted from http://en.wikipedia.org/wiki/HSL_color_space.
# Assumes h, s, and l are contained in the set [0, 1] and
# returns r, g, and b in the set [0, 1].
def hue2rgb(p, q, t):
if t < 0:
t += 1
if t > 1:
t -= 1
if t < 1/6:
return p + (q - p) * 6 * t
if t < 1/2:
return q
if t < 2/3:
return p + (q - p) * (2/3 - t) * 6
return p
r,g,b = 0,0,0
if s == 0:
r,g,b = l,l,l
else:
q=0
if l < 0.5:
q=l * (1 + s)
else:
q=l + s - l * s
p = 2 * l - q;
r = hue2rgb(p, q, h + 1/3)
g = hue2rgb(p, q, h)
b = hue2rgb(p, q, h - 1/3)
return r,g,b
# Displays an image
def display(img, colorbar=False, filename=""):
plt.figure(figsize=(10, 10))
if len(img.shape) == 2:
i = skimage.io.imshow(img, cmap='gray')
else:
i = skimage.io.imshow(img)
if colorbar:
plt.colorbar(i, shrink=0.5, label='depth')
plt.tight_layout()
if filename=="":
plt.show()
else:
plt.savefig(filename)
plt.rcParams['figure.dpi'] = 150
# complex function f(z) calculations start here
testlimitx = 100
testlimity = 100
testbase = 100
anim=0
lx=[]
ly=[]
lc=[]
lh=[]
ll=[]
lr=[]
ls=[]
print("Calculating...")
maxx=0
maxy=0
for posx in range(-testlimitx,testlimitx):
for posy in range(-testlimity,testlimity):
x=(posx/testbase)*1
y=(posy/testbase)*1
# function complex example
myc=x+(y*(1j))
myc=(myc**3)+1
resx=myc.real
resy=myc.imag
if abs(resx)>maxx:
maxx=abs(resx)
if abs(resy)>maxy:
maxy=abs(resy)
current_angle = 0
current_r = sqrt((resx**2)+(resy**2))
if resx!=0:
current_angle = atan2(resy,resx)
else:
if y>0:
current_angle = pi/2
else:
current_angle = (pi/2)*3
if current_angle < 0:
current_angle = current_angle + (2*pi)
current_angle = (1/(2*pi))*current_angle
h = current_angle
l = 0.5
s = 0.7
lx.append(x)
ly.append(y)
lh.append(h)
ll.append(l)
ls.append(s)
lr.append(current_r)
for i in range(0,len(lx)):
r,g,b = hslToRgb(lh[i], ls[i], ll[i])
# lc contains 200x200x3 R,G,B color values
lc.append(r)
lc.append(g)
lc.append(b)
print("Creating colormap ...")
colormap = np.zeros((200, 200, 3), dtype=np.float)
pos=0
for i in range (0,200):
for j in range (1,201):
colormap[200-j][i][0]=lc[pos]
pos=pos+1
colormap[200-j][i][1]=lc[pos]
pos=pos+1
colormap[200-j][i][2]=lc[pos]
pos=pos+1
print("Current index="+str(i)+","+str(j)+"\r", end='')
# finally this is the colormap that has been generated
display(colormap)
# sphere test: will map the colormap into the surface of the sphere
n=200
m=200
u = np.linspace(0,2*pi,n)
v = np.linspace(0,pi,m)
x = np.outer(np.cos(u),np.sin(v))
y = np.outer(np.sin(u),np.sin(v))
z = np.outer(np.ones(n),np.cos(v))
fig = plt.figure()
fig.patch.set_alpha(1)
ax = fig.gca(projection='3d')
ax.view_init(elev=0., azim=-180)
col1 = np.empty([n,m,3], dtype=float)
for i in range(0,len(col1)):
for j in range(0,len(col1[i])):
col1[i][j][1]=colormap[j][i][0]
col1[i][j][1]=colormap[j][i][1]
col1[i][j][2]=colormap[j][i][2]
ax.plot_surface(x,y,z,color='b',rstride=1, cstride=1, alpha=1.0, linewidth=0, facecolors=col1)
plt.show()
plt.savefig("sphere_test.png", dpi=600)
sphere_mapping()
上述示例的颜色图图像如下:
但是当我将图像映射到 numpy 数组“col1”后将其视为球体的表面时(映射只是因为点的颜色信息位于数组的不同位置,但维度两个数组的颜色是相同的),颜色不匹配,我猜这是由于一些不需要的透明度,所以我无法完全看到我所面对的当前面的颜色(由于透明度,我可以看到隐藏的一面也是如此,并且颜色正在混合)。我添加了 alpha=1.0 但似乎没有达到预期的效果。我期待完全相同的颜色,没有透明度,因此不会出现混合颜色。
我不确定这是否与 topic in this previous question 有关.
目前我正在使用以下参数进行 ax.plotsurface 调用:
ax.plot_surface(x,y,z,color='b',rstride=1, cstride=1, alpha=1.0, linewidth=0, facecolors=col1)
Is it possible to fix this problem? Thank you!
最佳答案
是否唯一的问题是颜色到 col1
的映射。而不是
col1[i][j][1]=colormap[j][i][0]col1[i][j][1]=colormap[j][i][1]col1[i][j][2]=colormap[j][i][2]
你可能想要
col1[i][j][0]=colormap[j][i][0]col1[i][j][1]=colormap[j][i][1]col1[i][j][2]=colormap[j][i][2]
关于python - 为什么使用 ax.pltsurface 创建的球体无法在曲面的各个面上保持所需的 alpha=1 ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46291295/
我一直在尝试根据内部“ Shiny 球体”图案在球体上产生发光效果,但一直坚持定位“球体”的某些方面。 就目前而言,我的 CSS 看起来像这样: .sphere { height: 200px;
我正在尝试使用下面给出的旋转矩阵来旋转“轨道”: [cos(angle) -sin(angle) 0; sin(angle) cos (angle) 0; 0 0
我有一组由地理 (WGS84) 坐标指定的多边形:它们位于一个球体上。 我有一个由经纬度对指定的点。 我想(有效地)找到点和多边形之间的最小大圆距离。 我当前的堆栈包括 fiona、shapely、g
将 boost::geometry::line_interpolate 与 boost::geometry::srs::spheroid 结合使用,我正在计算沿最短距离的大圆导航点2个地理点。下面的代
如何在 JavaFX 中填充具有线性渐变(如 2d 圆)的 3D 球体?我使用 JavaFX Scene Builder。 最佳答案 正如@mohsenmadi 所指出的,漫反射颜色不允许您使用一种颜
我想使用 Python PyOpenGL 生成三个球体的场景。两个在有颜色的一侧(红色和绿色)。中间一个上面有任何纹理(砖 block 纹理实际上是与代码位于同一目录中的方形 jpg 文件)。 到目前
我从不同网格变量中的 .x 文件加载多个网格。现在我想计算我加载的所有网格(以及正在显示的网格)的包围球请指导我如何实现这一目标。可以将 VertexBuffers 附加到一个变量中并使用它计算 bo
我正在尝试用“粒子”(由 3D XYZ 向量表示)以最佳方式填充 3D 球形体积,这些粒子需要彼此保持特定距离,同时尽量减少它们之间存在的自由空间量. 但有一个问题 - 粒子本身可能会落在球形体积的边
我想创建一个球体,实际上是一个地球仪。但我似乎找不到任何有关如何处理球体的顶点和索引以及如何设置它们的有用信息。你们中的任何人都可以引导我走上正确的轨道,也许给我一些示例代码或指向教程的链接吗? 最佳
我终于手动画了一个球体:) 我希望我的球体是红色的,但轮廓是绿色的: 为了实现这一点,我做了以下事情。我用红色画了一个实心球体,然后我画了同一个球体,但线框和绿色。当我打开 DEPTH_TEST 时,
我想在 HTML 5.0 Canvas 中绘制 3D 球或球体。我想了解有关如何绘制 3D 球体的算法。谁可以与我分享这个? 最佳答案 您将需要为一个球体建模,并让它具有不同的颜色,以便在它旋转时您可
我正在尝试使用 webGL 构建 3D 太阳系。 我让所有恒星按照应有的方式绕太阳旋转,并且我希望它们也绕自己的 Y 轴旋转。 我怎样才能添加它?我尝试过: mat4.rotate(mvMatrix,
我有二维彩色图像。所有彩色点都位于此矩形图像中心的圆形区域内,圆圈外的所有点都是黑色的(我从鱼眼相机获得这些矩形图像)。我知道这个圆心的坐标和它的半径。 我需要将所有彩色点从 2D 图像上的圆形区域移
我正在用球体上的粒子进行 Metropolis Monte Carlo 模拟,并有一个关于给定时间步长内随机运动的问题。 我知道要在球体上获得均匀分布的随机点开始,使用最简单的方法是不够的(使用恒定
我想让球体向前移动一定的厘米,但到目前为止我还没有设法让任何东西正常工作这是我现在的代码: EditText distanceText = (EditText) findViewById(R.id.d
我想仅使用 Canvas 制作一个旋转对象(球体、盒子等)。但我找不到教程。如果您看到某个地方或解释如何做,请提供帮助。 像这样example ,仅无任何效果 最佳答案 希望你喜欢数学。如果您愿意编写
使用 GL_TRIANGLES 在 OpenGL ES 2.0 中绘制纹理球体的最简单方法是什么? 我特别想知道如何计算顶点。 最佳答案 有多种方法可以对球体进行三角测量。受欢迎的,不太受欢迎的,好的
我有一个关于在 HTML5/Canvas/Javascript 中伪造 3d 的问题... 基本上,我在 上绘制了一个二维图像使用 drawImage() . 我想做的是绘制图像,然后置换球体上的纹
我在 OpenGL ES 中绘制行星,遇到了一些有趣的性能问题。普遍的问题是:如何最好地在球体上渲染“非常详细”的纹理? (球体是有保证的;我对球体特定的优化很感兴趣) 基本案例: 窗口大约是。 20
对于我的论文项目,我使用 DataArts WebGL Globe 来开发一个网页,该网页将在触摸显示器上的展览中使用。作为监视器触摸,我需要使地球可点击以选择单个国家并打开弹出窗口并突出显示选定的国
我是一名优秀的程序员,十分优秀!