• Advertisement
Sign in to follow this  

Drawing Circle!!

This topic is 2915 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want to draw a circle with a certain radius and also centered where its positioned. I am drawing my circle as really small dots but I cant seem to add the above to my liking.
float angle = 0;
for (int i = 1; i < = 360; i++)
{
                segmentLocation.X += (float)Math.Cos(angle);
                segmentLocation.Y += (float)Math.Sin(angle);
                spriteBatch.Draw(blank, segmentLocation, null, Color.White, angle, new Vector2(blank.Width/2f,blank.Height/2f), 1f, SpriteEffects.None, 1f);
                angle = angle + MathHelper.ToRadians(1);
}


What I m trying to do is to draw the circumcircle of a triangle. I have its center and its radius calculated. EDIT: I also have the three points if there's a technique for that :P, I have almost everything apart how to draw the bloody circle :P

Share this post


Link to post
Share on other sites
Advertisement
Store the center position separately.


center_point.xy = center of triangle;

for(...) {
segmentLocation.X = center_point.x + cos(angle);
segmentLocation.Y = center_point.y + sin(angle);
draw(...);
}

Share this post


Link to post
Share on other sites
Yes, but you need to keep it as a separate variable, and update every iteration. You can't just do += cos(angle), but must start from the original center and add the cos/sin(angle) every iteration.

Share this post


Link to post
Share on other sites
OK, sorry I didn't understand what you meant at first :)

But that doesn't really make it go in its circumcircle the size of the circle is always 1 and can't make it into the needed size every time for different sized triangles

Share this post


Link to post
Share on other sites
Not sure I understand exactly what you mean, but to draw points around a circle with radius r at center-point c, you can do it like this:

for each angle {
position.x = c.x + r * cos(angle);
position.y = c.y + r * sin(angle);

draw_point_at(position);
}


You could also just create a vertex-buffer with the 360 points of a unit-circle and then draw it with a different transformation-matrix, depending on the radius (scale) and center-point (translation) of the circle you want.

Share this post


Link to post
Share on other sites
Yeah but the method I wrote always draws in a certain size the circle and what I m trying to do is draw a circle that passes from a triangle's 3 vertices, its circumcircle :)

The way I draw the circle makes it always the same size

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement