Wall Distance

From Robowiki
Revision as of 09:51, 20 January 2026 by DamijForgotHisAccountCreds (talk | contribs) (can't seem to stop poking at it, removed bot name)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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