how can i draw a circle divided to many sectors ,each secteor area deppends on specific angle for each sector in the circle ,

thanx for help ,
regards

## All 9 Replies

you will have to use some sort of gui libraries and/or compiler. Depends on your operating system.

If you don't know it already, start a course in trigonometry. It might help.

trig will help for the math part but is useless for the gui part. What you want is an easy way to draw pie charts in C or C++. Read some of these google links.

(x - a) ^ 2 + (y - b) ^ 2 = r ^ 2
Where a and b are the center coordinates, and r is the radius. This should help you solve for x, and y, given one or the other.
This is useful for plotting, but sin, cos, and tan will be useful for splitting it up into sectors. (Remember a full rotation is 2 * pi)

Trig isn't all that difficult.. I put together a small example of how to create a bitmap, draw a circle and a sector in it (with a 50 deg angle). I tried to keep the code as short as possible, but it is still over 200 lines, so I will post the important part and attach the whole code. It should draw on the bitmap and save it as circle.bmp in the project folder.

``````const double PI = 3.141592;
const double deg_to_rad = PI / 180;
const double rad_to_deg = 180 / PI;

void draw_sector(Bitmap &bmp, int deg_startangle, int deg_finangle, int radius) {
int centre_x = bmp.width / 2;
int centre_y = bmp.height / 2;

// Start Angle
bmp.line(
centre_x, // x1
centre_y, // y1
);

// Finish Angle
bmp.line(
centre_x, // x1
centre_y, // y1
);
}

int main() {
// Create Bitmap object
Bitmap bmp(500, 500);

// Centre of bitmap
int centre_x = bmp.width / 2;
int centre_y = bmp.height / 2;

int x1, y1, x2, y2; // Temp location variables

// Set default old coordient
y2 = centre_y;

cout << "Drawing circle with a sector of 50 deg\n";

// Draw a circle ( loop from 0 to (2*PI) ) with 1deg accuracy
for (double i = 0; i < (360 * deg_to_rad); i += (1 * deg_to_rad)) {
// Get next coordients to draw a line to
x1 = int(centre_x + cos(i) * 150);
y1 = int(centre_y + sin(i) * 150);

// Draw line from old coordients to new ones
bmp.line(x1, y1, x2, y2);

// Set old coordients
x2 = x1;
y2 = y1;
}

// Draw a sector between angle 0 and 50

bmp.save("circle.bmp");

cout << "\nDone!\n\nPress <ENTER> to continue..\n";

cin.ignore();
return 0;
}``````

And here are some short tutorials to help :)
Trigonometry

Hope all this helps :]

commented: Whoo! You're a genius kid XP +4

thanks all my freinds , you response is realy helpful....

Best regards
extrov

Hello is spelled without the w. =)
Also, trigonometry is the way to go. You can probably find a tutorial or something: www.google.com/search?q=Trigonometry+Tutorial

My fingers get out of sync with my brain so often, every time I try to demo "Hello world" it comes out "Hellow orld"

Or maybe it's just an emphatic variant of Hello?

My fingers get out of sync with my brain so often, every time I try to demo "Hello world" it comes out "Hellow orld"

Or maybe it's just an emphatic variant of Hello?

yes thats it , u gut it ...
my be sometimes when people miss something ,anothers add it ...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.