【发布时间】:2026-01-30 09:05:03
【问题描述】:
请原谅我的第一篇文章,字面意思是这样。我已经敲了三天的头,试图让正方形在球体上正确对齐。有谁知道平面切线的参数方程?请参阅下面代码中的切线 X、Y 和 Z...
Here is the output for reference. My stupid face is there, as a bonus, for you all to hate on
代码是多个页面上更大库的一部分。这有点分散问题的注意力。我已经搜索了数学网站和 * 来寻找答案。我将位置和旋转数据烘焙到 Float32 数组中,然后再将其发送到渲染器。因此,lookAt 和其他三个和 WebGL 函数将不起作用。我需要纯数学解决方案。
this.sphere = function()
{
var args = arguments[ 0 ];
var offsets = offset( args.parameters.offsets );
var arrays =
{
unique: [],
position: [],
rotation: []
};
var phi, theta;
var x, y, z;
var tangentX, tangentY, tangentZ;
var pos = [];
var d360 = Math.PI * 2;
var d180 = Math.PI;
var d90 = Math.PI / 2;
var cap = false;
for ( var p = 0; p <= args.parameters.stacks; p++ )
{
// stacks
phi = d180 * p / args.parameters.stacks;
for ( var t = 0; t < args.parameters.slices; t++ )
{
var predicate = true;
// slices
theta = d360 * t / args.parameters.slices;
x = precision( Math.cos( theta ) * Math.sin( phi ), 3 ) * args.parameters.scale.x + offsets.position.x;
y = precision( Math.cos( phi ), 3 ) * args.parameters.scale.y + offsets.position.y;
z = precision( Math.sin( theta ) * Math.sin( phi ), 3 ) * args.parameters.scale.z + offsets.position.z;
pos = [ x, y, z ];
// caps - both sin and cos are 0
cap = !( precision( Math.sin( phi ), 0 ) || precision( Math.cos( theta ), 0 ) );
/* This is my problem area ************************************/
tangentX = - Math.sign( Math.sin( theta ) ) * Math.tan( y );
tangentY = d90 - theta;
tangentZ = 0;
//if ( predicate ) console.log( p, t, degrees( theta ), degrees( tangentY ), Math.sign( Math.sin( phi ) ) );
// add only once
if ( !hash( arrays.unique, pos ) && predicate )
{
arrays.unique.push( pos );
arrays.position.push( x, y, z );
arrays.rotation.push( tangentX, tangentY, tangentZ );
}
}
}
return { position: new Float32Array( arrays.position ), rotation: new Float32Array( arrays.rotation ) };
};
【问题讨论】:
-
将您的代码发布为文本,以便我们对其进行测试。您还应该将代码的主要部分也放入您的问题中。
-
我看到你的代码不在three.js中,我不知道你如何定义和使用旋转。但是,在three.js 中,您需要的是正确旋转您的飞机,您可以参考How to plot country names on the globe, so the mesh will be aligned with the surfaces。
-
来自 Stack Overflow 的帮助:寻求调试帮助的问题(“为什么这段代码不起作用?”)必须包括所需的行为、特定问题或错误以及重现所需的最短代码它在问题本身中。请在问题中输入您的代码文本,而不是文本的屏幕截图。
标签: 3d three.js webgl parametric-equations