# Help on code (drawing circle mathematically)

**URL:** <https://discourse.processing.org/t/help-on-code-drawing-circle-mathematically/13759>\
**Category:** Beginners\
**Created:** [September 2, 2019, 11:02am UTC](https://discourse.processing.org/t/help-on-code-drawing-circle-mathematically/13759 "2019-09-02T11:02:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sbiju72](https://avatars.discourse-cdn.com/v4/letter/s/9f8e36/32.png) [@sbiju72](https://discourse.processing.org/u/sbiju72)\
**Post date:** [September 2, 2019, 11:02am UTC](https://discourse.processing.org/t/help-on-code-drawing-circle-mathematically/13759/1 "2019-09-02T11:02:01Z")

</div>

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

Code below:

```auto
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);
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![TheWizardBear](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/thewizardbear/32/3552_2.png) [@TheWizardBear](https://discourse.processing.org/u/TheWizardBear)\
**Post date:** [September 2, 2019, 11:11am UTC](https://discourse.processing.org/t/help-on-code-drawing-circle-mathematically/13759/2 "2019-09-02T11:11:13Z")

</div>

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)`.

---

<div class="post-metadata">

**Author:** ![sbiju72](https://avatars.discourse-cdn.com/v4/letter/s/9f8e36/32.png) [@sbiju72](https://discourse.processing.org/u/sbiju72)\
**Post date:** [September 2, 2019, 11:42am UTC](https://discourse.processing.org/t/help-on-code-drawing-circle-mathematically/13759/3 "2019-09-02T11:42:18Z")

</div>

OOpssss … Thank you ever so much.  
It would have been useful it this was clear in the function’s documentation. ☹

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [September 2, 2019, 2:06pm UTC](https://discourse.processing.org/t/help-on-code-drawing-circle-mathematically/13759/4 "2019-09-02T14:06:09Z")

</div>

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.

> **[ellipseMode() / Reference](https://processing.org/reference/ellipseMode_.html)**
>
> Modifies the location from which ellipses are drawn by changing the way in which parameters given to ellipse() are interpreted. The default mode is ellipseMode(CENTER), which …

> 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.
