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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:37:49+00:00 2026-05-28T00:37:49+00:00

I am working with SVG graphics to draw Pie Graphs. I am given the

  • 0

I am working with SVG graphics to draw Pie Graphs. I am given the degrees a pie graph should be – eg 277 degrees – and the diameter – eg 200px – and I need to draw a circle of 277 degrees.

With SVG graphics I need to resolve that 277 degrees to a point where that circle will end.

I am not the greatest with math, so I have come up with a formula/javascript function that will allow me to take a degrees value & come up with a x,y point of where the circle will end.

Will my Javascript function(at the bottom) correctly resolve a degrees to a correct point? Can you help me develop my algorithm to obtain the coordinate from a degree value? Or maybe there is an existing algorithm I can use that I dont know about?

My Algorithm: (Which I require help with)
So the values I am given are: Circle Diameter: 200px, Circle size: 277 degrees.

  • I require the point at which 277 ends when rotating around the point 0,0.
  • 277 ends in the 1st quadrant which means I need to use sin (is that correct?)
  • So the values I know now of the triangle are: the hypotenuse=100px(the radius), the angle=7 degrees(277-270).

    sin(7) = o/100;
    0.1219 = o/100;
    o = 12.2;

  • Therefore the y point is 12.2 (for my sakes 0,0 is the top left corner so its really midY-x = 100-12.2 = 87.8; (is that correct?)

  • Now to determine the x pos, I use cos(is that correct?).

    cos(7) = a/100;
    a = 99.25;

  • Therefore the x point is 99.25 or 100-99.25=0.75;

So the x,y coordinate of 277 degrees is 0.75,87.8. Is that correct?

So in code this algorithm would be:

function resolveToPoint( deg, diameter )
{
    if ( deg <= 0)
        return 0;

    var x     = 0;
    var y     = 0;
    var angle = 0;
    var rad   = diameter/2;
    var midX  = rad;
    var midY  = rad;

    if (deg <= 90)
        angle = 90 - deg;
    else if (deg <= 180)
        angle = deg - 90;
    else if (deg <= 270)
        angle = deg - 180;
    else if (deg <= 360)
        angle = deg - 270;

    // Q: Will I ALWAYS use cos to determine the x & sin for the x NO MATTER what quadrant the angle is in??
    x = Math.cos(angle) * rad;
    y = Math.sin(angle) * rad;

    if (deg <= 90)
    {
        x = midX + x;
        y = midY - y;
    }
    else if (deg <= 180)
    {
        x = midX + x;
        y = midY + y;
    }
    else if (deg <= 270)
    {
        x = midX - x;
        y = midY + y;
    }
    else if (deg <= 360)
    {
        x = midX - x;
        y = midY - y;
    }

    return {mX: x, mY: y};
}

Then I’ll use it in a SVG like so:

function outputPiegraph( point, rad, diameter )
{  
    var svg = '<svg width="%spx" height=""%spx" id='pie' style="background-color: green;">
    <path d="M%spx,%spx L%spx, %spx A%spx,"%spx 1 1,1 %spx,%spx z"
     fill="red" stroke="blue" stroke-width="2" />"
</svg>';


    return sprintf(svg, diameter, diameter, point.mX, point.mY, rad, rad, rad, diameter);
}
  • 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-28T00:37:49+00:00Added an answer on May 28, 2026 at 12:37 am

    This is simple conversion from polar to Cartesian coordinates:

    function resolveToPoint(deg, diameter) {
        var rad = Math.PI * deg / 180;
        var r = diameter / 2;
        return {mX: r * Math.cos(rad), mY: r * Math.sin(rad)};
    }
    

    http://en.wikipedia.org/wiki/Polar_coordinates#Converting_between_polar_and_Cartesian_coordinates

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

Sidebar

Related Questions

I'm working on some ECMAScript/JavaScript for an SVG file and need to get the
I am currently working with svg and its dom manipulation... Are there any WYSIWYG
I am working with svg and its dom manipulation. I want to create a
I'm working on drawing an SVG grid using Javascript. I've managed to get the
I'm working on an interactive interface using SVG and JavaScript/jQuery, and I'm trying to
I'm working on a report that includes an embedded svg diagram. The diagram is
Working on a simple poker script in PHP and need a way to determine
I'm working on a project that uses SVG with Raphael.js . One component is
Is there any working module to convert a SVG image into a pixel format
I'm working with jQuery to modify some svg files data on the fly... one

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.