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.
- Stefano Zaghi — @szaghi
Contributions are welcome — see the Contributing page.
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.
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.0Vectorial 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.0Standalone — 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/prefixAs a project dependency — declare VecFor in your fobos and run fetch:
[dependencies]
deps_dir = src/third_party
VecFor = https://github.com/szaghi/VecForFoBiS.py fetch # fetch and build
FoBiS.py fetch --update # re-fetch and rebuildAdd to your fpm.toml:
[dependencies]
VecFor = { git = "https://github.com/szaghi/VecFor" }fpm build
fpm testcmake -B build && cmake --build buildmake # static library
make TESTS=yes # build and run tests