bambooflow Note

2次元ベクトルの回転

最終更新:

bambooflow

- view
メンバー限定 登録/ログイン

2次元ベクトルの回転



  • 変換式
\begin{pmatrix} x\cr y\cr \end{pmatrix} = \begin{pmatrix}\cos \theta &-\sin \theta\cr \sin \theta&\cos \theta\cr \end{pmatrix}\begin{pmatrix} x\cr y\cr \end{pmatrix}

θは2つのベクトルの角度差。

  • サンプルコード
#include <stdio.h>
#include <glm/glm.hpp>
#include <glm/gtx/rotate_vector.hpp>
 
int main(int argc, char* argv[])
{ 
  glm::dvec2 a(1.0, 0.0);
  glm::dvec2 b;
  glm::dvec2 c;
 
  b = glm::rotate(a, 30.0); // degree
 
  printf("a = %f,%f\n", a.x, a.y);
  printf("b = %f,%f\n", b.x, b.y);
 
  return 0;
}
 

a = 1.000000,0.000000
c = 0.866025,0.500000

タグ:

OpenGL GLM
記事メニュー
ウィキ募集バナー