项目作者: pdebuyl

项目描述 :
Basic quaternion operations
高级语言: Fortran
项目地址: git://github.com/pdebuyl/fortran_quaternion.git
创建时间: 2017-02-05T21:54:44Z
项目社区:https://github.com/pdebuyl/fortran_quaternion

开源协议:BSD 3-Clause "New" or "Revised" License

下载


fortran_quaternion

Author: Pierre de Buyl
License: 3-clause BSD

Build Status

fortran_quaternion is a Fortran module that provides some basic quaternion functions.

fortran_quaternion does not define any derived type, instead quaternions are provided as
4-element vectors storing the vector part first and the scalar part last.

  • qnew: return a quaternion from the scalar and vector input.
  • qvector: return the vector part of a quaternion.
  • qscalar: return the scalar part of a quaternion.
  • qnorm: return the norm.
  • qnormalize: return the normalized quaternion.
  • qconj: return the conjugate.
  • qinv: return the inverse.
  • qmul: return the product of two quaternions.

Example programs

Multiplication of two quaternions

  1. program quaternion_usage
  2. use quaternion
  3. implicit none
  4. double precision :: q1(4), q2(4)
  5. q1 = qnew(v=[1.d0, 2.d0, 3.d0], s=4.d0)
  6. q2 = qnew(v=[6.d0, 7.d0, 8.d0], s=5.d0)
  7. write(*,'(4f5.2,a,4f5.2)') q1, ' x ', q2
  8. write(*,'(a,4f7.2)') '= ', qmul(q1, q2)
  9. end program quaternion_usage

Rotation of a 3d vector about a given axis

  1. program quaternion_rotation
  2. use quaternion
  3. implicit none
  4. double precision :: q(4), v(3)
  5. double precision :: axis(3), theta
  6. axis = [ 1, 1, 0 ]
  7. theta = 2*atan(1.d0) ! pi/2
  8. q = qnew(s=cos(theta/2), v=sin(theta/2)*axis/norm2(axis))
  9. v = [0, 0, 1]
  10. write(*,'(a,3f7.2)') 'v = ', v
  11. ! Rotate qv by q
  12. v = qvector(qmul(q, qmul(qnew(v=v), qconj(q))))
  13. write(*,'(a,3f7.2)') 'rotated v = ', v
  14. end program quaternion_rotation

Installation

Copy the file src/quaternion.f90 or use cmake (with the add_subdirectory command) to
add the library to your project.

Tests

Tests are defined in test/ and rely on
fortran_tester, installed via git submodules:

  1. git submodule init
  2. git submodule update