在我当前的项目中,我对计算大型模型网格的空间相关噪声感兴趣。噪声在短距离内应该是强相关的,而在长距离内是不相关的。我当前的方法使用多元高斯和协方差矩阵,指定所有单元格之间的相关性。
不幸的是,这种方法对于大型网格来说非常慢。您对如何更有效地生成空间相关噪声有什么建议吗?(不一定是高斯分布)
import scipy.stats
import numpy as np
import scipy.spatial.distance
import matplotlib.pyplot as plt
# Create a 50-by-50 grid; My actual grid will be a LOT larger
X,Y = np.meshgrid(np.arange(50),np.arange(50))
# Create a vector of cells
XY = np.column_stack((np.ndarray.flatten(X),np.ndarray.flatten(Y)))
# Calculate a matrix of distances between the cells
dist = scipy.spatial.distance.pdist(XY)
dist = scipy.spatial.distance.squareform(dist)
# Convert the distance matrix into a covariance matrix
correlation_scale = 50
cov = np.exp(-dist**2/(2*correlation_scale)) # This will do as a covariance matrix
# Sample some …Run Code Online (Sandbox Code Playgroud) 这是一个非常具体的问题,但是尽管有大量的在线资源,但我似乎找不到能满足我需要的功能。假设我有一个任意的浮点数,例如说“ 2”。我想将浮点数转换为以下格式:
'2.000000E+000'
Run Code Online (Sandbox Code Playgroud)
也就是说:指数前有8位数字,指数后有3位数字(四位为正负号)。有一些功能几乎(但不完全)产生所需的输出。使用
"%.6e" %float(2)
Run Code Online (Sandbox Code Playgroud)
产生输出
'2.000000e+00'
Run Code Online (Sandbox Code Playgroud)
这使我可以指定在指数之前(而不是在指数之后)必须输入的位数-它始终为我提供两位数字。另一方面,函数numpy.format_float_scientific:
numpy.format_float_scientific(2.0000000000, exp_digits=3,precision=6)
Out[30]: '2.e+000'
Run Code Online (Sandbox Code Playgroud)
允许我指定的位数后的指数,而不是之前。我想两者都做。你知道我怎么能做到吗?
这里已经提出并回答了很多类似的问题,但浏览后没有一个完全解决我的问题。我正在寻找一种可靠的算法来找到每条由两个点指定的两条无限线的交点。就我而言,有两个并发症:
我目前的方法说明了基于斜率和截距的方法的缺点。这个问题可以通过实施一个旋转整个系统的步骤来部分规避,这样就没有线条是垂直的,但这看起来不太优雅。你知道更好的方法吗?
import numpy as np
# The intersection point of the example below should be (0,0)
# Vertices for the first line
p1_start = np.asarray([-5, 0])
p1_end = np.asarray([-3, 0])
# Vertices for the second line
p2_start = np.asarray([0, 4])
p2_end = np.asarray([0, 2])
# Calculate slope and intercept for the first line
m_1 = (p1_end[1]-p1_start[1])/(p1_end[0]-p1_start[0])
t_1 = p1_start[1] - m_1*p1_start[0]
# The slope and intercept are zero
print('First line')
print('slope = '+str(m_1)) …Run Code Online (Sandbox Code Playgroud) 我一直在尝试使用 Aframe 和 AR.js。对于增强现实应用程序,一个常见的问题是放置在标记上的对象变得相当“紧张”或“不稳定”。我已经对这个问题做了一些研究,看来解决这个问题的一种可能方法是平滑几个帧上的旋转和位置。不幸的是,关于这样做的教程几乎不存在,而且我才刚刚开始掌握 Html/Javascript。
因此我的问题是:您知道是否可以在 aframe 实体中拥有一个函数来提取位置和旋转、平滑它们,然后将它们传递给(我想)使用这些平滑值进行放置的子实体?
<a-entity position="0 0 0" rotation="0 0 0" >
<a-video Mysmoothingfunction src="#video" width="3.5" height="2"></a-video>
</a-entity>
Run Code Online (Sandbox Code Playgroud)
我可以想象开始可能是这样的:
<script type="text/javascript">
AFRAME.registerComponent("listener", {
schema :
{
stepFactor : {
type : "number",
default : 0.05
}
},
tick: function() {
this.getProperty("position"); // something like this?
}
</script>
Run Code Online (Sandbox Code Playgroud)
您知道如何解决这个问题吗?
python ×3
python-3.x ×3
aframe ×1
ar.js ×1
formatting ×1
geometry ×1
html ×1
javascript ×1
noise ×1
performance ×1
string ×1