Consider the following code:
#include <string>
class Intersect {
public:
static bool overlap(std::string polygonA, std::string polygonB);
};
bool Intersect::overlap(std::string polygonA, std::string polygonB) {
// implementation goes here
return true;
}
Implement the method Intersect::overlap, so that it returns true, if an overlap exists with the two convex polygons polygonA and polygonB provided as input and it returns false if no such overlap exists. It should work with non convex polygons also.
everything should be implemented inside a static method. Check if points are in clockwise are not.
ex:
input format: std::string polygonAlpha = "0 0,0 1,2 0,0 0";
std::string polygonBravo = "1 0,1 1,3 0,1 0";
std::string polygonCharlie = "2 2,2 3,4 2,2 2";
What I have tried:
std::vector<int> vect;
std::vector<int> vect1;
std::stringstream ss(polygonA);
std::stringstream ss1(polygonB);
for (int i; ss >> i;) {
vect.push_back(i);
if (ss.peek() == ',')
ss.ignore();
}
for (int i; ss1 >> i;) {
vect1.push_back(i);
if (ss.peek() == ',')
ss.ignore();
}
int signedarea=0;
signedarea=signedarea+ (vect[0]*vect[3]-vect[1]*vect[2])+vect[2]*vect[5]-vect[3]*vect[4]+vect[4]*vect[7]-vect[5]*vect[6];
std::cout << signedarea << std::endl;