Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8677645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:30:53+00:00 2026-06-12T20:30:53+00:00

All- So I need to store 3D positions (x, y, z) associated with objects

  • 0

All-

So I need to store 3D positions (x, y, z) associated with objects in a video game.

I’m curious, is this a terrible idea? The positions are generated quite frequently, and may vary some.

I basically would ONLY like to store the position in my database if it’s not within a yard of a position already stored.

I was basically selecting the existing positions for an object in the game (by object_id, object_type, continent and game_version), looping through, and calculating the distance using PHP. If It was > 1, I would insert it.

Now that i’m at about 7 million rows (obviously not for the same object), this isn’t efficient and the server I’m using is coming to a crawl.

Does anyone have any ideas on how I could better store this information? I’d prefer it be in MySQL somehow.

Here is the structure of the table:

object_id
object_type (like unit or game object)
x
y
z
continent (an object can be on more than one continent)
game_version (positions can vary based on the game version)

Later when I need to access the data, I basically only query it by object_id, object_type, continent, and game_version (so I have an index on these 4)

Thanks!
Josh

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T20:30:54+00:00Added an answer on June 12, 2026 at 8:30 pm

    Presumably objects on different continents are considered infinitely far apart. Also you haven’t disclosed the units you’re using in your table. I’ll assume inches (of which there are 36 in a yard).

    So, before you insert a point you need to determine whether you’re within a yard. To do this you’re going to need either the MySQL geo extension (which you can go read about) or separate indexes on at least your x and y columns, and maybe the z column.

    Are there any points within a yard? This query will get you whether there are any points within the bounding box of +/- one yard around your new point. A ‘nearby’ result of one or more means you shouldn’t insert the new point.

      SELECT COUNT(*) nearby
        FROM table t
       WHERE t.x between (?xpos - 36) AND (?xpos + 36)
         AND t.y between (?ypos - 36) AND (?ypos + 36)
         AND t.z between (?zpos - 36) AND (?zpos + 36)
         AND t.continent = ?cpos
    

    If you need the query to work with Cartesian distances rather than bounding boxes you can add a sum-of-squares distance computation. But I suspect bounding boxes will work just fine for your app, and be much more efficient than repeatedly fetching 75-row result sets to do proximity testing in your application.

    Conceptually it wouldn’t be much harder to create a stored procedure for MySQL that would conditionally insert the new row only if it met the proximity criteria. That way you’d have a simple one-way transaction rather than server back-and-forth.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I´ve a Javascript object with all the data that I need to store on
I need make all of my posts update. I use bulk upload for store,
All I need this for is strcpy(). I want to see whether the first
I need help with pointers and memory management. I need to store different objects,
We want to store positions of objects on a map in a database. Queries
This is my problem: I need to store a lot of log messages and
I need to read a PNG file and interpret all the information stored in
I have multiple threads who all need to write to the same Dictionary. I
I have a whole bunch of buttons that all need to have both a
I just have the array of 15 values that all need to be inserted

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.