解释我的问题的最好方法是举个例子:
example.py:
class A(object):
integers = [1, 2, 3]
singles = [i for i in integers]
class B(object):
integers = [1, 2, 3]
pairs = [(i, j) for i in integers for j in integers]
Run Code Online (Sandbox Code Playgroud)
当我在python 2下运行它时工作正常,但在python 3下我得到一个NameErrorfor class B(但不是class A):
$ python example.py
Traceback (most recent call last):
File "example.py", line 6, in <module>
class B(object):
File "example.py", line 8, in B
pairs = [(i, j) for i in integers for j in integers]
File …Run Code Online (Sandbox Code Playgroud) 我有一个相机正在观看的CubeGeometry,我希望相机可以放大,这样立方体就完全可见,但不会更大.
我最初的尝试是将立方体顶点转换为摄像机坐标系,
function toScreenXY(position, camera) {
var pos = position.clone();
var projScreenMat = new THREE.Matrix4();
projScreenMat.multiply(camera.projectionMatrix, camera.matrixWorldInverse);
projScreenMat.multiplyVector3( pos );
return pos;
}
function ScaleInView() {
camera.fov = 0.0;
for (var i=0; i<8; i++) {
proj2d = toScreenXY(cube.geometry.vertices[i],camera);
angle = 57.296 * Math.max(Math.atan(proj2d.x/proj2d.z), Math.atan(proj2d.y/proj2d.z));
camera.fov = Math.max(camera.fov,angle);
}
camera.updateProjectionMatrix();
}
Run Code Online (Sandbox Code Playgroud)
我认为这会起作用,但有时它太小了,有时候太大(取决于相机的位置).
我还需要为正射相机做这个.
编辑: 当立方体面向相机时,我知道如何做到这一点,当相机移动到某个任意(r,theta,phi)位置时,我正在寻找一种方法(球面极坐标; r实际上是为我的目的不变).
事实上,它是Lennard Jones潜力的衍生物.其原因是,我写一个分子动力学程序和时间至少80%是在下面的函数中度过,即使是最激进的编译器选项(GCC **-O3).
double ljd(double r) /* Derivative of Lennard Jones Potential for Argon with
respect to distance (r) */
{
double temp;
temp = Si/r;
temp = temp*temp;
temp = temp*temp*temp;
return ( (24*Ep/r)*(temp-(2 * pow(temp,2))) );
}
此代码来自文件"functs.h",我将其导入到我的主文件中.我认为以这种方式使用临时变量会使函数更快,但我担心创建它们太浪费了.我应该使用静电吗?此外,代码是使用openmp并行编写的,所以我不能真正将temp声明为全局变量?
定义变量Ep和Si(使用#define).我只使用C约1个月.我试着看一下gcc生成的汇编代码,但我完全迷失了.