Is this a sensible way to do it?

Fragment of a discussion from User talk:Cbrowne
Jump to navigation Jump to search
Edited by another user.
Last edit: 17:57, 11 October 2011

Wow, that one is excellent. I'm not quite grokking it yet, but experiments have shown that it performs much smoother than my previous implementation.

Now to get the gun to point in the right direction.

I've implemented a function, "turnGunTo" which (in theory) turns the gun to a given (absolute) heading. I'm struggling to get it to work, though, as the gun just appears to spin continuously. Here's my function:

	public void turnGunTo(double newHeading) {
		double oldHeading = getGunHeadingRadians(); 
		// use of normalRelativeAngle means we don't have to decide left or right

And, for reference, the calculateTurnAmount() function:

	public double calculateTurnAmount(double newHeading,double oldHeading) {
		// turn amount is a segment of a full circle, calculated by (circle - leftAngle) + rightAngle;
		return (FULL_CIRCLE - Math.max(newHeading, oldHeading)) + Math.min(newHeading, oldHeading);

What am I doing wrong? Also, is the method abstraction superfluous? It seems so, but in some ways it makes it a little bit more semantically-obvious what I'm trying to achieve.

Cbrowne17:55, 11 October 2011