I'm trying to code a 5 point star function in C++, I am using the WinBGIm library. I am getting stuck on the trigonometry of the triangle. My function is given the centre x and y coordinates and the radius of the star all as integers.
This is what I have s ofar.
Code:
// The main purpose of this program is to draw 7 stars
// Using the WinBGIm graphics library.
// Directives:
#include <graphics.h>
#include <cstdlib>
#include <cmath>
using namespace std;
//Constants
const int S = 700;
// First Star(test)
const int STARX1 = 0.2*S;
const int STARY1 = 0.5*S;
const int RADIUS1 = 0.07*S;
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Function Prototypes.
// This is a list of all the functions that I plan to write because the
// author of the graphics library did not have them!
void star (int cx, int cy, int radius);
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Main program
int main()
{
initwindow(S,S,"Dipper!");
star(STARX1, STARY1, RADIUS1);
delay(200000);
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// This function draws a star. The center of the star is at (cx, cy),
// and the radius of the star is given by radius.
void star(int cx, int cy, int radius)
{
int farrightxcoord = cx + radius*cos(M_PI/10);
int farrightycoord = cy - radius*sin(M_PI/10);
int bottomrightxcoord = cx+ radius*cos(5*M_PI/10);
int bottomrightycoord= cy - radius*sin(5*M_PI/10);
int bottomleftxcoord = cx+radius*cos(9*M_PI/10);
int bottomleftycoord=cx-radius*sin(9*M_PI/10);
int farleftxcoord = cx + radius*cos(13*M_PI/10);
int farleftycoord = cy - radius*sin(13*M_PI/10);
int topxcoord = cx + radius*cos(17*M_PI/10);
int topycoord = cy - radius*sin(17*M_PI/10);
line(farrightxcoord,farrightycoord, farleftxcoord, farleftycoord);
line(farrightxcoord,farrightycoord, bottomleftxcoord,bottomleftycoord);
line(bottomleftxcoord,bottomleftycoord,topxcoord,topycoord);
line(topxcoord,topycoord,bottomrightxcoord,bottomrightycoord);
line(bottomrightxcoord,bottomrightycoord, farleftxcoord, farleftycoord);
As you can see the star function is where I am really confused, can someone help me with this?