Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

876876 Posts in 32834 Topics- by 24278 Members - Latest Member: aetherX

May 18, 2013, 12:32:37 AM
TIGSource ForumsCommunityGet TogethersDrawing 1/4 of a circle
Pages: [1]
Print
Author Topic: Drawing 1/4 of a circle  (Read 538 times)
kamac
Level 10
*****


Notorious posts editor


View Profile WWW Email
« on: January 27, 2012, 09:39:20 AM »

Hey. I am trying to draw a rounded rect. so i have to drive four halfs of circle, in correct corners.

First, i am drawing a basic circle using
r*cos(n) for x
r*sin(n) for y

So, i have a loop. ( C++ )

Code:
for(float n=0.0;n<3.0;n += 0.1)
{
sf::Shape p = sf::Shape::Line(
sf::Vector2f(dist*cos(n)+x+dist-1,dist*sin(n)+y+dist-1),
sf::Vector2f(dist*cos(n+1)+x+dist-1,dist*sin(n+1)+y+dist-1),1.0f,
sf::Color(0,0,0));
App.Draw(p);
}

Where dist = 10.

Any ideas how to draw only 1/4 of the circle? (Currently the upper-left one)
Logged

Claw
Level 4
****



View Profile WWW Email
« Reply #1 on: January 27, 2012, 09:43:32 AM »

You're currently looping from 0.0 to 3.0, if that renders a full circle try going from 0.0 to 0.75 for a quarter.
Logged

kamac
Level 10
*****


Notorious posts editor


View Profile WWW Email
« Reply #2 on: January 27, 2012, 09:46:00 AM »

Ouch. By the way, sorry wrong category. Should be technical.

Quote
You're currently looping from 0.0 to 3.0, if that renders a full circle try going from 0.0 to 0.75 for a quarter.

I'll try.
Logged

Claw
Level 4
****



View Profile WWW Email
« Reply #3 on: January 27, 2012, 09:48:32 AM »

I'm sort of guessing, I didn't run through the maths but generally a circle will be drawn in segments, so as long as those segments are being created in sequence (ie. not skipping and coming back to them later or something weird) then it should be that simple Grin
Logged

Noah!
Level 6
*



View Profile WWW
« Reply #4 on: January 27, 2012, 09:59:18 AM »

Aw man, and I was so excited to meet up with you guys and draw circle segments...

Anyway, the way I would do it is by making a polygon and filling in the points from there, like this: (apologies, untested code!)

Code:
sf::Shape p;
p.AddPoint(x,y); // center point is important!
for (float n = 0.0; n < 1.57; n += 0.1) {
p.AddPoint(x + (cos(n) * dist), y + (sin(n) * dist));
}
App.Draw(p);

This way, you can build the shape once, and then all subsequent actions can be performed on just the one object!
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic