linalg icon indicating copy to clipboard operation
linalg copied to clipboard

Suggestion: projection_onto() and rejection_from() functions for vectors

Open csp256 opened this issue 3 years ago • 1 comments

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.

csp256 avatar Jul 02 '21 23:07 csp256

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.

sgorsten avatar Oct 28 '21 04:10 sgorsten