Skip to content Skip to sidebar Skip to footer

Calculate Points Around A Circle In Android

I'm programming a game in android where an enemy ship needs to fire in a star pattern around itself. Basically, for any X number of shots I set the enemy ship to fire, I want it to

Solution 1:

The trigonometric functions in most programming languages, Java included, measure the argument in radians, not degrees. There is a helper function to do the conversion, so everywhere you call sin or cos you can add a call to toRadians:

Math.cos(Math.toRadians(dAngle))

Solution 2:

First error:

dAngle = 360/iShotNumber;

You want a double as a result of the division, then you cannot simply do an integer division. You should do:

dAngle = 360.0/(double)iShotNumber;

I'm checking to find other errors.

Post a Comment for "Calculate Points Around A Circle In Android"