Is it possible to expand this task to the N-dimensional case?

Even so: is the use of recursion and a variable number of arguments justified here?

something like

function get_dimension($point,$radius,$dimension_axis){ for($i=floor($point[$dimension_axis]-$radius);$i<=ceil($point[$dimension_axis]+$r);$i++){ if($dimension_axis>count($point)){ //Операции с мегамерным массивом }else{ get_dimension($point,$radius,++$dimension_axis); } } 

    1 answer 1

    In theory, it is easy to generalize, and recursion (by the number of dimensions) seems to me a suitable tool.

    I would have done something like this (I didn’t test it with pseudocode either, sorry, I’m not a php expert):

     process_points(int currdim, point currpoint, point center, double radius) { var r2 = radius * radius; var currpointR2 = 0; for (var dim = 0; dim < currdim - 1; dim++) currpointR2 += (currpoint[dim] - center[dim]) * (currpoint[dim] - center[dim]); var restR2 = r2 - currpointR2; if (restR2 < 0) return; var restR = sqrt(restR2); var min = floor(center[currdim] - restR); var max = ceil(center[currdim] + restR); for (var xx = min; xx <= max; xx++) { point newCurrPoint = currpoint; newCurrPoint[dim] = xx; if (currdim < totaldims - 1) process_points(currdim + 1, newCurrPoint, center, radius); else // last dim paint_point(newCurrPoint); } } process_points(0, center, center, r);