Re: circles
- From: dempson@xxxxxxxxxxxxx (David Empson)
- Date: Thu, 23 Feb 2006 09:44:38 +1300
<aiiadict@xxxxxxxxx> wrote:
slowly figuring this out...
it only works for angles 90,180, 270...
other angles need "special cases"..
I calculate start/end points of arc using trig (sin and cos)
the circle segment is drawn, then the arc draw is
attempted...
for other angles besides those above, I need to set X
and Y to the start/end points of the arc, and draw from
there.
if anyone has a better idea of how to do this, please let
me know...
I want to get the arc coordinates for a 45 degree slice
of a circle. As input to the routine, I have ANGLE. The
arc I want coordinates for is ANGLE-22.5 to angle +22.5
I haven't looked at your program in detail, but there is a standard
algorithm for drawing circles (or arcs).
I managed to work it out for myself back in high school (mid 80s) when I
wrote a hi-res graphics drawing program. My memory was refreshed when I
was taught it again in a graphics course at University (late 80s).
Haven't had much use for it since then so my memory is a bit rusty. The
name "Bresenham" comes to mind, but I might be muddling the line and
circle algorithms.
You can work out the start and end coordinates for an arc using sin and
cos. The trick then is to work out exactly which pixels between those
two points are the best fit for the circle.
The algorithm basically works by stepping one pixel at a time from the
start position towards the end position. For each potential pixel,
calculate the distance to centre of the circle, and then plot the pixels
which are the closest fit.
Within any eighth of the circle, you always step one pixel on one axis,
and either 0 or 1 pixels on the other axis.
For example, within the 0 to 45 degree arc, you always step one pixel
up, and step either 0 or 1 pixels left (whichever is the closest fit).
Within the 45 to 90 degree arc, you always step one pixel left, and step
either 0 or 1 pixels up (whichever is the closest fit).
Repeat for each subsequent quadrant.
Calculating the distance to the centre is a bit difficult (square root),
but you can take a shortcut by working in squares of the X and Y
coordinates, and comparing that to the square of the hypotenuse.
Good luck!
--
David Empson
dempson@xxxxxxxxxxxxx
.
- Follow-Ups:
- Re: circles
- From: aiiadict
- Re: circles
- References:
- circles
- From: aiiadict
- circles
- Prev by Date: circles
- Next by Date: Re: circles
- Previous by thread: circles
- Next by thread: Re: circles
- Index(es):
Relevant Pages
|
Loading