Wall Distance
Revision as of 09:28, 20 January 2026 by DamijForgotHisAccountCreds (talk | contribs) (replaced some)
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