get Polygon Vertexes - Android java.lang

Android examples for java.lang:Math Geometry

Description

get Polygon Vertexes

Demo Code


//package com.java2s;

public class Main {
    /**//from w  w w. j a  v  a2s .co  m
     * @param cx
     * @param cy
     * @param radius
     * @param sides
     * @return obtiene los v?rtices de un pol?gono regular
     */
    public static float[][] getPolyconVertexes(float cx, float cy,
            float radius, int sides) {

        float[][] vertexes = new float[sides][2];
        int i = 0;

        do {
            float x = cx + radius
                    * (float) Math.cos(2.0 * Math.PI * i / sides);
            float y = cy + radius
                    * (float) Math.sin(2.0 * Math.PI * i / sides);

            vertexes[i][0] = x;
            vertexes[i][1] = y;
            i++;

        } while (i < sides);

        return vertexes;
    }
}

Related Tutorials