0
我有2 THREE.Vector3()
s。三个js圆偏角(旋转点)
我想画一个circle
围绕一个矢量,并使用第二个矢量作为切线。
我有圆弧几何的半径是向量之间的距离。
我怎样才能旋转圈触摸第二个向量?
我怎样才能获得弧度的圆(赤纬)旋转?
我可以使用三种框架功能还是需要使用数学方法?
(我希望它应该是3D框架的一些核心功能)。
我有2 THREE.Vector3()
s。三个js圆偏角(旋转点)
我想画一个circle
围绕一个矢量,并使用第二个矢量作为切线。
我有圆弧几何的半径是向量之间的距离。
我怎样才能旋转圈触摸第二个向量?
我怎样才能获得弧度的圆(赤纬)旋转?
我可以使用三种框架功能还是需要使用数学方法?
(我希望它应该是3D框架的一些核心功能)。
在3D矢量图形是4x4 homogenous transform matrices
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于矩阵的适当字段atan2
或acos(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 [] * Cvector_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
基向量所以没有必要通过将其乘以
什么是你不知道的硬件计算角度或不知道的问题如何计算旋转?你也使用变换矩阵还是自己变换坐标?另请参阅[glCircle3D](http://stackoverflow.com/a/25182327/2521214)它可能会帮助 – Spektre
我要求正确的方法。我可以在三角形上使用测角公式,但是我问三维是否可以通过某个函数来完成它,例如getAngle(a,b,c)等等...... 将pythagoras formules写入js源代码是无效的。 – Martin