VecFor
February 28, 2026 ยท View on GitHub
3D Cartesian vector algebra for Fortran
a pure Fortran 2003+ OOP library for vectorial calculus in a three-dimensional frame of reference.
๐ Rich Operator Set+, -, *, /, .cross., .dot., .paral., .ortho. โ full Cartesian algebra in operator notation | ๐ข Mixed-Kind Operands Vector OP scalar for any integer or real PENF kind, resolved at compile time with no runtime overhead | ๐ Geometry Methodsangle, rotate, mirror, face_normal3/4, distance_to_line, distance_to_plane, projection_onto_plane | ๐๏ธ Multi-Precisionvector_R4P, vector_R8P (default), vector_R16P โ all re-exported from a single use vecfor |
|---|---|---|---|
| โก Pure & Elemental All procedures are pure or elemental โ thread-safe, no side effects | ๐ Multi-licensed GPL v3 ยท BSD 2/3-Clause ยท MIT | ๐ฆ Multiple build systems fpm, FoBiS, CMake, Make | ๐ OOP / TDD designed One derived type, comprehensive automated doctests |
For full documentations (guide, tutorial, examples, etc...) see the VecFor website.
Authors
- Stefano Zaghi โ @szaghi
Contributions are welcome โ see the Contributing page.
Copyrights
This project is distributed under a multi-licensing system:
- FOSS projects: GPL v3
- Closed source / commercial: BSD 2-Clause, BSD 3-Clause, or MIT
Anyone interested in using, developing, or contributing to VecFor is welcome โ pick the license that best fits your needs.
Quick start
Import VecFor, build vectors from the built-in Cartesian versors, and perform algebra:
use vecfor
implicit none
type(vector) :: point1, point2, distance
point1 = 1 * ex ! ex, ey, ez are the Cartesian unit versors
point2 = 1 * ex + 2 * ey
distance = point2 - point1 ! [0, 2, 0]
call distance%print ! Component y +2.000...
print *, distance%normL2() ! 2.0
Vectorial operators:
use vecfor
use penf, only: R8P
implicit none
type(vector) :: v1, v2, cross
real(R8P) :: dot
v1 = ex
v2 = ex + 2 * ey
cross = v1 .cross. v2 ! [0, 0, 2]
dot = v1 .dot. v2 ! 1.0
Install
FoBiS
Standalone โ clone, build, and install in one command:
FoBiS.py install szaghi/VecFor -mode static-gnu
FoBiS.py install szaghi/VecFor -mode static-gnu --prefix /path/to/prefix
As a project dependency โ declare VecFor in your fobos and run fetch:
[dependencies]
deps_dir = src/third_party
VecFor = https://github.com/szaghi/VecFor
FoBiS.py fetch # fetch and build
FoBiS.py fetch --update # re-fetch and rebuild
fpm
Add to your fpm.toml:
[dependencies]
VecFor = { git = "https://github.com/szaghi/VecFor" }
fpm build
fpm test
CMake
cmake -B build && cmake --build build
Makefile
make # static library
make TESTS=yes # build and run tests