Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8083115
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:21:22+00:00 2026-06-05T17:21:22+00:00

I have adapted some code from a great article I found about circle drawing

  • 0

I have adapted some code from a great article I found about circle drawing by Mukund Sivaraman to execute a passed function for each point on a given circle:

template<class Function>
static void For_each_point_on_circle(Image *image, int radius, Function function)
{
    int x, y;
    int l;
    l = (int) radius * cos (M_PI / 4);
    for (x = 0; x <= l; x++)
    {
        y = (int) sqrt ((double) (radius * radius) - (x * x));
        function(image, x, y);
        function(image, x, -y);
        function(image, -x, y);
        function(image, -x, -y);
        function(image, y, x);
        function(image, y, -x);
        function(image, -y, x);
        function(image, -y, -x);
  }
}

However, what I really need is to calculate the points around the circle in sequence, so the calls to function(image, x, y) will go from 0 to 360 degrees in sequence rather than skipping about, which is acceptable when drawing the circle.

I could calculate all the points and sort them, but I was hoping someone may know a way to do it properly, maybe using multiple loops each calculating a segment each?

Many thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T17:21:24+00:00Added an answer on June 5, 2026 at 5:21 pm

    something like this should do it:

    template<class Function>
    static void For_each_point_on_circle(Image *image, int radius, Function function)
    {
        int x, y;
        int l;
        l = (int) radius * cos (M_PI / 4);
        for (x = -l; x < l; x++)
        {
            y = (int) sqrt ((double) (radius * radius) - (x * x));
            function(image, x, y);
        }
        for (x = -l; x < l; x++)
        {
            y = (int) sqrt ((double) (radius * radius) - (x * x));
            function(image, y, -x);
        }
        for (x = -l; x < l; x++)
        {
            y = (int) sqrt ((double) (radius * radius) - (x * x));
            function(image, -x, -y);
        }
        for (x = -l; x < l; x++)
        {
            y = (int) sqrt ((double) (radius * radius) - (x * x));
            function(image, -y, x);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code adapted from a previous question/answer: var str = $('title').text();
I have a simple java project (adapted from the example here ), which is
Adapted from the nested form Railscast , I have: In my model class Post
In some old Java code, I found a class that contains a lot of
I'm in the process of porting some code from Objective C to C++. I'm
I am taking some code that I have used for a nested listview before
I have some code in my ApplicationEvent.vb to handle command line params and then
I have some designer generated code that I am using to query a dataset.
Text and sample code adapted from http://www.webdeveloper.com/forum/archive/index.php/t-65078.html , may not reflect actual question: I
I have some problems with my custom adapter for a ListView . I'm unsure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.