Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Algorithm 理解此代码片段中的旋转数学_Algorithm_Unity3d_Math_3d_Game Development - Fatal编程技术网

Algorithm 理解此代码片段中的旋转数学

Algorithm 理解此代码片段中的旋转数学,algorithm,unity3d,math,3d,game-development,Algorithm,Unity3d,Math,3d,Game Development,下面是我的代码,它是由伪代码给出的,专门针对旋转的东西 var rad = (targettransform.rotationEuler.y) * Math.PI / 180; var difVec = targettransform.pos - othertransform.pos; //the difVec.z which means radius this._targetPos.z -= difVec.z * (1 - Math.cos(rad)); this._targetPos.

下面是我的代码,它是由伪代码给出的,专门针对旋转的东西

var rad = (targettransform.rotationEuler.y) * Math.PI / 180;


var difVec = targettransform.pos - othertransform.pos;

//the difVec.z which means radius
this._targetPos.z -= difVec.z * (1 - Math.cos(rad));
this._targetPos.x += difVec.z * Math.sin(rad);

this.transform.position = this._targetPos;
this.transform.lookAt(targettransform.position, Utils.UnitY);
上面的伪代码只不过是旋转而已,但我不明白
1-Math.cos(rad)
的作用,它可能是相对于三角函数的一些推导。有人能详细解释一下数学吗

编辑
对不起,我弄错了,代码片段的主要目的是在x-z平面上通过
vec3(difVec.z*Math.sin(rad),0,this.\u targetpos.z)
偏移“\u targetpos”。我设法重写了伪代码以使其有意义。代码片段似乎只实现了保持相对距离和观察目标的功能。

我们可以在绕任意轴旋转公式中看到这样的术语
(1-Cos(Fi))
(Sin(Fi))


但这个问题并没有提供足够的细节来确定这个代码到底是做什么的。

1-cos(Θ)=2sin²(Θ/2)和sin(Θ)=2sin(Θ/2)cos(Θ/2),这样你就可以将标量δ乘以2sin(Θ/2),再乘以方向上的一个向量,这个向量被加到目标位置。

我知道三角恒等式,这对公众来说没有任何意义rotation@haoc:我不同意你的观点。我怀疑-通过
移动z分量。z
可能表示它变为零。也许更清楚地描述真实的问题会有所帮助。