Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Define the coordinates and heights of the four corners of the square using Vector3
- local corner1 = workspace.C1.Position--lowest xz
- local corner2 = workspace.C2.Position--highx
- local corner3 = workspace.C3.Position--high xz
- local corner4 = workspace.C4.Position--highz
- local data = nil
- local kmlatc = 0.0089932160591873051132943266071425475329470212629986378196766981;
- local url = "https://api.open-elevation.com/api/v1/lookup"
- local header = {["locations"]={}}
- local center = {7.9389+0.01798643211,98.3389}--latlong
- -- Function to perform bilinear interpolation
- function calculateLon(lat)
- return 360/(math.sin(math.rad(90-lat))*2*math.pi*6371)
- end
- function bilinear_interpolation(x, y)
- -- Calculate normalized distances
- local alpha = (x - corner1.x) / (corner2.x - corner1.x)
- local beta = (y - corner1.z) / (corner3.z - corner1.z)
- -- Perform interpolation to estimate height
- local h = (1 - alpha) * (1 - beta) * corner1.y
- + alpha * (1 - beta) * corner2.y
- + alpha * beta * corner3.y
- + (1 - alpha) * beta * corner4.y
- return h
- end
- -- Test the interpolation at a specific point
- for lat = -25,25,0.1 do
- for long = -25,25,0.1 do
- local latitude = center[1] + kmlatc*lat
- local longtitude = center[2] +calculateLon(latitude)*long
- table.insert(header["locations"],{["latitude"]=latitude,["longitude"]=longtitude})
- end
- end
- print(game.HttpService:JSONEncode(header))
- local respond = game.HttpService:PostAsync(url,game.HttpService:JSONEncode(header))
- data = game.HttpService:JSONDecode(respond)
- print("responed")
- local c = 0
- for lat = -25,25,0.1 do
- for long = -25,25,0.1 do
- c=c+1
- local pointPos = Vector3.new(lat,0,long)
- local p = Instance.new("Part")
- p.Position=pointPos
- p.Anchored =true
- p.Size = Vector3.new(0.1,data["results"][c]["elevation"]/500,0.1)--divide20 to get mtree
- p.Parent =workspace
- p.Color = Color3.new(0,0,0)
- if data["results"][c]["elevation"] > 0 then
- p.Color = Color3.new(1,1,1)
- end
- task.wait()
- end
- end
- corner1 = workspace.C1.Position
- corner2 = workspace.C2.Position
- corner3 = workspace.C3.Position
- corner4 = workspace.C4.Position
- workspace.Visuals:ClearAllChildren()
- for x = corner1.X,corner2.X, 0.5 do
- for y=corner2.Z,corner3.Z,0.5 do
- local estimated_height = bilinear_interpolation(x, y)
- local px = Instance.new("Part");px.Position = Vector3.new(x,estimated_height,y);px.Anchored= true;px.Parent = workspace.Visuals;px.Size = Vector3.new(0.1,0.1,0.1)
- end
- end
- --end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement