00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef VCG_USE_EIGEN
00025 #include "deprecated_point2.h"
00026 #else
00027
00028 #ifndef __VCGLIB_POINT2
00029 #define __VCGLIB_POINT2
00030
00031 #include "../math/eigen.h"
00032
00033
00034 namespace vcg{
00035 template<typename Scalar> class Point2;
00036 }
00037
00038 namespace Eigen {
00039 template<typename Scalar> struct ei_traits<vcg::Point2<Scalar> > : ei_traits<Eigen::Matrix<Scalar,2,1> > {};
00040 template<typename XprType> struct ei_to_vcgtype<XprType,2,1,0,2,1>
00041 { typedef vcg::Point2<typename XprType::Scalar> type; };
00042 }
00043
00044 namespace vcg {
00045
00053 template <class _Scalar> class Point2 : public Eigen::Matrix<_Scalar,2,1>
00054 {
00055
00056
00057
00058
00059 public:
00060 typedef Eigen::Matrix<_Scalar,2,1> Type;
00061
00062
00063
00064 private:
00065 typedef Eigen::Matrix<_Scalar,2,1> _Base;
00066 public:
00067 using _Base::coeff;
00068 using _Base::coeffRef;
00069 using _Base::setZero;
00070 using _Base::data;
00071 using _Base::V;
00072
00073 _EIGEN_GENERIC_PUBLIC_INTERFACE(Point2,_Base);
00074 VCG_EIGEN_INHERIT_ASSIGNMENT_OPERATORS(Point2)
00075
00076
00077 inline Point2 () { }
00079 inline Point2 ( const Scalar nx, const Scalar ny ) : Base(nx,ny) {}
00081 inline Point2(Point2 const & p) : Base(p) {}
00082 template<typename OtherDerived>
00083 inline Point2(const Eigen::MatrixBase<OtherDerived>& other) : Base(other) {}
00084
00086
00087 inline Scalar operator ^ ( Point2 const & p ) const
00088 {
00089 return data()[0]*p.data()[1] - data()[1]*p.data()[0];
00090 }
00091
00093 inline Scalar Angle() const
00094 {
00095 return math::Atan2(data()[1],data()[0]);
00096 }
00098 inline Point2 & Cartesian2Polar()
00099 {
00100 Scalar t = Angle();
00101 data()[0] = this->norm();
00102 data()[1] = t;
00103 return *this;
00104 }
00106 inline Point2 & Polar2Cartesian()
00107 {
00108 Scalar l = data()[0];
00109 data()[0] = (Scalar)(l*math::Cos(data()[1]));
00110 data()[1] = (Scalar)(l*math::Sin(data()[1]));
00111 return *this;
00112 }
00114 inline Point2 & Rotate( const Scalar rad )
00115 {
00116 Scalar t = data()[0];
00117 Scalar s = math::Sin(rad);
00118 Scalar c = math::Cos(rad);
00119
00120 data()[0] = data()[0]*c - data()[1]*s;
00121 data()[1] = t *s + data()[1]*c;
00122
00123 return *this;
00124 }
00125 };
00126
00127 typedef Point2<short> Point2s;
00128 typedef Point2<int> Point2i;
00129 typedef Point2<float> Point2f;
00130 typedef Point2<double> Point2d;
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00142 }
00143 #endif
00144
00145 #endif