Bruce Wayne - 1 month ago 10

Java Question

I've checked all the other questions related to this and they haven't helped me. I'm not trying to make a duplicate question. I need to create a circle in java using lines (9 to be exact for that im working on right now).

Formula

`int points = 9;`

int r = 100;

float originX = width/2+r;

float originY = height/2;

float angle1;

float angle2;

void setup() {

size(500, 500);

}

void draw() {

for(int i=0; i < points;++i) {

angle1 = i * 2 * PI / points;

angle2 = i * 2 * PI / points;

line(originX + r * cos( angle1), originY + r * sin(angle1),

originX + r * cos( angle2), originY + r * sin(angle2));

}

}

That is the formula and I know the circumfrence of a circle is 2pi radians so I was using (2*pi)/9 as my theta for both.

My current code is located above

Can someone tell me how to get this working?

Answer

Currently, you are drawing the spokes of a wheel, rather that the circumference. To do this you want to draw a line from the i-th point to the (i+1)-th point

```
for(int i=0; i < points;++i) {
angle1 = i * 2 * Pi / points;
angle2 = (i+1) * 2 * Pi / points;
line(OriginX + r * cos( angle1), OriginY + r * sin(angle1),
OriginX + r * cos( angle2), OriginY + r * sin(angle2)) ;
}
```