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

Home » Public Forums » archive » Re: Arc of a circle
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
Re: Arc of a circle [message #70525] Wed, 21 April 2010 10:24
jeanh is currently offline  jeanh
Messages: 79
Registered: November 2009
Member
On 20/04/2010 9:16 PM, Fred wrote:
> Hello! simple question: does anybody know how to draw an arc of a
> circle in plot. A circle can be easily created, knowing the center
> coordinates and radius, through the routine "tvcircle". What I am
> mising is how to create a simple arc subtending an arbitrary angle.
> Thanks!
> Fred

Hi Fred,
here is a function I have that does basically what Craig just described.
This functions makes a pie (connects the arc to the center point), so
feel free to remove the 1st and last point to remove this part.

Jean


function pie, x_center,y_center, radius, angle_base, angle_arc, radian =
radian
;return a 2*102 array providing the coordinates of a pie. (straight
line from the center to the begining of the
; arc, the arc, straight line from the end of the line to the center
point.)
;The user can draw the pie as lines or as a polygon
;
;example:
; POLYFILL, pie(0,0,10,45,90)
; PLOTS, pie(0,0,10,45,90)

;INPUTS:
; X_center, Y_center: the coordinates of the center of the pie
; radius: the radius of the pie
; angle_base: arc of the pie will start to be drawn at this angle
; angle_arc: the other end of the arc will be at "angle_arc" degree
COUNTERclockwise from the begining of the arc
;
;KEYWORD:
; radian: set if the anles are specified in Radian. Default is Degree
;
;AUTHOR: Jean-Gabriel Hasbani jean-gabriel@.......hasbani.......ca
(remove the dots)
; March 2008

if n_elements(angle_arc) eq 0 then return,-1

angle_base_PIE = 1.0 * angle_base
angle_arc_PIE = 1.0 * angle_arc

if ~keyword_set(radian) then begin
angle_base_PIE = angle_base_PIE * !DtoR
angle_arc_PIE = angle_arc_PIE * !DtoR
endif

;get 100 points defining the arc
arc_points = ((angle_arc_PIE / 99.0) * FINDGEN(100))+angle_base_PIE
arc_x = x_center + radius * COS(arc_points)
arc_y = y_center + radius * SIN(arc_points)

;Add a straigth line from the center to the start and end points of the arc
x = [x_center, arc_x, x_center]
y = [y_center, arc_y, y_center]

arc_x = 0B
arc_y = 0B

;Create a 2 * 102 array of coordinates
pts = TRANSPOSE([[x],[y]])

RETURN, pts
end
Re: Arc of a circle [message #70535 is a reply to message #70525] Tue, 20 April 2010 20:01 Go to previous message
Craig Markwardt is currently offline  Craig Markwardt
Messages: 1869
Registered: November 1996
Senior Member
On Apr 20, 9:16 pm, Fred <fedef...@gmail.com> wrote:
> Hello!  simple question: does anybody know how to draw an arc of a
> circle in plot. A circle can be easily created, knowing the center
> coordinates and radius, through the routine "tvcircle". What I am
> mising is how to create a simple arc subtending an arbitrary angle.

Are you familiar with cosines and sines? The set of points X, Y

X = X0 + R*COS(TH)
Y = Y0 + R*SIN(TH)

where TH is an array spanning 0 to 2*!DPI, is a circle centered on
(X0,Y0).

If you choose a smaller span of angles, then you will get a circular
arc instead of a full circle.

Craig
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Unsigned Integer Math Problem
Next Topic: Re: Problem with variable declaration

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

Current Time: Wed Oct 08 15:07:48 PDT 2025

Total time taken to generate the page: 0.00524 seconds