Мне нужно найти ординаты точек, которые находятся на фигуре и в форме, и я увидел веб-формулу, чтобы получить их, но мои результаты в данный момент неправы.Рекомендации по редактированию метода
bool Shape::inPoly(int x,int y)
{
xArray[0] = 1;
xArray[1] = 1;
xArray[2] = 3;
xArray[3] = 3;
yArray[0] = 1;
yArray[1] = 3;
yArray[2] = 3;
yArray[3] = 1;
int i;
int j;
int nvert = 4;
int c = 0;
int testval = 0;
for (i = 0, j = nvert - 1; i < nvert; j = i++)
{
if ((yArray[i]>y) != (yArray[j]>y))
{
testval = (xArray[j]-xArray[i]) * (y-yArray[i])/(yArray[j]-yArray[i]) + xArray[i];
}
if (x == testval)
{
// point is on boundary!
c = 0; // set indicator to "not inside"
break; // abort loop
}
if (x < testval)
{
// intersection found
c = !c;
}
}
return c;
}
void Shape::pointInShape()
{
std::cout << "results" << std::endl;
std::cout << inPoly(1,1) << std::endl;
std::cout << inPoly(1,2) << std::endl;
std::cout << inPoly(1,3) << std::endl;
std::cout << inPoly(2,1) << std::endl;
std::cout << inPoly(2,2) << std::endl;
std::cout << inPoly(2,3) << std::endl;
std::cout << inPoly(3,1) << std::endl;
std::cout << inPoly(3,2) << std::endl;
std::cout << inPoly(3,3) << std::endl;
}
Вот мои результаты
results 0 <-- (means that 1,1 is not within polygon) 0 <-- (means that 1,2 is not within polygon) 0 <-- (means that 1,3 is not within polygon) 1 <-- (2,1 is is within polygon)// this should be 0 1 <-- (2,2 is is within polygon) 0 <-- (means that 2,3 is is not within polygon) 0 <-- (means that 3,1 is is not within polygon) 0 <-- (means that 3,2 is is not within polygon) 0 <-- (means that 3,3 is is not within polygon)
Я не могу показаться, чтобы выяснить, как настроить формулу, нужно несколько советов по этому
последний «)» не имеет себе равных «(» – Amit
синтаксической ошибки ... – ErasmoOliveira
Вы уверены, что вы проверили это? Я полагаю, дважды щелкнув на сообщение об ошибке и увидеть, где он указывает. – Javia1492