Help with maths

I want to calculate the pixels that need to be on in the range. What I do is when I parse the data to the function I get the position of 2 points/pixels. I wan to calculate the pixels in between to turn on. I’m not sure where to start. Any ideas?


function Calculate_Range(On_Data)
    --[[
    Range = {
        ["Pixel_1"] = {
            ["Row"] = 1,
            ["Column"] = 2

        },
        ["Pixel_2"] = {
            ["Row"] = 3,
            ["Column"] = 5
        }
    },
    ]]
    local Test1 = On_Data.Range.Pixel_1.Row - On_Data.Range.Pixel_2.Row
    local Test2 = On_Data.Range.Pixel_1.Column - On_Data.Range.Pixel_2.Column
    print(Test1,Test2)

end```

I’m not sure I understand your problem

I want to find the numbers in the range. Ill provide an image below:


Basically I want to calculate the the range in between Pixel 1 and Pixel 2. So all the grey ones on the image.

1 Like

(I hope I understood your question correctly. Correct me if I didn’t). The solution to this problem is similar to how one would calculate the minimum and maximum vector3 when using Region3 which works by finding the minimum and maximum of all axis between both vectors. This is a function that returns a table containing the “pixels” in between 2 “pixels”:

local min = math.min
local max = math.max

function getBetween(x1,y1, x2,y2)
	local returnT = {}
	
	--Getting the minimum and maximum of both coordinates
	local minX = min(x1,x2)
	local minY = min(y1,y2)
	
	local maxX = max(x1,x2)
	local maxY = max(y1,y2)
	
	
	--Looping through the range
	for y = minY, maxY do
		for x = minX, maxX do
			if(x ~= x1 or y ~= y1) and (x ~= x2 or y ~= y2) then --Making sure the original values wont be included (disable this statement if you want the original coordinates to be included)
				table.insert(returnT, {
					Column = x,
					Row = y
				})
			end
		end
	end
	
	
	return returnT
end

Demonstration:

print(getBetween(1,1, 4,4))

image

print(getBetween(5,2, 4,3))

image

Edit: I made a mistake! Should be fixed now