homog2d library
Functions
showcase14.cpp File Reference

Generates moving polygons and shows their intersection points. More...

#include "../../homog2d.hpp"
Include dependency graph for showcase14.cpp:

Functions

int main (int, const char **)
 

Detailed Description

Generates moving polygons and shows their intersection points.

Function Documentation

◆ main()

int main ( int  ,
const char **   
)
12 {
13  auto nbim = 20; // nb images
14 
15  std::vector<Point2d> vpts1{
16  { 0, 0 },
17  { 140,30 },
18  { 80,110},
19  { 60,50 },
20  { 20,80 }
21  };
22  std::vector<Point2d> vpts2{
23  { 0, 0 },
24  { 65, -30 },
25  { 78, -10 },
26  { 120,-20 },
27  { 140,30 },
28  { 80,110},
29  { 60,50 },
30  { 20,80 }
31  };
32 
33  CPolyline poly1( vpts1 );
34  CPolyline poly2( vpts2 );
35  poly2.translate(120,80);
36  poly1.translate(20,30);
37  poly2.rotate( Rotate::CCW, Point2d(150, 150) );
38 
39  auto extr_col = img::DrawParams().setColor(100,250,0).setPointStyle( img::PtStyle::Dot );
40  for( int i=0; i<nbim; i++ )
41  {
42  img::Image<img::SvgImage> im( 360, 280 );
43 // poly1.draw( im, img::DrawParams().setColor(250,128,0) );
44 // poly2.draw( im, img::DrawParams().setColor(250,0,128) );
45  im.draw( poly1, img::DrawParams().setColor(250,128,0) );
46  im.draw( poly2, img::DrawParams().setColor(250,0,128) );
47 
48  auto res = poly1.intersects(poly2); // intersection points
49  auto ptInt = res.get();
50  for( const auto& pt: ptInt )
51  pt.draw( im, img::DrawParams().setColor(0,250,0).setPointStyle( img::PtStyle::Dot ) );
52 
53  auto closest = getClosestPoints( poly1, poly2 );
54  auto ppts = closest.getPoints();
55  draw( im, ppts );
56  Segment( closest.getPoints() ).draw( im, img::DrawParams().setColor(0,0,250) );
57  getBB( poly1, poly2 ).draw( im, img::DrawParams().setColor(220,200,220) );
58  im.drawText( "MinDist=" + std::to_string( closest.getMinDist() ), Point2d(20,20) );
59 
60  poly1.translate( 10, 7 );
61  poly2.translate( -7, -7 );
62 
63  auto c2 = poly2.centroid();
64  poly2 = Homogr().addTranslation( -c2.getX(), -c2.getY() ).addRotation(10.*M_PI/180.).addTranslation( c2.getX(), c2.getY() ) * poly2;
65 
66  std::ostringstream oss;
67  oss << "showcase14_" << std::setfill('0') << std::setw(2) << i << ".svg";
68  im.write( oss.str() );
69  }
70 }
Homogr_< HOMOG2D_INUMTYPE > Homogr
Default homography (3x3 matrix) type, uses double as numerical type.
Definition: homog2d.hpp:12382
void draw(Data &data)
Definition: precision_test_opencv.cpp:184
Segment_< HOMOG2D_INUMTYPE > Segment
Default segment type.
Definition: homog2d.hpp:12388
#define M_PI
Definition: homog2d.hpp:235
void draw(img::Image< img::SvgImage > &im, img::DrawParams dp=img::DrawParams()) const
SVG draw function.
Definition: homog2d.hpp:4414
Draw parameters, independent of back-end library.
Definition: homog2d.hpp:514
Point2d_< HOMOG2D_INUMTYPE > Point2d
Default point type, uses double as numerical type.
Definition: homog2d.hpp:12379
priv::ClosestPoints< PLT1, FPT1, PLT2, FPT2 > getClosestPoints(const base::PolylineBase< PLT1, FPT1 > &poly1, const base::PolylineBase< PLT2, FPT2 > &poly2)
Computes the closest points between two polylines (types can be different)
Definition: homog2d.hpp:10591
img::Image< img::SvgImage > im(300, 400)
DrawParams & setPointStyle(PtStyle ps)
Definition: homog2d.hpp:585
Opaque data structure, will hold the image type, depending on back-end library. This type is the one ...
Definition: homog2d.hpp:712
FRect_< HOMOG2D_INUMTYPE > getBB(const T &t)
Return Bounding Box of primitive or container holding primitives (free function)
Definition: homog2d.hpp:10312
DrawParams & setColor(uint8_t r, uint8_t g, uint8_t b)
Definition: homog2d.hpp:605
Polyline, will be instanciated either as OPolyline_ (open polyline) or CPolyline_.
Definition: homog2d.hpp:364
Point2d pt
Definition: homog2d_test.cpp:4034
Here is the call graph for this function: