Skip to content

Commit

Permalink
update RCP
Browse files Browse the repository at this point in the history
  • Loading branch information
skramm committed Dec 18, 2023
1 parent ddaf418 commit 56e7f88
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/homog2d_manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@ see [the related constructor](#build_RCP).
This function returns a `std::pair` holding two numerical values:
the distance between two consecutive points as "first", and "second" the radius of the inscribed circle.
The minimum value for `dist` is 3, will throw if less.
The minimum value for `nb` is 3, the function will throw if less.
![polyline_rcp_1](img/polyline_rcp_1.svg)
Expand Down
12 changes: 12 additions & 0 deletions homog2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2452,6 +2452,9 @@ class FRect_: public detail::Common<FPT>
template<typename TX, typename TY>
void moveTo( TX x, TY y )
{
HOMOG2D_CHECK_IS_NUMBER( TX );
HOMOG2D_CHECK_IS_NUMBER( TY );

auto s = size();
_ptR1.set(x,y);
_ptR2.set( _ptR1.getX() + s.first, _ptR1.getY() + s.second );
Expand Down Expand Up @@ -3007,6 +3010,8 @@ Use of Sfinae so it can be selected only for arithmetic types
template<typename TX, typename TY>
void moveTo( TX x, TY y )
{
HOMOG2D_CHECK_IS_NUMBER( TX );
HOMOG2D_CHECK_IS_NUMBER( TY );
set( Point2d_<FPT>(x, y) );
}

Expand Down Expand Up @@ -4664,6 +4669,8 @@ class Segment_: public detail::Common<FPT>
template<typename TX, typename TY>
void moveTo( TX x, TY y )
{
HOMOG2D_CHECK_IS_NUMBER( TX );
HOMOG2D_CHECK_IS_NUMBER( TY );
moveTo( Point2d_<FPT>(x,y) );
}

Expand Down Expand Up @@ -5898,10 +5905,15 @@ at 180° of the previous one.
template<typename TX,typename TY>
void moveTo( TX x, TY y )
{
HOMOG2D_CHECK_IS_NUMBER( TX );
HOMOG2D_CHECK_IS_NUMBER( TY );
moveTo( Point2d_<FPT>(x,y) );
}

/// Move Polyline to new origin, given by \c new_org
/**
\warning The polygon origin is NOT its center but the point No 0!
*/
template<typename T1>
void moveTo( const Point2d_<T1>& new_org )
{
Expand Down
5 changes: 4 additions & 1 deletion misc/demo_opencv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1687,7 +1687,10 @@ void action_RCP( void* param )
CPolyline pol;
auto values = pol.set( data.radius, data.nbPts );
std::cout << " -Building Regular Convex Polygon with " << data.nbPts << " points\n";
pol.translate(data.trans_x,data.trans_y);

// pol.translate(data.trans_x,data.trans_y);
pol.moveTo( Point2d(data.trans_x,data.trans_y) );

pol.draw( data.img );
drawText( data.img, "NbPts=" +std::to_string(data.nbPts), Point2d(20,40) );
drawText( data.img, "segment dist=" +std::to_string(values.first), Point2d(20,60) );
Expand Down
23 changes: 19 additions & 4 deletions misc/figures_src/src/polyline_rcp_1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@

int main()
{
img::Image<img::SvgImage> im( 450,200 );
img::Image<img::SvgImage> im( 550,200 );

Point2d p1(100,100);
Point2d p2(280,100 );
Point2d p2(360,100 );
p1.draw( im );
p2.draw( im );
CPolyline pol1, pol2;
auto values1 = pol1.set(80,5);
auto values2 = pol2.set(100,7);
pol1.moveTo( p1 );
pol2.moveTo( p2 );
pol1.translate( p1.getX(), p1.getY() );
pol2.translate( p2.getX(), p2.getY() );

Circle c1( p1, values1.second );
Circle c2( p2, values2.second );

Expand All @@ -26,5 +27,19 @@ int main()
pol1.draw( im, img::DrawParams().setColor(250,0,0) );
pol2.draw( im, img::DrawParams().setColor(250,0,0) );

auto s1 = pol1.getSegs().at(0);
auto s2 = pol2.getSegs().at(0);

auto spara1 = s1.getParallelSegs(25).second;
auto spara2 = s2.getParallelSegs(25).second;
spara1.draw( im );
spara2.draw( im );
std::ostringstream oss1, oss2;
oss1 << values1.first;
oss2 << values2.first;

drawText( im, oss1.str(), spara1.getCenter() );
drawText( im, oss2.str(), spara2.getCenter() );

im.write( "polyline_rcp_1.svg" );
}

0 comments on commit 56e7f88

Please sign in to comment.