http://www.perlmonks.org?node_id=1231454

Discipulus has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks,

I have an array of arrays full of o and, given the coordinates of one element and a radius I want to change all elements around the center into x

My AoA can be eventually big so I do not want to process every element of the AoA.

The sub ( illuminate in the example below ) must not complain if a point is outside of the AoA (for example giving a corner as vertex).

A pure perl solution will be the best, but also using modules will be ok.

Sorry if I only have the below sketch but I'm very scarce in trig and until now I can only figure to hardcode series of coordinates relative to the vertex (that is silly..)

use strict; use warnings; my $max = 19; my @aoa = map { [ ( 'o' ) x ($max + 1) ] } 0..$max ; display( @aoa ); # @to_change will contain [row1,col1],[row2,col2]... my @to_change = illuminate( 5, 4, 6 ); sub illuminate{ my $center_row = shift; my $center_col = shift; my $radius = shift; ... } sub display{ foreach my $row ( @_ ){ foreach my $col ( @$row ){ print $col; } print "\n" } }

Thanks

L*

PS the above code displays the AoA before the change: I want to be able to select into @to_change the serie of elements falling inside the circle.

minor changes to explain better

UPDATE June 24 2019 see also 2d field of view, vision algorithm in grid (ray casting)

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.