⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 quaternion.hpp

📁 CGAL is a collaborative effort of several sites in Europe and Israel. The goal is to make the most i
💻 HPP
📖 第 1 页 / 共 5 页
字号:
//  boost quaternion.hpp header file//  (C) Copyright Hubert Holin 2001.//  Distributed under the Boost Software License, Version 1.0. (See//  accompanying file LICENSE_1_0.txt or copy at//  http://www.boost.org/LICENSE_1_0.txt)// See http://www.boost.org for updates, documentation, and revision history.#ifndef BOOST_QUATERNION_HPP#define BOOST_QUATERNION_HPP#include <complex>#include <iosfwd>                                    // for the "<<" and ">>" operators#include <sstream>                                    // for the "<<" operator#include <boost/config.hpp> // for BOOST_NO_STD_LOCALE#ifndef    BOOST_NO_STD_LOCALE    #include <locale>                                    // for the "<<" operator#endif /* BOOST_NO_STD_LOCALE */#include <valarray>#include <boost/math/special_functions/sinc.hpp>    // for the Sinus cardinal#include <boost/math/special_functions/sinhc.hpp>    // for the Hyperbolic Sinus cardinalnamespace boost{    namespace math    {#if defined(__GNUC__) && (__GNUC__ < 3)        // gcc 2.95.x uses expression templates for valarray calculations, but        // the result is not conforming. We need BOOST_GET_VALARRAY to get an        // actual valarray result when we need to call a member function    #define    BOOST_GET_VALARRAY(T,x)    ::std::valarray<T>(x)        // gcc 2.95.x has an "std::ios" class that is similar to         // "std::ios_base", so we just use a #define    #define    BOOST_IOS_BASE    ::std::ios        // gcc 2.x ignores function scope using declarations,        // put them in the scope of the enclosing namespace instead:        using    ::std::valarray;        using    ::std::sqrt;        using    ::std::cos;        using    ::std::sin;        using    ::std::exp;        using    ::std::cosh;#endif /* defined(__GNUC__) && (__GNUC__ < 3) */#define    BOOST_QUATERNION_ACCESSOR_GENERATOR(type)                    \            type                    real() const                        \            {                                                           \                return(a);                                              \            }                                                           \                                                                        \            quaternion<type>        unreal() const                      \            {                                                           \                return(quaternion<type>(static_cast<type>(0),b,c,d));   \            }                                                           \                                                                        \            type                    R_component_1() const               \            {                                                           \                return(a);                                              \            }                                                           \                                                                        \            type                    R_component_2() const               \            {                                                           \                return(b);                                              \            }                                                           \                                                                        \            type                    R_component_3() const               \            {                                                           \                return(c);                                              \            }                                                           \                                                                        \            type                    R_component_4() const               \            {                                                           \                return(d);                                              \            }                                                           \                                                                        \            ::std::complex<type>    C_component_1() const               \            {                                                           \                return(::std::complex<type>(a,b));                      \            }                                                           \                                                                        \            ::std::complex<type>    C_component_2() const               \            {                                                           \                return(::std::complex<type>(c,d));                      \            }                #define    BOOST_QUATERNION_MEMBER_ASSIGNMENT_GENERATOR(type)                               \            template<typename X>                                                            \            quaternion<type> &        operator = (quaternion<X> const  & a_affecter)        \            {                                                                               \                a = static_cast<type>(a_affecter.R_component_1());                          \                b = static_cast<type>(a_affecter.R_component_2());                          \                c = static_cast<type>(a_affecter.R_component_3());                          \                d = static_cast<type>(a_affecter.R_component_4());                          \                                                                                            \                return(*this);                                                              \            }                                                                               \                                                                                            \            quaternion<type> &        operator = (quaternion<type> const & a_affecter)      \            {                                                                               \                a = a_affecter.a;                                                           \                b = a_affecter.b;                                                           \                c = a_affecter.c;                                                           \                d = a_affecter.d;                                                           \                                                                                            \                return(*this);                                                              \            }                                                                               \                                                                                            \            quaternion<type> &        operator = (type const & a_affecter)                  \            {                                                                               \                a = a_affecter;                                                             \                                                                                            \                b = c = d = static_cast<type>(0);                                           \                                                                                            \                return(*this);                                                              \            }                                                                               \                                                                                            \            quaternion<type> &        operator = (::std::complex<type> const & a_affecter)  \            {                                                                               \                a = a_affecter.real();                                                      \                b = a_affecter.imag();                                                      \                                                                                            \                c = d = static_cast<type>(0);                                               \                                                                                            \                return(*this);                                                              \            }                #define    BOOST_QUATERNION_MEMBER_DATA_GENERATOR(type)       \            type    a;                                        \            type    b;                                        \            type    c;                                        \            type    d;                        template<typename T>        class quaternion        {        public:                        typedef T value_type;                                    // constructor for H seen as R^4            // (also default constructor)                        explicit            quaternion( T const & requested_a = T(),                                            T const & requested_b = T(),                                            T const & requested_c = T(),                                            T const & requested_d = T())            :   a(requested_a),                b(requested_b),                c(requested_c),                d(requested_d)            {                // nothing to do!            }                                    // constructor for H seen as C^2                            explicit            quaternion( ::std::complex<T> const & z0,                                            ::std::complex<T> const & z1 = ::std::complex<T>())            :   a(z0.real()),                b(z0.imag()),                c(z1.real()),                d(z1.imag())            {                // nothing to do!            }                                    // UNtemplated copy constructor            // (this is taken care of by the compiler itself)                                    // templated copy constructor                        template<typename X>            explicit            quaternion(quaternion<X> const & a_recopier)            :   a(static_cast<T>(a_recopier.R_component_1())),                b(static_cast<T>(a_recopier.R_component_2())),                c(static_cast<T>(a_recopier.R_component_3())),                d(static_cast<T>(a_recopier.R_component_4()))            {                // nothing to do!            }                                    // destructor            // (this is taken care of by the compiler itself)                                    // accessors            //            // Note:    Like complex number, quaternions do have a meaningful notion of "real part",            //            but unlike them there is no meaningful notion of "imaginary part".            //            Instead there is an "unreal part" which itself is a quaternion, and usually            //            nothing simpler (as opposed to the complex number case).            //            However, for practicallity, there are accessors for the other components            //            (these are necessary for the templated copy constructor, for instance).                        BOOST_QUATERNION_ACCESSOR_GENERATOR(T)                        // assignment operators                        BOOST_QUATERNION_MEMBER_ASSIGNMENT_GENERATOR(T)                        // other assignment-related operators            //            // NOTE:    Quaternion multiplication is *NOT* commutative;            //            symbolically, "q *= rhs;" means "q = q * rhs;"            //            and "q /= rhs;" means "q = q * inverse_of(rhs);"                        quaternion<T> &        operator += (T const & rhs)            {                T    at = a + rhs;    // exception guard                                a = at;                                return(*this);            }                                    quaternion<T> &        operator += (::std::complex<T> const & rhs)            {                T    at = a + rhs.real();    // exception guard                T    bt = b + rhs.imag();    // exception guard                                a = at;                 b = bt;                                return(*this);            }                        

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -