1. arcs

Howdy there people...

Does anyone have a procedure that draws arcs, or know of some little
string of code to do it?

Anything woud be appreciated.

Thanking you in advance,

Mike Fowler


==
Mike Fowler - wildcat_nz at yahoo.com  o__ ---
wildcat_nz at yahoo.com               _,>/'_ ---
"the limitations are limitless"   (_) \(_) ---
 - Beck

_________________________________________________________
DO YOU YAHOO!?
Get your free @yahoo.com address at http://mail.yahoo.com

new topic     » topic index » view message » categorize

2. Re: arcs

About a week ago Mike Fowler asked for a routine to draw arcs. I wanted  the
thing myself several times in the past, and since it's not an easy one to
improvise, I finally decided to have a go tonight.

The routine below is not terribly fast, but it seems to do its job
reasonably well. I have done very little testing, so if you encounter any
problems, please let me know. Enjoy. jiri

--  file  : arc.e
--  author: jiri babor
--  email : jbabor at paradise.net.nz
--  date  : 98-11-13

constant
    pi = 3.14159265359,
    d2r=pi/180      -- degrees to radians

function round(object x)
    if atom(x) then
        if x<0 then return -floor(-x+0.5)
        else return floor(x+0.5)
        end if
    else
        for i=1 to length(x) do
            x[i]=round(x[i])
        end for
        return x
    end if
end function

function arc_points(integer x,integer y,integer a,integer b,atom sa,atom
sweep)
    -- x,y are centre coordinates of ellipse
    -- a,b are x and y half-axes respectively
    -- sa is starting angle
    -- sweep is arc angle
    -- angles in degrees, clockwise, zero at 3 o'clock
    -- return coordinates of starting and ending point of arc:
{{x1,y1},{x2,y2}}
    atom ea
    ea=sa+sweep
    sa=sa*d2r       -- starting angle in radians
    ea=ea*d2r       -- ending angle in radians
    return round({{a*cos(sa),b*sin(sa)}+{x,y},{a*cos(ea),b*sin(ea)}+{x,y}})
end function

procedure arc(integer xc, integer yc, integer a, integer b,
              atom sa, atom sweep, integer c)
    -- draw elliptical arc of color c
    -- x,y are centre coordinates of ellipse
    -- a,b are x and y half-axes respectively
    -- sa is starting angle
    -- sweep is arc angle
    -- angles in degrees, clockwise, zero at 3 o'clock
    atom d,ea,f
    integer ex,ey,x,y,aa,bb
    aa=a*a
    bb=b*b
    f=a/b
    d=bb/sqrt(aa+bb)
    if sweep<0 then
        ea=sa*d2r
        sa=(sa+sweep)*d2r
    else
        ea=(sa+sweep)*d2r
        sa=sa*d2r
    end if
    x=round(a*cos(sa))
    y=round(b*sin(sa))
    ex=round(a*cos(ea))
    ey=round(b*sin(ea))
    pixel(c,{x,y}+{xc,yc})
    while x!=ex or y!=ey do
        if y<-d then
            x=x+1
            y=-round(sqrt(aa-x*x)/f)
        elsif y>d then
            x=x-1
            y=round(sqrt(aa-x*x)/f)
        elsif x>0 then
            y=y+1
            x=round(sqrt(bb-y*y)*f)
        else
            y=y-1
            x=-round(sqrt(bb-y*y)*f)
        end if
        pixel(c,{x,y}+{xc,yc})
    end while
end procedure


--
<snip:test> ----------------------------------------------------------------
-

include graphics.e
include get.e

object junk

junk=graphics_mode(18)
ellipse(BRIGHT_BLUE,0,{60,50},{260,150})
arc(160,100,100,50,-30,-270,BRIGHT_WHITE)

arc(50,50,20,20,180,90,YELLOW)
arc(270,50,20,20,-90,90,YELLOW)
arc(270,150,20,20,0,90,YELLOW)
arc(50,150,20,20,90,90,YELLOW)
draw_line(YELLOW,{{50,30},{270,30}})
draw_line(YELLOW,{{50,170},{270,170}})
draw_line(YELLOW,{{30,50},{30,150}})
draw_line(YELLOW,{{290,50},{290,150}})

junk=wait_key()
junk=graphics_mode(-1)


-----Original Message-----
From: Mike Fowler <wildcat_nz at YAHOO.COM>
To: EUPHORIA at LISTSERV.MUOHIO.EDU <EUPHORIA at LISTSERV.MUOHIO.EDU>
Date: Friday, November 06, 1998 8:12 PM
Subject: arcs


>Howdy there people...
>
>Does anyone have a procedure that draws arcs, or know of some little
>string of code to do it?
>
>Anything woud be appreciated.
>
>Thanking you in advance,
>
>Mike Fowler
>
>
>==
>Mike Fowler - wildcat_nz at yahoo.com  o__ ---
>wildcat_nz at yahoo.com               _,>/'_ ---
>"the limitations are limitless"   (_) \(_) ---
> - Beck
>
>_________________________________________________________
>DO YOU YAHOO!?
>Get your free @yahoo.com address at http://mail.yahoo.com
>
>

new topic     » goto parent     » topic index » view message » categorize

3. Re: arcs

Pathetically enough, I am following Irv's example:
replying to my own email!

This is really just for the newbies, all oldhands would
have already recognized my mistake: please make the main
two routines, arc_points() and arc() *global*, otherwise
they will not be visible outside their own include!

(No-one should be allowed to post any code at 3 am!) jiri

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu