Kitomas

Untitled

Oct 1st, 2020
1,305
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- assuming your mobile computer previous coordinates were 99 120 100
  2. local previous_X, previous_Y, previous_Z = 99, 120, 100
  3. -- assuming your mobile computer current coordinates are 111 112 113
  4. local list_of_satellites = {
  5.    {x=22, y=55, z=77, distance=((111-22)^2+(112-55)^2+(113-77)^2)^0.5},  -- correct satellite
  6.    {x=35, y=99, z=42, distance=((111-35)^2+(112-99)^2+(113-42)^2)^0.5},  -- correct satellite
  7.    {x=44, y=44, z=44, distance=((111-94)^2+(112-94)^2+(113-94)^2)^0.5},  -- incorrect satellite
  8.    {x=10, y=88, z=70, distance=((111-10)^2+(112-88)^2+(113-70)^2)^0.5},  -- correct satellite
  9.    {x=54, y=54, z=54, distance=((111-64)^2+(112-64)^2+(113-64)^2)^0.5},  -- incorrect satellite
  10.    {x=91, y=33, z=15, distance=((111-91)^2+(112-33)^2+(113-15)^2)^0.5},  -- correct satellite
  11. }
  12.  
  13. local X, Y, Z, list_of_incorrect_sat_indices = trilateration(list_of_satellites, previous_X, previous_Y, previous_Z)
  14. if X then
  15.    print(X, Y, Z)
  16.    if #list_of_incorrect_sat_indices > 0 then
  17.       print("Satellites at the following indices are incorrect: "..table.concat(list_of_incorrect_sat_indices, ","))
  18.    end
  19. else
  20.    print"Not enough satellites"
  21. end
RAW Paste Data