Ask Your Question

Revision history [back]

try :

Point p1,p2,p3,p4;
.....
vector<Point> ctr;

ctr.push_back(p1);
ctr.push_back(p2);
ctr.push_back(p3);
ctr.push_back(p4);

bool inside = pointPolygonTest  ( ctr,Point2f(254,30.1),false);

try :

Point p1,p2,p3,p4;
.....
vector<Point> ctr;

ctr.push_back(p1);
ctr.push_back(p2);
ctr.push_back(p3);
ctr.push_back(p4);
bool

double inside = pointPolygonTest ( ctr,Point2f(254,30.1),false); ctr,Point2f(254,30.1),false);

try :

Point p1,p2,p3,p4;
.....
vector<Point> ctr;

ctr.push_back(p1);
ctr.push_back(p2);
ctr.push_back(p3);
ctr.push_back(p4);

double inside = pointPolygonTest ( ctr,Point2f(254,30.1),false);

ctr,Point2f(254,30.1),false);

try :

Point p1,p2,p3,p4;
.....
vector<Point> ctr;

ctr.push_back(p1);
ctr.push_back(p2);
ctr.push_back(p3);
ctr.push_back(p4);

double inside;
inside = pointPolygonTest pointPolygonTest(ctr, Point2f(254, 30.1), false);
if (inside < 0)
 ( ctr,Point2f(254,30.1),false);
 cout << "Outside\n";
else if (inside > 0)
    cout << "inside\n";
else
    cout << "contour points\n";
inside= pointPolygonTest(ctr, Point2f(50, 50), false);
if (inside < 0)
    cout << "Outside\n";
else if (inside > 0)
    cout << "inside\n";
else
    cout << "contour points\n";
inside = pointPolygonTest(ctr, Point2f(10, 50), false);
if (inside < 0)
    cout << "Outside\n";
else if (inside > 0)
    cout << "inside\n";
else
    cout << "contour points\n";

Results :

Outside inside contour points

try :

double inside;
inside = pointPolygonTest(ctr, Point2f(254, 30.1), false);
if (inside < 0)
    cout << "Outside\n";
else if (inside > 0)
    cout << "inside\n";
else
    cout << "contour points\n";
inside= pointPolygonTest(ctr, Point2f(50, 50), false);
if (inside < 0)
    cout << "Outside\n";
else if (inside > 0)
    cout << "inside\n";
else
    cout << "contour points\n";
inside = pointPolygonTest(ctr, Point2f(10, 50), false);
if (inside < 0)
    cout << "Outside\n";
else if (inside > 0)
    cout << "inside\n";
else
    cout << "contour points\n";

Results :

Outside Outside

inside

contour points

try :

Point p1(10,10),p4(10,100), p3(100,100), p2(100,10) ;
    vector<Point> ctr;

ctr.push_back(p1);
ctr.push_back(p4);
ctr.push_back(p3);
ctr.push_back(p2);
double inside;
inside = pointPolygonTest(ctr, Point2f(254, 30.1), false);
if (inside < 0)
    cout << "Outside\n";
else if (inside > 0)
    cout << "inside\n";
else
    cout << "contour points\n";
inside= pointPolygonTest(ctr, Point2f(50, 50), false);
if (inside < 0)
    cout << "Outside\n";
else if (inside > 0)
    cout << "inside\n";
else
    cout << "contour points\n";
inside = pointPolygonTest(ctr, Point2f(10, 50), false);
if (inside < 0)
    cout << "Outside\n";
else if (inside > 0)
    cout << "inside\n";
else
    cout << "contour points\n";

Results :

Outside

inside

contour points