# Help on code (drawing circle mathematically)

Hi
I’m failing to see why the default circle and the circle mathematically drawn doesn’t match.
Any help is appreciated.

Code below:

``````size(400,400);
int cx = 200, cy = 200, cr = 100, xdis, ydis;
stroke(255,0,0);
circle(200,200,100);

stroke(0,255,0);
for(int i = cx-cr; i<=cx+cr; i = i + 1)
{
for(int j = cy-cr; j<= cy+cr; j = j+ 1)
{
xdis = i - cx;
ydis = j - cy;
if ((sq(xdis) + sq(ydis)) < sq(cr)) // points are plotted only if x^2 + y^2 < r^2
{
point(i,j);
}
}
}
``````
1 Like

If you are referring to the difference in size, it is because the circle() function takes in a diameter and not a radius, so it was being drawn twice as small as the second one. To make it the same size use `circle(200, 200, 200)`.

2 Likes

OOpssss … Thank you ever so much.
It would have been useful it this was clear in the function’s documentation. ellipse and circle documentation talk about

and the third and fourth parameters set the shape’s width and height. The origin may be changed with the ellipseMode() function.

https://processing.org/reference/ellipseMode_.html

The default mode is ellipseMode(CENTER) , which interprets the first two parameters of ellipse() as the shape’s center point, while the third and fourth parameters are its width and height.
ellipseMode(RADIUS) also uses the first two parameters of ellipse() as the shape’s center point, but uses the third and fourth parameters to specify half of the shapes’s width and height.

1 Like