Projecting longitude and latitude into roblox coordinates

Hi! I’m working on a project to essentially port GIS data into Roblox Studio. The problem is, I’m bad at math. I’m struggling to convert longitude and latitude values into usable coordinates. I’m currently (or at least, have been) trying to use the Mercator projection, but for some reason it isnt working in my code. For the sake of simplicity, I’m going to hardcode the relative points, but these points are from an actual dataset.
The code:

local long, lat = -18.10700586764, 2.72381920804
local origin = {18.10540349317, 2.72392959377}

local lambda, phi = math.rad(long - origin[1]), math.rad(lat - origin[2])

-- long = λ
-- lat  = φ

local x = 637813 * lambda - math.rad(origin[1])
local y = 637813 * math.log(math.tan((math.pi/4)+(phi/2)) - math.rad(origin[2])) -- ln(tan(π/4 + φ/2) - λ0), where λ0 = origin[1]

print(x)
print(y)

Returns -403114.5706251562 and -31068.386101019096. I tried the same formula with the same values in Desmos, and the values are completely off. Desmos returns -17.8375314293 and 742.614377499. Am I missing something? Like I said, I’m not great at math, but as far as I can tell the code is doing the same formula that I have in Desmos. I was able to find this on StackOverflow, but the pseudocode they gave as an example was completely different which confused me a bit.


Tangentially related question about a similar but different formula

I found another plugin doing something similar to what I’m doing. This plugin uses the following code:

function util.coord_to_pos(lat, long, origin, scale)
	local x = (long - origin[2])
	local y = lat - origin[1]
	
	return x*scale*math.cos(math.rad(lat)), -y*scale
end

I’ve tested this method out and it works fine, however I have no information on how they got this formula or how it works. I know basically nothing about this method, and the plugin I’m referencing is completely undocumented. I don’t want to use a formula when I have no idea what its origin is or who originally made it, and I don’t want to just steal someone else’s code straight from their own project. If anyone has any details on the method/formula that is used here, please share so I can look into it (I know it works!)

Thanks in advance,

637813 * lambda - math.rad(origin[1])

Is not the same as this:

637813 * (lambda - math.rad(origin[1]))

Also if λ is longitude why does it appear in the formula for y in your comment? It seems like you subtract origin[2] from lat twice.

Moved (added?) the parenthesis and its still completely borked. No luck

Also if λ is longitude why does it appear in the formula for y in your comment? It seems like you subtract origin[2] from lat twice.

My mistake, that shouldn’t have been there. Still not working sadly.