0

I am trying to make an addon for a 3D game, that will require to fly in certain areas, that will be defined in a very long JSON array. The game works with coordinates, and the cube will be determined via coordinates too.

How can I check if the point given in the function with its lat, lon, and alt is in a defined box? The code must also be very light, as it would run every 50ms or so.

How the code would look like:

function checkIfInBox(playerLat, playerLon, playerAlt, cube){
//code to determined
if (inCube === true){
return true
}
else {
return false}
}

playerLat, playerLon and playerAlt would be integers, while cube would be an array with all 8 corners of the cube.

  • Is it an axis-aligned cube? Is the lat-long-alt also axis-aligned? Typically it's best to transform the point into the coordinate system of the cube. Longitude has an arbitrary orientation, we'd need to know the conventions by which the various coordinate systems are defined. – Wyck Jun 21 '22 at 18:12
  • Im not sure what you mean by axis-aligned, but the cube can be rotated in any way on the Z axis. lat-lon-alt are just what I am extracting from the game, and they are the precise position of the user. What I'm asking is really how to know if this user is in the area defined by 8 points. – TotallyRealElonMusk Jun 21 '22 at 18:16
  • Convert polar lat-long-alt to X,Y,Z cartesian coordinates. Then transform the X,Y,Z coordinates into the local coordinate system of the cube (usually by multiplying by the inverse of its object-to-world transformation matrix). Then if you have x,y,z coordinates relative to the cube it's a trivial check from there. – Wyck Jun 21 '22 at 18:18
  • If it was 2D then the problem has a solution (it's called a point inside polygon). By projecting the cube onto a plane (for all dimensions) you can check if the point lies within all of them. – IT goldman Jun 21 '22 at 18:24
  • Actually i figured out a way: check if the X of the point is between the min and max of the X cube, and do the same with the Y and Z. Thanks for the help! – TotallyRealElonMusk Jun 21 '22 at 18:55

0 Answers0