【发布时间】:2014-10-02 20:33:34
【问题描述】:
我正在使用以下代码在 3d 中绘制穿过原点的随机平面。
from __future__ import division
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
#Number of hyperplanes
n = 20
#Dimension of space
d = 3
plt3d = plt.figure().gca(projection='3d')
for i in xrange(n):
#Create random point on unit sphere
v = np.random.normal(size = d)
v = v/np.sqrt(np.sum(v**2))
# create x,y
xx, yy = np.meshgrid(range(-5,5), range(-5,5))
z = (-v[0] * xx - v[1] * yy)/v[2]
# plot the surface
plt3d.plot_surface(xx, yy, z, alpha = 0.5)
plt.show()
但是看图片我不相信他们是统一选择的。我做错了什么?
【问题讨论】:
-
该死的!一个真正的最小工作示例。投赞成票。
-
@Veedrac 你不能定义一个通过单个法向量穿过原点的平面吗?见math.stackexchange.com/questions/952525/…。我使用的方法也是mathworld.wolfram.com/SpherePointPicking.html的“另一种选择随机点的简单方法[..]”中描述的方法
-
啊,你对这两点都是对的。傻我。