Advertisement
NUCLEARESOL

Phuket generator roblox

Sep 29th, 2023
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. -- Define the coordinates and heights of the four corners of the square using Vector3
  2. local corner1 = workspace.C1.Position--lowest xz
  3. local corner2 = workspace.C2.Position--highx
  4. local corner3 = workspace.C3.Position--high xz
  5. local corner4 = workspace.C4.Position--highz
  6. local data = nil
  7. local kmlatc = 0.0089932160591873051132943266071425475329470212629986378196766981;
  8. local url = "https://api.open-elevation.com/api/v1/lookup"
  9. local header = {["locations"]={}}
  10. local center = {7.9389+0.01798643211,98.3389}--latlong
  11. -- Function to perform bilinear interpolation
  12. function calculateLon(lat)
  13. return 360/(math.sin(math.rad(90-lat))*2*math.pi*6371)
  14. end
  15. function bilinear_interpolation(x, y)
  16. -- Calculate normalized distances
  17. local alpha = (x - corner1.x) / (corner2.x - corner1.x)
  18. local beta = (y - corner1.z) / (corner3.z - corner1.z)
  19.  
  20. -- Perform interpolation to estimate height
  21. local h = (1 - alpha) * (1 - beta) * corner1.y
  22. + alpha * (1 - beta) * corner2.y
  23. + alpha * beta * corner3.y
  24. + (1 - alpha) * beta * corner4.y
  25.  
  26. return h
  27. end
  28.  
  29. -- Test the interpolation at a specific point
  30. for lat = -25,25,0.1 do
  31. for long = -25,25,0.1 do
  32. local latitude = center[1] + kmlatc*lat
  33. local longtitude = center[2] +calculateLon(latitude)*long
  34. table.insert(header["locations"],{["latitude"]=latitude,["longitude"]=longtitude})
  35. end
  36. end
  37.  
  38. print(game.HttpService:JSONEncode(header))
  39. local respond = game.HttpService:PostAsync(url,game.HttpService:JSONEncode(header))
  40. data = game.HttpService:JSONDecode(respond)
  41. print("responed")
  42. local c = 0
  43. for lat = -25,25,0.1 do
  44. for long = -25,25,0.1 do
  45. c=c+1
  46. local pointPos = Vector3.new(lat,0,long)
  47. local p = Instance.new("Part")
  48. p.Position=pointPos
  49. p.Anchored =true
  50. p.Size = Vector3.new(0.1,data["results"][c]["elevation"]/500,0.1)--divide20 to get mtree
  51. p.Parent =workspace
  52. p.Color = Color3.new(0,0,0)
  53. if data["results"][c]["elevation"] > 0 then
  54. p.Color = Color3.new(1,1,1)
  55. end
  56. task.wait()
  57. end
  58. end
  59.  
  60.  
  61. corner1 = workspace.C1.Position
  62. corner2 = workspace.C2.Position
  63. corner3 = workspace.C3.Position
  64. corner4 = workspace.C4.Position
  65. workspace.Visuals:ClearAllChildren()
  66. for x = corner1.X,corner2.X, 0.5 do
  67. for y=corner2.Z,corner3.Z,0.5 do
  68. local estimated_height = bilinear_interpolation(x, y)
  69. 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)
  70.  
  71. end
  72. end
  73. --end
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement