From 2a298cf611612bcdb22edf3e49644339ea483599 Mon Sep 17 00:00:00 2001 From: Andrei <andrei.herdt@inrialpes.fr> Date: Fri, 7 Jan 2011 03:14:32 +0100 Subject: [PATCH] Add structure to handle 2-dimensional convex hulls - Add type convex_hull_t - Add method resize(int&) - Add method reset(void) - Add method set(double*,double*) - Add method rotate(double&) --- src/privatepgtypes.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++ src/privatepgtypes.h | 33 ++++++++++++++++++++++++++- 2 files changed, 83 insertions(+), 1 deletion(-) diff --git a/src/privatepgtypes.cpp b/src/privatepgtypes.cpp index 032facfe..7b49a313 100644 --- a/src/privatepgtypes.cpp +++ b/src/privatepgtypes.cpp @@ -127,4 +127,55 @@ namespace PatternGeneratorJRL reset(); } + + void + convex_hull_t::rotate(const double & angle) + { + + double c_a = cos(angle); + double s_a = sin(angle); + + for( int j=0;j<X.size();j++ ) + { + X[j] = ( X[j]*c_a - Y[j]*s_a ); + Y[j] = ( X[j]*s_a + Y[j]*c_a ); + } + + } + + convex_hull_s::convex_hull_s(const int & size) + { + resize(size); + reset(); + } + + convex_hull_s::convex_hull_s() + { + + } + + void + convex_hull_t::reset() + { + X.clear(); + Y.clear(); + } + + void + convex_hull_t::resize(const int & size) + { + X.resize(size); + Y.resize(size); + } + + void + convex_hull_t::set(const double * arrayX, const double * arrayY) + { + for(int i=0;i<X.size();i++) + { + X[i] = arrayX[i]; + Y[i] = arrayY[i]; + } + } + } diff --git a/src/privatepgtypes.h b/src/privatepgtypes.h index 15cf2104..de92018d 100644 --- a/src/privatepgtypes.h +++ b/src/privatepgtypes.h @@ -149,12 +149,43 @@ namespace PatternGeneratorJRL /// \brief Linear constraints struct linear_constraint_s { - ublas::compressed_vector<double> A; + boost_ublas::compressed_vector<double> A; double b; }; typedef struct linear_constraint_s linear_constraint_t; + /// \brief Set of 2-dimensional point + struct convex_hull_s + { + + MAL_VECTOR(X,double); + MAL_VECTOR(Y,double); + + /// \brief Rotate the points around the origin by angle + /// + /// \param[in] angle + void rotate(const double & angle); + + /// \brief Resize members to the desired number of points + /// + /// \param[in] size + void resize(const int & size); + + /// \brief Set the point values + /// + /// \param[in] X + /// \param[in] Y + void set(const double * arrayX, const double * arrayY); + + /// \brief Set all points to zero + void reset(); + + convex_hull_s(const int & size); + convex_hull_s(); + + }; + typedef struct convex_hull_s convex_hull_t; } #endif /* _PATTERN_GENERATOR_INTERNAL_PRIVATE_H_ */ -- GitLab