Modified gen_ball.m