用 Scilab 计算OpenGL 的旋转矩阵

来源:互联网 发布:儿童编程培训班多少钱 编辑:程序博客网 时间:2024/05/29 06:40

Scilab  (http://www.scilab.org/) 是一款免费的,类似于Matlab的软件。

进行矩阵运算的时候比较方便。

 

 

OpenGl的三维坐标系中, 分别绕 x, y, z 三坐标轴旋转xAngle, yAngle, zAngle之后的旋转矩阵,可以用下列公式计算。

 

function [ glRotateMatrix ] = glRotateMatrix( xAngle, yAngle, zAngle )

   // Convert angle to radius
  thetaX = xAngle * ( %pi / 180.0 );
  thetaY = yAngle * ( %pi / 180.0 );
  thetaZ = zAngle * ( %pi / 180.0 );

  Rx = [
    1 0 0
    0 cos( thetaX ) -sin( thetaX )
    0 sin( thetaX ) cos( thetaX )
  ];

  Ry = [
    cos( thetaY ) 0 sin( thetaY )
    0 1 0
    -sin( thetaY ) 0 cos( thetaY )
  ];

  Rz = [
    cos( thetaZ ) -sin( thetaZ ) 0
    sin( thetaZ ) cos( thetaZ ) 0
    0 0 1
  ];

  glRotateMatrix = Rx * Ry * Rz;

endfunction

 

使用方法:

// v 是极其手臂的位置。

 

-->v  = {0; 0; 8}

-->glRotateMatrix(30, 45, 0) * v
 ans  =
 
    5.6568542 
  - 2.8284271 
    4.8989795

原创粉丝点击