Question: bool Polygon::contains(Point point) { int i, j, c = 0; for (i = 0, j = vertexCount-1; i < vertexCount; j = i++) { if

bool Polygon::contains(Point point)

{

int i, j, c = 0;

for (i = 0, j = vertexCount-1; i < vertexCount; j = i++)

{

if ( ((points[i].getY()>point.getY()) != (points[j].getY()>point.getY())) &&

(point.getX() < (points[j].getX()-points[i].getX()) * (point.getY()-points[i].getY()) / (points[j].getY()-points[i].getY()) + points[i].getX()) )

{

c = !c;

}

else

c = c;

}

return c;

}

all the other tests (!(1,1),(1,1),!(-1,-1),(1,1)) work except the one that was with (0,2) what could I be missing? any assistance would be great thanks!

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!