任意轴算法 ( Arbitrary Axis Algorithm )

已知三维空间中任意单位向量,求以该向量为Z轴的local正交坐标系:

任意轴算法 ( Arbitrary Axis Algorithm )

如上图,每个模型都有自己local 坐标系,已知其中一个朝向求另外两个方向。

在autodesk中采用的是Arbitrary Axis Algorith。

http://www.autodesk.com/techpubs/autocad/acadr14/dxf/arbitrary_axis_algorithm_al_u05_c.htm

下面就叙述一下这个算法的原理:

Input:N(x,y,z)

Output:Local_X(x,y,z) Local_Y(x,y,z) Local_Z(x,y,z)

Begin

Local_Z =N ;

单位化Local_Z;

if(abs(Local_Z.x) < 1/64) and (abs (Local_Z.y) < 1/64)//N 不是Z轴abs 

{

Local_X = Local_Z 叉乘 (0,1,0);

单位化Local_X;

Local_Y = Local_Z 叉乘 Local_X;

}

else

{

Local_X = Local_Z 叉乘 (0,0,1);

单位化Local_X;

Local_Y = Local_Z 叉乘 Local_X;

}

End

用matlab进行算法验证

function [AxisX AxisY AxisZ]=ArbitraryAxisAlgorithm(AxisZ)
AxisZ =AxisZ/sqrt(sum(AxisZ'*AxisZ));
if(AxisZ(1)<1e-6 && AxisZ(2)<1e-6 )
AxisX = cross(AxisZ,[0 1 0]');
AxisY = cross(AxisX,AxisZ);
else
AxisX = cross(AxisZ,[0 1 0]');
AxisY = cross(AxisX,AxisZ);
end
x=[0 AxisX(1) ];
y=[0 AxisX(2) ];
z=[0 AxisX(3) ];
%plot3(x,y,z);

plot3(x,y,z,'r','linewidth',2);
hold on;
x=[0 AxisY(1)]
y=[0 AxisY(2)]
z=[0 AxisY(3)]
figure(1)
plot3(x,y,z,'g','linewidth',2);
hold on;
x=[0 AxisZ(1)]
y=[0 AxisZ(2)]
z=[0 AxisZ(3)]
figure(1)
plot3(x,y,z,'b','linewidth',2);
hold on;
end

运行[x y z]=ArbitraryAxisAlgorithm([1 1 1]')进行验证

任意轴算法 ( Arbitrary Axis Algorithm )

 

你可能感兴趣的:(Algorithm)