Android : How to draw smooth circular maize using midpoint circle algorithm for jbox2d polygon shape

on Saturday, October 25, 2014


I need to draw a cirlce of polygon objects for my android application.For this I am trying to implement "MID POINT CIRCLE ALGORITHM" but what i am getting looks horrible enter image description here


how can I make it more smoother? here is my code:



final int centerX=0; final int centerY=5; final int radius=5;
int d = 3 - (2 * radius);
int x = 0;
int y = radius;

do {
drawCircle(centerX + x, centerY + y);
drawCircle(centerX + x, centerY - y);
drawCircle(centerX - x, centerY + y);
drawCircle(centerX - x, centerY - y);
drawCircle(centerX + y, centerY + x);
drawCircle(centerX + y, centerY - x);
drawCircle(centerX - y, centerY + x);
drawCircle(centerX - y, centerY - x);

if (d < 0) {
d += 2 * x + 1;
} else {
d += 2 * (x - y) + 1;
y--;
}
x++;
} while (x <= y);
// drawCircle function

public void drawCircle( final int x,final int y){

PolygonShape shape = new PolygonShape();
shape.setAsBox(0.5f, 0.5f);

BodyDef bd = new BodyDef();
bd.position.set(x,y);

Body ground = getWorld().createBody(bd);
ground.createFixture(shape, 0.0f);

}

0 comments:

Post a Comment