Function alpha = vec2ang(v1,v2)
alpha = vec2ang(v1,v2,n)
alpha = vec2ang(v1,v2,n,m)
alpha = vec2ang(v1,v2,n,2,l1,l2)
returns the angle alpha between vector v1 and vector v2.
If normal n is input (or empty), the alpha is given in
degrees, in the range 0...180.
If normal n is input (and non-empty), the function
returns the angle alpha from vector v1 to vector v2,
measured anticlockwise around the normal. Then, alpha is
given in degrees, in the range 0...360.
All vectors are three-dimensional.
The function provides two methods:
-- a traditional method by cross and dot products, when
input argument m equals 1;
-- a method considering angles in a parallelogram, when
input argument m equals 2. It is numerically more
accurate and stable, according to W. Kahan in
"Computing Cross-Products and Rotations in 2- and
3-Dimensional Euclidean Spaces", 25 February 2016,
https://people.eecs.berkeley.edu/%7Ewkahan/MathH110/Cross.pdf .
The first method is applied at default.
Input arguments v1, v2, n, l1 and l2 are M-by-3 matrices.
The output argument alpha is an column vector of length M.
For the second method, one may input l1 and l2 which
contain the vector lengths of v1 and v2, respectively, to
avoid the internal calculation of vector lengths (again).
The function operates on each row of the input arguments.
So, for each row k, the function calculates the angle
alpha(k,1) between given vectors v1(k,:) and v2(k,:),
optionally with given n(k,:), and/or l1(k,:) and l2(k,:).
The function internally calls the following non-standard
m-files:
-- cross3d.m
-- dot3d.m
-- vectorlength.m
(c) 2026 fabien van mook
2026.08.20 release of this file within package "fvm-geometry" under GNU GPLv3+