Difference between revisions of "Wall Distance"
Jump to navigation
Jump to search
m (replaced some) |
m (can't seem to stop poking at it, removed bot name) |
||
| Line 10: | Line 10: | ||
final int isRight = isPositive(eGoing); | final int isRight = isPositive(eGoing); | ||
final int isDown = isPositive(Math.abs(eGoing) - Math.PI*0.5d); | final int isDown = isPositive(Math.abs(eGoing) - Math.PI*0.5d); | ||
| − | final double wallDistLat = ((eCenter.getX() * ((isRight+1)&1)) + ( | + | final double wallDistLat = ((eCenter.getX() * ((isRight+1)&1)) + (PLAY_WIDTH-eCenter.getX()) * isRight) / Math.abs(Math.cos(Math.PI*0.5d-eGoing)); |
| − | final double wallDistVirt = ((eCenter.getY() * (isDown) + ( | + | final double wallDistVirt = ((eCenter.getY() * (isDown) + (PLAY_HEIGHT-eCenter.getY()) * ((isDown+1)&1))) / Math.abs(Math.cos(eGoing)); |
| − | return Math.min(wallDistLat, wallDistVirt) / | + | return Math.min(wallDistLat, wallDistVirt) / MAX_DIST; |
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Latest revision as of 09:51, 20 January 2026
An example to calculate wall distance in percentage of width or height, whichever is closer and 'more pertinent'
static int isPositive(final double value) {
return value < 0 ? 0 : 1;
}
static double calcWallSpace(final Point eCenter, double eGoing) {
eGoing = Utils.normalRelativeAngle(eGoing);
final int isRight = isPositive(eGoing);
final int isDown = isPositive(Math.abs(eGoing) - Math.PI*0.5d);
final double wallDistLat = ((eCenter.getX() * ((isRight+1)&1)) + (PLAY_WIDTH-eCenter.getX()) * isRight) / Math.abs(Math.cos(Math.PI*0.5d-eGoing));
final double wallDistVirt = ((eCenter.getY() * (isDown) + (PLAY_HEIGHT-eCenter.getY()) * ((isDown+1)&1))) / Math.abs(Math.cos(eGoing));
return Math.min(wallDistLat, wallDistVirt) / MAX_DIST;
}In a typical 800x600 arena, using this should result in a measurement in Kilo-pixels.
Cosine similarity between heading and 'direct to the wall vector.'
Can be pretty useful for various reasons.
-- Damij