2015-07-22 91 views
0

我有2 THREE.Vector3() s。三个js圆偏角(旋转点)

我想画一个circle围绕一个矢量,并使用第二个矢量作为切线。

我有圆弧几何的半径是向量之间的距离。

我怎样才能旋转圈触摸第二个向量?

我怎样才能获得弧度的圆(赤纬)旋转?

我可以使用三种框架功能还是需要使用数学方法?

(我希望它应该是3D框架的一些核心功能)。

enter image description here

+0

什么是你不知道的硬件计算角度或不知道的问题如何计算旋转?你也使用变换矩阵还是自己变换坐标?另请参阅[glCircle3D](http://stackoverflow.com/a/25182327/2521214)它可能会帮助 – Spektre

+0

我要求正确的方法。我可以在三角形上使用测角公式,但是我问三维是否可以通过某个函数来完成它,例如getAngle(a,b,c)等等...... 将pythagoras formules写入js源代码是无效的。 – Martin

回答

0

在3D矢量图形是4x4 homogenous transform matrices

  • 您创建的矩阵,它适用于整个几何做的伎俩
  • ,通常是在GFX HW侧
  • 完成
  • 在你的情况下,你甚至不需要计算角度只是计算基向量

这是我的glCircle3D in C++/OpenGL

void glCircle3D(double *pos,double *nor,double r,bool _fill) 
    { 
    int i,n=36; 
    double a,da=divide(pi2,n),p[3],dp[3],x[3],y[3]; 
    // set x to something not parallel to normal vector 
     if (fabs(nor[0]-nor[1])>1e-6) vector_ld(x,nor[1],nor[0],nor[2]); 
    else if (fabs(nor[0]-nor[2])>1e-6) vector_ld(x,nor[2],nor[1],nor[0]); 
    else if (fabs(nor[1]-nor[2])>1e-6) vector_ld(x,nor[0],nor[2],nor[1]); 
    else      vector_ld(x,1.0,0.0,0.0); 
    vector_mul(x,x,nor); // x=cross(x,nor) 
    vector_mul(y,x,nor); // y=cross(x,nor) 
    vector_len(x,x,r); // x=r*x/|x| ... r is scalar 
    vector_len(y,y,r); // y=r*y/|y| ... r is scalar 
    if (_fill) 
     { 
     glBegin(GL_TRIANGLE_FAN); 
     glVertex3dv(pos); 
     } 
    else glBegin(GL_LINE_STRIP); 
    for (a=0.0,i=0;i<=n;i++,a+=da) 
     { 
     vector_mul(dp,x,cos(a)); vector_add(p,pos,dp); 
     vector_mul(dp,y,sin(a)); vector_add(p,p ,dp); 
     glVertex3dv(p); 
     } 
    glEnd(); 
    } 
  • nor是圆正常(你的情况第二向量)
  • pos是圆中心位置(在你的情况0,0,0 )
  • r是半径(在你的情况下你的第一个向量大小)
  • x,y载体系统
  • 基本向量与nor定义正交坐标如果要构造变换矩阵然后只复制的x,y,也没有,POS于矩阵的适当字段
  • 并使用半径为1
  • 圆几何
  • 你可以看到没有atan2acos(dot(v1,v2))需要
  • 只是简单的交叉产品就足够了......
  • 矿使用矿载体文库的代码
  • 因此只需像
  • vector_ld(a,x,y,z)一个[] = {X,Y,Z}
  • vector_mul(a,b,c)编写功能的[] = B [] XC []
  • vector_mul(a,b,c)一个[] = b [] * C
  • vector_add(a,b,c)一个[] = b [] + C []
  • vector_sub(a,b,c)一个[] = b [] - C []
  • vector_len(a,b,c) a [] = b [] * c/| b [] |
  • 圆坐标很简单:p=pos+x*cos(alpha)+y*sin(alpha);
  • 半径r里面已经x,y基向量所以没有必要通过将其乘以