<p>You can use the sine and cosine functions to do this. Normally they start on the x axis and rotate counter-clockwise. The start point can be found by calculating:</p>

<pre><code>startX = x + cos(startRadians) * radius;
startY = y + sin(startRadians) * radius;
</code></pre>

<p>Likewise the ending coordinates are:</p>

<pre><code>endX = x + cos(endRadians) * radius;
endY = y + sin(endRadians) * radius;
</code></pre>

<p>Note that <code>sin()</code> and <code>cos()</code> take their parameters in radians. Given that <code>stangle</code> and <code>endangle</code> are integers, I'm guessing they're probably in degrees so you'll need to convert them by doing something like:</p>

<pre><code>double startRadians = (double)stangle * M_PI / 180.0;
</code></pre>

<p>etc.</p>

<p>If you want to draw the entire pie wedge, you'll need to iterate from the start angle to the end angle and calculate every <code>n</code> degrees along the curve.</p>

CC BY-SA 4.0
2019-10-01T05:01:29.780Z
Please look into the codes i have written so far(updated my question). I know its not perfect,i am very new to coding. Specially usage of ` graphics.h `
Netranjit Borgohain
CC BY-SA 4.0
2019-10-01T16:00:37.593Z
It looks almost right. I think you only want one loop that goes from `startAngle` to `endAngle`. And of course you'll need to actually draw some lines between the points you generate.
user1118321
CC BY-SA 4.0
2019-10-01T16:08:18.507Z
Can you help me with that,please! I am clueless after this.
Netranjit Borgohain
CC BY-SA 4.0
2019-10-02T01:08:52.397Z
This site isn't for how to write code. I suggest you post it to the main StackOverflow site to get help with that.
user1118321
CC BY-SA 4.0
2019-09-27T04:19:41.063Z
2019-09-27T04:19:41.063Z
user1118321
<p>As we know in C/C++ there is "graphics.h" header file with the help of which we can do graphics programs in C. 
There is a function <strong>pieslice</strong> in that header file,its syntax is:</p>

<pre><code>#include &lt;graphics.h&gt;

void pieslice(int x, int y, int stangle, int endangle, int radius);
</code></pre>

<p>[x,y are the center of the circle,stangle and endangle are the starting and end angles respectively]</p>

<p>Can we make a pieslice in C/C++ without using this in-built function.Please help. Tried making it with the help of the lines and arc function of the 
<code>graphics.h</code> but i am still not able to figure out how to connect the lines with the arc. 
Thank You in advance.</p>

<p>My code so far:</p>

<pre><code>#include&lt;stdio.h&gt;
#include&lt;graphics.h&gt;
#include&lt;math.h&gt;

int main()
{
    int gd=DETECT,gm;
    initgraph(&amp;gd,&amp;gm,NULL);
    int xc,yc,r,st_angle,ed_angle,StartX,StartY;
    printf("Enter the centers of pieslice:\n");
    scanf("%d %d",&amp;xc,&amp;yc);
    printf("Enter the radius:\n");
    scanf("%d",&amp;r);
    printf("Enter the starting angle:\n");
    scanf("%d",&amp;st_angle);
    printf("Enter the end angle:\n");
    scanf("%d",&amp;ed_angle);

    double startRadians = (double)st_angle * M_PI /180.0;
    double endRadians = (double)ed_angle * M_PI /180.0;

    for(int k=0; k&lt;startRadians;k++)
    {   
        startX = xc+ cos(startRadians) * r;
        startY = yc+ sin(startRadians) * r;
    }
    for(int l=o; l&lt;endRadians; l++)
    {
        endX = xc+ cos(endRadians) * r;
        endY = yc+ sin(endRadians) * r;
    }


</code></pre>

CC BY-SA 4.0
2019-09-29T07:19:16.317Z
What do you already know about the pieslice shape that would help you draw it? Do you want to write a function that takes the same arguments as the existing pieslice function? To help people know what you're looking for, could you edit to explain what you are starting with? Do you want to construct this shape using arcs and straight lines provided by `graphics.h` or do you want to draw it one pixel at a time?
trichoplax is on Codidact now
CC BY-SA 4.0
2019-09-29T07:30:03.863Z
I want to draw it using arcs and line provided by ` graphics.h ` .
Netranjit Borgohain
CC BY-SA 4.0
2019-10-31T15:41:17.850Z
FYI: `graphics.h` is not a part of C++. It's some external library.
Nicol Bolas
<c++><vector-graphics>
Program to make "Pieslice" without using library function?
Netranjit Borgohain
# Program to make "Pieslice" without using library function?

(Asked by: username_0 on 2019-09-26)

As we know in C/C++ there is "graphics.h" header file with the help of which we can do graphics programs in C.
There is a function **pieslice** in that header file,its syntax is:

```
#include <graphics.h>

void pieslice(int x, int y, int stangle, int endangle, int radius);

```

[x,y are the center of the circle,stangle and endangle are the starting and end angles respectively]

Can we make a pieslice in C/C++ without using this in-built function.Please help. Tried making it with the help of the lines and arc function of the
`graphics.h` but i am still not able to figure out how to connect the lines with the arc.
Thank You in advance.

My code so far:

```
#include<stdio.h>
#include<graphics.h>
#include<math.h>

int main()
{
    int gd=DETECT,gm;
    initgraph(&gd,&gm,NULL);
    int xc,yc,r,st_angle,ed_angle,StartX,StartY;
    printf("Enter the centers of pieslice:\n");
    scanf("%d %d",&xc,&yc);
    printf("Enter the radius:\n");
    scanf("%d",&r);
    printf("Enter the starting angle:\n");
    scanf("%d",&st_angle);
    printf("Enter the end angle:\n");
    scanf("%d",&ed_angle);

    double startRadians = (double)st_angle * M_PI /180.0;
    double endRadians = (double)ed_angle * M_PI /180.0;

    for(int k=0; k<startRadians;k++)
    {   
        startX = xc+ cos(startRadians) * r;
        startY = yc+ sin(startRadians) * r;
    }
    for(int l=o; l<endRadians; l++)
    {
        endX = xc+ cos(endRadians) * r;
        endY = yc+ sin(endRadians) * r;
    }

```

**Tags:** c++, vector-graphics

> **Comments:**
> **username_1**: What do you already know about the pieslice shape that would help you draw it? Do you want to write a function that takes the same arguments as the existing pieslice function? To help people know what you're looking for, could you edit to explain what you are starting with? Do you want to construct this shape using arcs and straight lines provided by `graphics.h` or do you want to draw it one pixel at a time?  
> **username_0**: I want to draw it using arcs and line provided by ` graphics.h ` .  
> **username_2**: FYI: `graphics.h` is not a part of C++. It's some external library.  

---

## 1 answers

### Answer by username_3 on 2019-09-27. Score: 1

You can use the sine and cosine functions to do this. Normally they start on the x axis and rotate counter-clockwise. The start point can be found by calculating:

```
startX = x + cos(startRadians) * radius;
startY = y + sin(startRadians) * radius;

```

Likewise the ending coordinates are:

```
endX = x + cos(endRadians) * radius;
endY = y + sin(endRadians) * radius;

```

Note that `sin()` and `cos()` take their parameters in radians. Given that `stangle` and `endangle` are integers, I'm guessing they're probably in degrees so you'll need to convert them by doing something like:

```
double startRadians = (double)stangle * M_PI / 180.0;

```

etc.

If you want to draw the entire pie wedge, you'll need to iterate from the start angle to the end angle and calculate every `n` degrees along the curve.

> **Comments:**
> **username_0**: Please look into the codes i have written so far(updated my question). I know its not perfect,i am very new to coding. Specially usage of ` graphics.h `  
> **username_3**: It looks almost right. I think you only want one loop that goes from `startAngle` to `endAngle`. And of course you'll need to actually draw some lines between the points you generate.  
> **username_0**: Can you help me with that,please! I am clueless after this.  
> **username_3**: This site isn't for how to write code. I suggest you post it to the main StackOverflow site to get help with that.  

---

