Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.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
Javascript 在circle Three.js上计算目标范围_Javascript_Math_Three.js_Radians - Fatal编程技术网

Javascript 在circle Three.js上计算目标范围

Javascript 在circle Three.js上计算目标范围,javascript,math,three.js,radians,Javascript,Math,Three.js,Radians,我有一道数学题正在努力解决 我有一个特别的弧度,我想把相机对准相机。我想告诉用户,如果他们需要向左或向右平移以获得该弧度,公差为PI/4 我已经通过相机+推拉旋转使平移数正常化 function getCurrentPan(){ return dolly.rotation.y + camera.rotation.y > 0 ? (dolly.rotation.y + camera.rotation.y)%Math.PI : ((dolly.rotat

我有一道数学题正在努力解决

我有一个特别的弧度,我想把相机对准相机。我想告诉用户,如果他们需要向左或向右平移以获得该弧度,公差为PI/4

我已经通过相机+推拉旋转使平移数正常化

function getCurrentPan(){
    return dolly.rotation.y + camera.rotation.y > 0
        ? (dolly.rotation.y + camera.rotation.y)%Math.PI
        : ((dolly.rotation.y + camera.rotation.y)%Math.PI) + Math.PI;
}
所以它总是在0和π之间

我计划计算出我可以检查的范围,看看用户是否需要向左或向右平移才能达到该弧度。正在尝试此代码:

      point.leftRange = {};
        point.leftRange.min = point.pan - range > 0 ? point.pan - range : Math.PI - point.pan - range;
        point.leftRange.max = point.leftRange.min - Math.PI/2 - range > 0 ? (point.pan - range)%Math.PI : (Math.PI - (point.leftRange.min - Math.PI/2 - range))% Math.PI;

        console.log(point.leftRange);

        point.rightRange = {};
        point.rightRange.min = (point.pan + range) % Math.PI;
        point.rightRange.max = (point.rightRange.min + (Math.PI/2 - range)) % Math.PI;

        console.log(point.rightRange);
这让我觉得

点1.464308692701496 左最小值1.071609611002772 左最大0.8918857974908487 右。最小值1.8570077744002202 右最大值3.0351050194963927 我尝试过的另一种方法是

             var opp = (point.pan - Math.PI/2)%Math.PI;
                opp = opp > 0 ? opp : Math.PI - opp;

                if(getCurrentPan() > point.pan && getCurrentPan() < opp)
                     console.log('greater');
                else if(getCurrentPan() < point.pan && getCurrentPan() > opp)
                     console.log('less');
如果pan的值为0.5,左范围为3,则不考虑这一点


对不起,我没有解释清楚,但如果有人能给我指出正确的方向,我将不胜感激

这是过度设计的。如果要确定目标是在摄影机的左侧还是右侧,请执行以下操作:

d = camera.getworlddirection();
diff = target.position - camera.position;
theta = atan2(diff.x,diff.z) - atan2(d.x,d.z);
这是摄影机的观察位置与对象相对于摄影机的位置之间的角度

因此:


谢谢那很有用。我的问题不是它是一个物体。。但这可能有好处——更多的是存储的视角。我可能可以在这个角度上添加一个隐藏的对象,如果我不能根据这个角度来做的话。目标的类型是什么。位置和相机。位置是我得到的向量类型。我得到的错误可能意味着很多事情。位置是3。矢量3是。控制台输出说明了什么?如果你有问题,开始一个新问题。
if(abs(theta) < someThreshold){
  if(theta > 0){
    //its to the right
  }
  else{
   //its to the left
  }
}