The principles of drawing and storing a circle?

Hi all, I’m back briefly!

An idea popped into my head recently that would make a great excuse for a learning project.

I’m interested in playing with circles, Cartesian and Polar coordinates and transforms etc. and I know that JUCE has tools for drawing and storing ellipses etc. But I want to do my own manipulations and for that I need to know how to store a circle in memory.

The math for a rectangle is pretty straight forward, and I can imagine that the math for a circle is way more involved (and maybe depends on what I eventually intend to do with the circle)

I can’t even think what to put into google to begin, so if anyone understands my problem, or has a a suggestion for a good starting point, your input would be greatly appreciated.

Thank you.

How do you mean ‘store’? I mean, at a minimum you store a rectangle with two values, width and height. And along those same lines you store a circle with a single value, usually radius. For both of those instance, if you want to add a location, for the rectangle you add the x/y coordinates for the upper right corner, and for the circle you add the x/y coordinates for the center. But, from your question I think you need more than just that information

Drawing is achieved by using radians and cos/sin to derive the x/y coordinates. A circle is 2pi radians, so, iterate from 0 to 2pi, at whatever value you choose for granularity, and then x=center_x + (radius * cos(radian)), y=center_y + (radius * sin(radian)). Hope that helps get you started. Oh, and here is a video showing this in action:
Drawing a circle with sin() & cos()

1 Like


What is your plan?

  • Doing mathematic calculations?
  • Rasterise manually?

And here is, how it is done in JUCE’s source code:

Thanks so much @cpr and @daniel

So basically, I’m thinking about building some kind of tool that works with circles but lets you modify them as you wish. So i need to have some kind of way to describe each circle, not just use a circle drawing function.

The FFT spectrum of your waveform is very much related to the circles you want to draw. See this youtube video about harmonics:

I guess storing your circles could be realized by storing the FFT coefficients of your waveform, or actually encode it into circular harmonics (which should be very much related to the FFT)

Great! I now have a ton of material to consume and ponder over, i already have a good idea how to store the data (hint custom data structure).

Wow. For the first time i feel like I’m really doing programming! And it’s a little bit ironic because i still havent even written my first line of code yet!

The best way to learn programming, is to do programming. And not just some tutorials, but having an idea for a project, and trying to realize it. On the way, you’ll encounter so many problems which you will solve, and in that progress, you learn more than any basic c++ course can teach you. Have fun! :slight_smile:

1 Like

Yes and no. Sure, getting hands dirty is a great way of learning, but actually programming is exactly what @arifd is doing, thinking about a problem and ways to solve it.

I am with Edsger Dijkstra here: “If you don’t know, what your program should do, don’t start writing it” :wink:


True! Let me rephrase that :slight_smile: The best way to learn programming, is finding a problem you are eager to solve, figuring out an algorithm which does that, and implement said algorithm. This should give you enough motivation to not stop when it’s getting hard :slight_smile:

@arifd looking forward to seeing how your project evolves, sounds like a very cool tool!

1 Like