URL: https://www.overclockers.at/coding-stuff/solved_raycasting_punkt_in_polygon_ergebnis_stimmt_221626/page_1 - zur Vollversion wechseln!
ich hab ein problem, und zwar möcht ich herausfinden ob ein punkt in einem polygon liegt dazu hab ich die methode hier verwendet: http://alienryderflex.com/polygon/
nun stimmt aber einfach oft das ergebnis einfach ned und ich komm einfach nicht drauf was ich falsch mache...
(unten der erste wert ist XY vom punkt und die nächsten 2 sind die 2 eckpunkte vom quadrat)
ergebnis ist true, ok soweit
... jetzt ist das ergebnis plötzlich false, obwohl der punkt drin liegt (kann man auch an den koordinaten ablesen
so schaut meine funktion jetzt aus (eigentlich anders aber ich habs der einfachheit halber mal meine geändert und fast genauso formatiert wie im beispiel um zu schauen ob ich einen fehler find, find ihn aber nicht )
Code:boolean inside(float testX, float testY) { boolean oddResult = false; int j = polyX.length-1; for( int i=0; i < polyX.length; i++) { if( polyY[i] < testY && polyY[j] >= testY || polyY[j] < testY && polyY[i] >= testY ) { if( polyX[i] + (testY - polyY[i]) / (polyY[j]-polyY[i]) * (polyX[j] - polyX[i]) < testX ) { oddResult = !oddResult; } } } return oddResult; }
Code:boolean inside(float testX, float testY) { boolean oddResult = false; int j = polyX.length-1; for( int i=0; i < polyX.length; i++) { if( polyY[i] < testY && polyY[j] >= testY || polyY[j] < testY && polyY[i] >= testY ) { if( polyX[i] + (testY - polyY[i]) / (polyY[j]-polyY[i]) * (polyX[j] - polyX[i]) < testX ) { oddResult = !oddResult; } } j = i; } return oddResult; }
lol :-)
http://en.wikipedia.org/wiki/Rubber_duck_debugging
overclockers.at v4.thecommunity
© all rights reserved by overclockers.at 2000-2025