24#include "AstMath/MathOperator.hpp"
25#include "AstUtil/Constants.hpp"
26#include "AstUtil/Math.hpp"
44template<
typename _Scalar,
size_t N>
48#define _AST_DEF_VECTOR_METHOD(Scalar) \
49 A_DEF_POD_ITERABLE(Scalar) \
50 Scalar operator()(size_t idx) const{return data()[idx];} \
51 Scalar& operator()(size_t idx) {return data()[idx];} \
52 Scalar& x() {return data()[0];} \
53 Scalar& y() {return data()[1];} \
54 Scalar& z() {return data()[2];} \
55 Scalar x() const {return data()[0];} \
56 Scalar y() const {return data()[1];} \
57 Scalar z() const {return data()[2];} \
61template<
typename _Scalar,
size_t N>
65 typedef _Scalar Scalar;
67 _AST_DEF_VECTOR_METHOD(Scalar);
73template<
typename _Scalar>
78 typedef _Scalar Scalar;
82 :x_(0), y_(0), z_(0){}
83 VectorN(
double x,
double y,
double z)
84 :x_(x), y_(y), z_(z){}
86 #ifdef AST_BUILD_LIB_PY
87 void __setitem__(
size_t idx, _Scalar v){data()[idx] = v;}
90 static Self Zero(){
return Self{0,0,0}; }
91 static Self UnitX() {
return Self{1,0,0}; }
92 static Self UnitY() {
return Self{0,1,0}; }
93 static Self UnitZ() {
return Self{0,0,1}; }
95 _Scalar at(
size_t idx)
const{
return data()[idx]; }
96 _Scalar& at(
size_t idx) {
return data()[idx]; }
99 double norm()
const{
return _ASTMATH
norm(*
this);}
101 Self cross(
const Self& other)
const{
return _ASTMATH cross(*
this, other);}
102 double angle(
const Self& other)
const{
return Angle(*
this, other);}
103 double dot(
const Self& other)
const{
return _ASTMATH
dot(*
this, other);}
104 void setZero(){x_ = y_ = z_ = 0;}
105 Self& operator*=(Scalar
s){
return *
this = _ASTMATH
operator*(*
this,
s);}
108 Self operator-()
const{
return Self{-x_, -y_, -z_};}
109 Self operator-(
const Self& other)
const{
return _ASTMATH operator-(*
this, other);}
110 Self operator+(
const Self& other)
const{
return _ASTMATH operator+(*
this, other);}
111 Self& operator+=(
const Self& other){
return *
this = _ASTMATH operator+(*
this, other);}
112 Self& transpose(){
return *
this;}
113 const Self& transpose()
const{
return *
this;}
114 std::string toString()
const;
115 _AST_DEF_VECTOR_METHOD(Scalar);
121AST_MATH_API std::string toString(
const Vector3d& v);
123template<
typename _Scalar>
135 void resize(
size_t size);
137 A_DEF_ITERABLE(_Scalar, data_, size_)
139 _Scalar* data_{
nullptr};
147template<
typename _Scalar>
150 return aAngle(v1, v2);
153template<
typename _Scalar>
154inline VectorX<_Scalar>::VectorX()
160template<
typename _Scalar>
161inline VectorX<_Scalar>::VectorX(
size_t size)
162 : data_((_Scalar*)malloc(sizeof(_Scalar)* size))
169template<
typename _Scalar>
170inline VectorX<_Scalar>::~VectorX()
176template<
typename _Scalar>
177inline void VectorX<_Scalar>::resize(
size_t size)
183 data_ = (_Scalar*)malloc(
sizeof(_Scalar) * size);
188template <
typename _Scalar>
189inline void VectorX<_Scalar>::setZero()
192 memset(data_, 0,
sizeof(_Scalar) * size_);
195typedef VectorX<double> VectorXd;
203AST_DECL_TYPE_ALIAS(Vector3d)
204AST_DECL_TYPE_ALIAS(VectorXd)
MatrixMN< _Scalar, I, K > operator*(const MatrixMN< _Scalar, I, J > &left, const MatrixMN< _Scalar, J, K > &right)
矩阵乘法
定义 MathOperator.hpp:580
double norm(const double *vec, size_t N)
norm
定义 MathOperator.hpp:290
double dot(const Container1 &vec1, const Container2 &vec2)
dot
定义 MathOperator.hpp:162
auto normalized(const Vector &vec) -> typename std::enable_if<!std::is_pointer< Vector >::value, Vector >::type
normalized
定义 MathOperator.hpp:361
double normalize(double *vec, size_t N)
normalize
定义 MathOperator.hpp:315
double squaredNorm(const double *vec, size_t N)
squaredNorm
定义 MathOperator.hpp:254
constexpr EDimension operator/(EDimension dim1, EDimension dim2) noexcept
量纲除法运算符
定义 Dimension.hpp:232