-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathshowcase7.cpp
73 lines (59 loc) · 1.4 KB
/
showcase7.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
\file
\brief shows isInside circles vs polyline
*/
//#define HOMOG2D_DEBUGMODE
#include "../../homog2d.hpp"
using namespace h2d;
int main( int, const char** )
{
auto n = 25; // nb images
Circle cir( 3. );
std::vector<Point2d> vpts{
{ -1.0, 1.0 },
{ -1.2, -0.7 },
{ 1.8, -0.5 },
{ 1.6, 1.1 },
{ 0.5, 0.8 }
};
CPolyline pl( vpts );
auto Hdraw = Homogr().addTranslation(7,6).addScale(15);
img::Image<img::SvgImage> im( 300, 200 );
auto col_outside = img::DrawParams().setColor(50,20,200);
auto col_inside = img::DrawParams().setColor(200,20,20).setThickness(2);
auto coeff_x = 1.12;
auto coeff_y = 1.16;
Homogr H1 = Homogr().addScale( coeff_x, coeff_y );
Homogr H2 = Homogr().addScale( 1./coeff_x, 1./coeff_y );
for( int i=0; i<n; i++ )
{
im.clear();
auto pl2 = Hdraw * pl;
auto cir2 = Hdraw * cir;
auto col_c = col_outside;
if( cir.isInside( pl ) )
col_c = col_inside;
auto col_p = col_outside;
if( pl.isInside( cir ) )
col_p = col_inside;
pl2.draw( im, col_p );
cir2.draw( im, col_c );
auto inter = cir.intersects(pl);
if( inter() )
{
auto inter_pts = inter.get();
for( const auto& pt: inter.get() )
{
auto pt2 = Hdraw * pt;
pt2.draw( im );
}
}
if( i<n/2 )
pl = H1*pl;
else
pl = H2*pl;
std::ostringstream oss;
oss << "showcase7_" << std::setfill('0') << std::setw(2) <<i << ".svg";
im.write( oss.str() );
}
}