Difference between revisions of "Wall Distance"
Jump to navigation
Jump to search
m (Tidy up a bit) |
m (replaced some) |
||
| Line 2: | Line 2: | ||
<syntaxhighlight> | <syntaxhighlight> | ||
| − | + | static int isPositive(final double value) { | |
| − | + | return value < 0 ? 0 : 1; | |
| − | + | } | |
| − | + | ||
| − | + | static double calcWallSpace(final Point eCenter, double eGoing) { | |
| − | |||
eGoing = Utils.normalRelativeAngle(eGoing); | eGoing = Utils.normalRelativeAngle(eGoing); | ||
| − | final | + | final int isRight = isPositive(eGoing); |
| − | + | final int isDown = isPositive(Math.abs(eGoing) - Math.PI*0.5d); | |
| − | + | final double wallDistLat = ((eCenter.getX() * ((isRight+1)&1)) + (FiveHunna.PLAY_WIDTH-eCenter.getX()) * isRight) / Math.abs(Math.cos(Math.PI*0.5d-eGoing)); | |
| − | + | final double wallDistVirt = ((eCenter.getY() * (isDown) + (FiveHunna.PLAY_HEIGHT-eCenter.getY()) * ((isDown+1)&1))) / Math.abs(Math.cos(eGoing)); | |
| − | + | return Math.min(wallDistLat, wallDistVirt) / FiveHunna.MAX_DIST; | |
} | } | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| − | + | In a typical 800x600 arena, using this should result in a measurement in Kilo-pixels. | |
| − | In a typical 800x600 arena, using | ||
| − | + | Cosine similarity between heading and 'direct to the wall vector.' | |
| − | |||
| − | |||
Can be pretty useful for various reasons. | Can be pretty useful for various reasons. | ||
| − | |||
-- Damij | -- Damij | ||
Revision as of 10:28, 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)) + (FiveHunna.PLAY_WIDTH-eCenter.getX()) * isRight) / Math.abs(Math.cos(Math.PI*0.5d-eGoing));
final double wallDistVirt = ((eCenter.getY() * (isDown) + (FiveHunna.PLAY_HEIGHT-eCenter.getY()) * ((isDown+1)&1))) / Math.abs(Math.cos(eGoing));
return Math.min(wallDistLat, wallDistVirt) / FiveHunna.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