Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pdebuyl/fortran_quaternion
Basic quaternion operations
https://github.com/pdebuyl/fortran_quaternion
fortran
Last synced: 28 days ago
JSON representation
Basic quaternion operations
- Host: GitHub
- URL: https://github.com/pdebuyl/fortran_quaternion
- Owner: pdebuyl
- License: bsd-3-clause
- Created: 2017-02-05T21:54:44.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-03-02T14:44:00.000Z (over 7 years ago)
- Last Synced: 2024-01-29T08:46:52.223Z (9 months ago)
- Topics: fortran
- Language: Fortran
- Size: 13.7 KB
- Stars: 11
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fortran_quaternion
**Author:** Pierre de Buyl
**License:** 3-clause BSD[![Build Status](https://travis-ci.org/pdebuyl/fortran_quaternion.svg?branch=master)](https://travis-ci.org/pdebuyl/fortran_quaternion)
`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
~~~.f90
program quaternion_usage
use quaternion
implicit nonedouble precision :: q1(4), q2(4)
q1 = qnew(v=[1.d0, 2.d0, 3.d0], s=4.d0)
q2 = qnew(v=[6.d0, 7.d0, 8.d0], s=5.d0)write(*,'(4f5.2,a,4f5.2)') q1, ' x ', q2
write(*,'(a,4f7.2)') '= ', qmul(q1, q2)end program quaternion_usage
~~~### Rotation of a 3d vector about a given axis
~~~.f90
program quaternion_rotation
use quaternion
implicit nonedouble precision :: q(4), v(3)
double precision :: axis(3), thetaaxis = [ 1, 1, 0 ]
theta = 2*atan(1.d0) ! pi/2q = qnew(s=cos(theta/2), v=sin(theta/2)*axis/norm2(axis))
v = [0, 0, 1]
write(*,'(a,3f7.2)') 'v = ', v
! Rotate qv by q
v = qvector(qmul(q, qmul(qnew(v=v), qconj(q))))
write(*,'(a,3f7.2)') 'rotated v = ', vend 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](https://github.com/pdebuyl/fortran_tester), installed via git submodules:git submodule init
git submodule update