Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re^2: circular area in a coordinates grid (AoA)

by Discipulus (Abbot)
on Mar 20, 2019 at 12:32 UTC ( #1231489=note: print w/replies, xml ) Need Help??

in reply to Re: circular area in a coordinates grid (AoA)
in thread circular area in a coordinates grid (AoA)

very nice, thanks for the code and for the patience Marshall,

I noticed your code get some Use of uninitialized value in join or string if the circle goes outside of the AoA for high values of row.

I fixed it with a condition more in the nested for loop:

$aoa[$x][$y] = 'x' if ( (($x-$circle_x)**2 + ($y-$circle_y)**2 <= ($ci +rcle_radius**2) ) # and $x >=0 and $y >=0 ) + and $x >=0 and $y >=0 and $x <= $max )


There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^3: circular area in a coordinates grid (AoA)
by Marshall (Canon) on Mar 21, 2019 at 21:17 UTC
    Thanks for the correction! I guess there is a similar problem in the y direction. I like seeing bug reports like this because it means that somebody actually ran the code! I guess some adjustment of the loop conditional is also possible to not even consider points outside of the input array.

    I very seldom use $array[][] syntax because Perl is so cool at working with references to rows. I suppose some tricky splice() statement could be used, but my brain started hurting and I went for something straightforward. Glad to have been of help.

    Update: Here is modified version without extraneous prints and better control over loop condition:

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1231489]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2021-10-27 08:35 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (91 votes). Check out past polls.