two LEDS away on the x, y, x axis
That is not a matrix but a cube. Is that right?
Is there a way to do that?
Yes, there are several ways but first you have to know how things are wired up so that you can calculate an LED number from an x, y, z coordinate and back again, that is given an LED number get back a x, y, z coordinate.
Once you have those functions you can implement your rules us in either a look up table or algorithm.
i would really appreciate it if you can give me sample code
That normally means do it for you, unless you can give me an example where it would not be.