comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Circle drawing request.
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Circle drawing request. [message #7981] Tue, 28 January 1997 00:00
D.Kennedy is currently offline  D.Kennedy
Messages: 26
Registered: January 1997
Junior Member
This must be a FAQ - anyone got a good circle drawing sub-routine?
Input - x, y, radius
Output - [x,y] vectors for POLYFILL etc.

I have been using one (shown below) but I find it produces fine lines
shooting off to small y values from the left and right edges of each
circle. And my fiddling with it has made it worse I'm afraid.


FUNCTION CIRCLE, xcenter, ycenter, radius
; Emailed by Dfanning 27th Jan

step = (radius/24.0)
x = FLTARR(25)
y = FLTARR(25)

; Construct a circle

FOR j=0,24 DO BEGIN
x(j) = j*step
y(j) = SQRT(radius^2 - x(j)^2)
ENDFOR

x = [x, Reverse(x)]
y = [y, -Reverse(y)]
x = [-Reverse(x), x]
y = [y,y]

; Center the circle at the specified coordinates.

x = x + xcenter
y = y + ycenter

points = FLTARR(2, 100)
points(0,*) = x
points(1,*) = y
RETURN, points
END
--
David Kennedy, Dept. of Pure & Applied Physics, Queen's University of Belfast
Email: D.Kennedy@Queens-Belfast.ac.uk | URL: http://star.pst.qub.ac.uk/~dcjk/
Hi! I'm a .signature virus! Copy me into yours and join the fun!
Re: Circle drawing request. [message #7985 is a reply to message #7981] Tue, 28 January 1997 00:00 Go to previous message
Wayne Landsman is currently offline  Wayne Landsman
Messages: 117
Registered: January 1997
Senior Member
David Kennedy wrote:
>
> This must be a FAQ - anyone got a good circle drawing sub-routine?
> Input - x, y, radius
> Output - [x,y] vectors for POLYFILL etc.
>
> I have been using one (shown below) but I find it produces fine lines
> shooting off to small y values from the left and right edges of each
> circle. And my fiddling with it has made it worse I'm afraid.
>
David,

You might want to look at the procedure TVCIRCLE available from
http://idlastro.gsfc.nasa.gov/ftp/pro/tv/tvcircle.pro, which includes a
/FILL option for using POLYFILL. It uses a more sophisticated circle
drawing algorithm that was shown to me a few years back by Allyn Saroyn.

A possible problem with the simple-minded algorithm where the X,Y
coordinates of the circle are calculated at a preset number of values
(25*4 = 100 for David Fanning's sample code) is that the circle might
sometimes be smooth, and sometimes spiky, depending on the circle size
and the graphics device. TVCIRCLE gets around this problem by always
calculating the positions internally in device coordinates, and
calculating all positions where the X,Y device coordinates differ by an
integral amount. Thus, the circle is guarenteed (in principle) to come
out smooth on all graphics devices.

--Wayne Landsman landsman@mpb.gsfc.nasa.gov
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Shaded circles request.
Next Topic: Re: Colorbar query.

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:39:44 PDT 2025

Total time taken to generate the page: 0.00593 seconds