boostorg / qvm

Boost Quaternions, Vectors, Matrices library
Boost Software License 1.0
82 stars 43 forks source link

Add corss operation for 2d vector #28

Closed eryar closed 3 years ago

eryar commented 3 years ago

Hello, I find that the cross operation only for 3d vector:

namespace boost { namespace qvm {

    //Only enabled if:
    //  is_vec<A>::value && is_vec<B>::value &&
    //  vec_traits<A>::dim==3 && vec_traits<B>::dim==3
    template <class A,class B>
    typename deduce_vec2<A,B,3>::type
    cross( A const & a, B const & b );

} }

cross for 2d vector is also useful for check parallel.

Best Regards,

zajo commented 3 years ago

On Mon, Dec 14, 2020 at 6:52 AM Shing Liu notifications@github.com wrote:

Hello, I find that the cross operation only for 3d vector:

namespace boost { namespace qvm {

//Only enabled if:
//  is_vec<A>::value && is_vec<B>::value &&
//  vec_traits<A>::dim==3 && vec_traits<B>::dim==3
template <class A,class B>
typename deduce_vec2<A,B,3>::type
cross( A const & a, B const & b );

} }

cross for 2d vector is also useful for check parallel.

I thought that in math cross product is only defined for 3D vectors, but today I learned ( https://www.gamedev.net/forums/topic/289972-cross-product-of-2d-vectors/2828289/) that there are "analogs" for other dimensions, e.g. for 2D we could use (U.xV.y-U.yV.x). Is this what you had in mind?

eryar commented 3 years ago

Yes, I mean the "analogs" for 2d vector, use (U.xV.y-U.yV.x). The cross product result of two 3d vector is a vector, but the "analogs" for 2d vector is a scalar type.

zajo commented 3 years ago

See https://github.com/boostorg/qvm/blob/master/include/boost/qvm/vec_operations.hpp#L147.

eryar commented 3 years ago

Great! Thank you.