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

  • SEARCH
  • Home
  • 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 6058719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:37:48+00:00 2026-05-23T08:37:48+00:00

I have some properties defined by the user, and then I want use them

  • 0

I have some properties defined by the user, and then I want use them to automatically generate a regular polygon. The properties are centre x, centre y, radius and number of vertices. I would like to know how to calculate the x and y coordinates of all vertices of a regular polygon. I’ve already tried to do as Calculate coordinates of a regular polygon's vertices discussion. But it always gives me thw wrong coordinates. My current code is as follows (C++):

#define DOUBLE(a) ((a)*(a))

…

if(radius <= 0 || vertices < 3)
  return NULL;

Polygon* poly = new Polygon;

double angle = DOUBLE(M_PI) / vertices;

for(long i = 0; i < vertices; i++)
{
  double a = (angle * i);

  poly->add(centerX + radius * cos(a), centerY + radius * sin(a));
}

return poly;
  • 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-05-23T08:37:49+00:00Added an answer on May 23, 2026 at 8:37 am

    There’s an error in your angle calculation.

    The angle between each vertex should be 2 * M_PI / vertices.

    Obviously your macro:

    #define DOUBLE(a) ((a)*(a))
    

    is incorrect.

    However in C++ you really shouldn’t use macros for such trivial operations anyway – it should at the very most be an inline function, or just the direct formula given above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have some element in my container and want to save all properties of
I have an interface like this: public interface IUser{ //some properties here T ToDerived(User
My current setup : I have an entity object with some properties, among them
I have a recursively defined user control that needs the following properties: there are
I have a few DependencyProperties defined in some custom user controls. I'd like for
The Application class in System.Windows.Forms have a some properties that can be quite useful.
I have some logic that depends upon two properties being set, as it executes
I have some very simple XML: <properties> <property> <name>BobFish</name> <explaination>Bob is a fish.</explaination> </property>
I have an object config which has some properties. I can export this ok,
I have implemented an application for modify the xml layout with some properties. I

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.