Skip to content

Commit

Permalink
added showcase20 (not in doc yet)
Browse files Browse the repository at this point in the history
  • Loading branch information
skramm committed May 16, 2024
1 parent 2b14215 commit 2209a84
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
1 change: 1 addition & 0 deletions misc/homog2d.cbp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@
<Unit filename="showcase/showcase17.cpp" />
<Unit filename="showcase/showcase18.cpp" />
<Unit filename="showcase/showcase19.cpp" />
<Unit filename="showcase/showcase20.cpp" />
<Unit filename="showcase/showcase2a.cpp" />
<Unit filename="showcase/showcase2b.cpp" />
<Unit filename="showcase/showcase3.cpp" />
Expand Down
75 changes: 75 additions & 0 deletions misc/showcase/showcase20.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
\file
\brief Three circles, one fixed and two whose center rotates. Fixed radius.
It shows the line formed by intersections points. The three lines intersect at same point (black).
*/
#define HOMOG2D_USE_OPENCV
//#define HOMOG2D_DEBUGMODE
#include "../../homog2d.hpp"

using namespace h2d;
using namespace h2d::img;

int main( int, const char** )
{
auto nbim = 30; // nb images

CPolyline pol( 50, 3 );
pol.translate( 140, 160 );
auto pts = pol.getPts();
auto pt0 = pts[0];
auto pt1 = pts[1];
auto pt2 = pts[2];

auto k1=5;
auto k2=12;

auto rad0 = 60;
auto rad1=70, rad2=80;
uint8_t m = 220;
for( int i=0; i<nbim; i++ )
{
auto angle = i * 2. * M_PI / nbim;
auto xr1 = std::cos(angle)*k1;
auto yr1 = std::sin(angle)*k1;
auto xr2 = std::cos(angle)*k2;
auto yr2 = std::sin(angle)*k2;

Point2d p2( pt2 );
Point2d p1( pt1 );
p1.translate( xr1, -yr1 );
p2.translate( xr2, yr2 );
Circle cir1( p1, rad1 );
Circle cir2( p2, rad2 );
Circle cir0( pt0, rad0 );

Image<cv::Mat> im( 300, 300 );
cir0.draw( im, DrawParams().setColor(0,250,0) );
cir1.draw( im, DrawParams().setColor(250,0,0) );
cir2.draw( im, DrawParams().setColor(0,0,250) );
#if 0
p1.draw( im, DrawParams().setColor(250,0,0) );
p2.draw( im, DrawParams().setColor(0,0,250) );
pt0.draw( im, DrawParams().setColor(0,250,0) );
#endif
auto int01 = cir0.intersects(cir1).get();
auto int02 = cir0.intersects(cir2).get();
auto int12 = cir2.intersects(cir1).get();

auto gray = DrawParams().setColor(200,200,200);
auto li01 = int01[0] * int01[1];
auto li02 = int02[0] * int02[1];
auto li12 = int12[0] * int12[1];
li01.draw( im, DrawParams().setColor(m,m,0) );
li02.draw( im, DrawParams().setColor(0,m,m) );
li12.draw( im, DrawParams().setColor(m,0,m) );

auto centerpt = li01 * li02;
centerpt.draw( im, DrawParams().setColor(0,0,0).setPointStyle(PtStyle::Dot) );

std::ostringstream oss;
oss << "showcase20_" << std::setfill('0') << std::setw(2) <<i << ".png";
im.write( oss.str() );
}
}

0 comments on commit 2209a84

Please sign in to comment.