Original Post
If I pass in amount=25 rotation=90 to the method below, the result is a weird -1.5308086E-15 instead of (what I thought) should be 0. Why is this?
The same code for the x axis works as expected, with the result being 0:
Cheers.
/**
* @param amount The distance to move. Will always be positive.
* @param rotation
* @return The distance resulting from moving amount in the direction of rotation.
*/
public static float getYDistanceMovedBy(float amount, float rotation) {
return Math.abs(amount) * (float) -Math.cos(Math.toRadians(rotation));
}public void testGetYDistanceMovedBy2() {
float amount = 25.0f;
float rotation = 90.0f;
float distance = Geometry.getYDistanceMovedBy(amount, rotation);
assertEquals(0.0f, distance);
}The same code for the x axis works as expected, with the result being 0:
/**
* @param amount The distance to move. Will always be positive.
* @param rotation
* @return The distance resulting from moving amount in the direction of rotation.
*/
public static float getXDistanceMovedBy(float amount, float rotation) {
return Math.abs(amount) * (float) Math.sin(Math.toRadians(rotation));
}public void testGetXDistanceMovedBy2() {
float amount = 25.0f;
float rotation = 0.0f;
float distance = Geometry.getXDistanceMovedBy(amount, rotation);
assertEquals(0.0f, distance);
}Cheers.