# Best way to get all vectors between two vectors?

Alright so currently I have a grid that is made with Rows and Columns and each cell has a 2dvector as a coord (X1Y1).

say I have a grid with 20 rows and 20 columns that would give me 400 different 2d vectors as a coord.

When I input a specific coord for example lets use X50Y50 and i want to get all vectors with in a 4 cell radius

Right now i have to currently make a function that i manualy made a vector + or - for each cell that could be in radius and its quite cumbersome and seems alot more work than it should be as if i want to scale it and get vectors in a bigger radius i have to then make 100s of + or 1 nodes for each cell i want to obtain.

Is there any way i could just put the start and end coords and get all between?

For example a function takes the origin cell coord the center then adds the max radius and subtracts max radius and then gets all cell coords between those two?

EXAMPLE OF WHAT I WANT TO DO: Start origin Cell Coord is X5,Y5 I want a radius of 4 cells out

So how do I get all cell coords between X9,Y1 and X1,Y9?

I can’t seem to find a simple way to just get all vectors within a range or box. I know the is point in box node exists but i dont understand how to apply it or if its the right way to do what i want.

I always do this i post a question then while i wait for some insight i tend to more or less figure it out lol.

Your way is almost identical to what i ended up coming up with after testing both your method vs the one i came up with i found your method will skip cells on the same row or column of the origin since we are either adding or subtracting both the x and y value on every loop instead of X+1 Y+0 thus some cells were lost and this could easily be added into your example to account for.

Below is the method i came up with I think yours might technically be better performance wise since it’s only using a single loop

I will test both and see what one is better. thank you for your response!

If I understand your question correctly, I think you just need to simply do an array of vectors with some looping and some math. Does this work for you?

Note: if you don’t want to include the starting vector in your array of vectors, simply change the for loop first index to 1.

No, you are totally right. My logic was pretty flawed actually. I think I just tried to do it too quickly. Anyway, I edited my answer and made it a lot cleaner, but it does require two for loops as well.