get Circle Position - Java java.lang

Java examples for java.lang:Math Geometry Shape

Description

get Circle Position

Demo Code



public class Main{
    static public final float degreesToRadians = PI / 180f;
    static public float getCirclePosition(float centerX, float centerY,
            float radius, float angleBegin, float angleEnd, int index,
            int totalNumber, boolean returnX) {
        float angle = angleBegin + (angleEnd - angleBegin)
                * (index / (float) (totalNumber - 1));
        if (returnX)
            return centerX + radius
                    * (float) Math.cos(angle * degreesToRadians);
        else//from   ww w . j  a  v a 2 s .  co m
            return centerY + radius
                    * (float) Math.sin(angle * degreesToRadians);
    }
}

Related Tutorials