Drawing an honeycomb with as3

Posted by vitto on Stack Overflow See other posts from Stack Overflow or by vitto
Published on 2010-05-22T10:29:58Z Indexed on 2010/05/22 10:40 UTC
Read the original article Hit count: 279

Filed under:
|

Hi, I'm trying to create an honeycomb with as3 but I have some problem on cells positioning.

I've already created the cells (not with code) and for cycled them to a funcion and send to it the parameters which what I thought was need (the honeycomb cell is allready on a sprite container in the center of the stage).

to see the structure of the cycle and which parameters passes, please see the example below, the only thing i calculate in placeCell is the angle which I should obtain directly inside tha called function

alt text

Note: the angle is reversed but it isn't important, and the color are useful in example only for visually divide cases.

My for cycle calls placeCell and passes cell, current_case, counter (index) and the honeycomb cell_lv (cell level).

I thought it was what i needed but I'm not skilled in geometry and trigonometry, so I don't know how to position cells correctly:

function placeCell (cell:Sprite, current_case:int, counter:int, cell_lv:int):void {
    var margin:int = 2;

    var angle:Number = (360 / (cell_lv * 6)) * (current_case + counter);
    var radius:Number = (cell.width + margin) * cell_lv;

    cell.x = radius * Math.cos (angle);
    cell.y = radius * Math.sin (angle);

    trace ("LV " + cell_lv + "  current_case " + current_case + "   counter " + counter + " angle " + angle + " radius " + radius)

}

how can I do to solve it?

© Stack Overflow or respective owner

Related posts about actionscript-3

Related posts about geometry