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 467505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T23:35:17+00:00 2026-05-12T23:35:17+00:00

i need to draw a polygon of n sides given 2 points (the center

  • 0

i need to draw a polygon of “n” sides given 2 points (the center and 1 of his vertex) just that i suck in math. I have been reading a lot and all this is what i have been able to figure it (i dont know if it is correct):

Ok, i take the distance between the 2 points (radius) with the theorem of Pythagoras:

sqrt(pow(abs(x - xc), 2) + pow(abs(y - yc), 2));

And the angle between this 2 points with atan2, like this:

atan2(abs(y - yc), abs(x - xc));

Where xc, yc is the center point and x, y is the only vertex know.

And with that data i do:

void polygon(int xc, int yc, int radius, double angle, int sides)
{
    int i;
    double ang = 360/sides; //Every vertex is about "ang" degrees from each other
    radian = 180/M_PI;
    int points_x[7]; //Here i store the calculated vertexs
    int points_y[7]; //Here i store the calculated vertexs

    /*Here i calculate the vertexs of the polygon*/
    for(i=0; i<sides; i++)
    {
        points_x[i] = xc + ceil(radius * cos(angle/radian));
        points_y[i] = yc + ceil(radius * sin(angle/radian));
        angle = angle+ang;
    }

    /*Here i draw the polygon with the know vertexs just calculated*/
    for(i=0; i<sides-1; i++)
        line(points_x[i], points_y[i], points_x[i+1], points_y[i+1]);
    line(points_y[i], points_x[i], points_x[0], points_y[0]);
}

The problem is that the program dont work correctly because it draw the lines not like a polygon.

Someone how know enough of math to give a hand? im working in this graphics primitives with C and turbo C.


Edit: i dont want to fill the polygon, just draw it.

  • 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-12T23:35:17+00:00Added an answer on May 12, 2026 at 11:35 pm

    Consider what 360/sides actually returns if sides is not a factor of 360 (this is integer division – see what 360/7 actually returns).

    There is no need to use degrees at all – use 2*Math_PI/(double)nsides and work throughout in radians.

    also you can omit the final line by using the modulus function (module nsides).

    If you have more than 7 sides you will not be able to store all the points. You don’t need to store all the points if you are simply drawing the polygon rather than storing it – just the last point and the current one.

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

Sidebar

Related Questions

I need to draw a Polygon from several points (I have their latitude, longitude).
I have polygon given by the points sequence I need to apply follow rules:
I have a concave polygon I need to draw in OpenGL. The polygon is
I need to draw a polygon in Pascal(dev-pascal) which has semicircles at its sides.
I need to draw on a TPanel, ideally directly so I don't have another
I need to draw a .png image on an UIView. I have no clue
Right now I am trying to draw a polygon in Cocos2d, but I need
We are building a web app library which need draw some polyline/polygon/circle/rectange. Also we
I need a diagonal polygon color fill that resizes based on screen width /
I need to draw polygon using mouse and mark a particular area on Google

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.