linalg
linalg copied to clipboard
Suggestion: projection_onto() and rejection_from() functions for vectors
For example:
template<class T> struct vec<T,4>
{
// ...
vec<T,4> projected_onto(vec<T,4> const& v) { return (dot(*this,v)/dot(v,v)) * v;}
vec<T,4> rejection_from(vec<T,4> const& v) { return *this - this->projected_onto(v); }
// ...
}
I feel like projection_onto()
at least is common enough to warrant inclusion.
They'd both be pretty sensible additions, and I think I have a couple copies of each floating around in various codebases over the years.
I'd probably prefer to include them as free functions, for consistency with the rest of the library, although the names don't work as well without the a.func(b) infix-style naming.