public static Offset GetOffset( long speedInMillipixelsPerMillisecond, long movementDirectionInMillidegrees, long elapsedMillisecondsPerIteration) { if (speedInMillipixelsPerMillisecond < 0) { throw new Exception(); } if (speedInMillipixelsPerMillisecond == 0) { return new Offset { DeltaXInMillipixels = 0, DeltaYInMillipixels = 0 } } ; movementDirectionInMillidegrees = DTMath.NormalizeAngleInMillidegrees(movementDirectionInMillidegrees); long numberOfMillipixels = speedInMillipixelsPerMillisecond * elapsedMillisecondsPerIteration; return(new Offset { DeltaXInMillipixels = numberOfMillipixels * DTMath.SineScaled(milliDegrees: movementDirectionInMillidegrees) / 1000L, DeltaYInMillipixels = numberOfMillipixels * DTMath.CosineScaled(milliDegrees: movementDirectionInMillidegrees) / 1000L }); }
// 0 degrees is going straight up // 90 degrees is going right // 180 degrees is straight down // 270 degrees is going left // (Note function returns value in millidegrees) public static long?GetMovementDirectionInMillidegrees(long currentX, long currentY, long desiredX, long desiredY) { long deltaX = desiredX - currentX; long deltaY = desiredY - currentY; if (deltaX == 0 && deltaY == 0) { return(null); } long angleInMillidegrees = DTMath.ArcTangentScaled(x: deltaX, y: deltaY); long angle2 = -angleInMillidegrees + 90L * 1000L; return(DTMath.NormalizeAngleInMillidegrees(angle2)); }