在 JavaScript 中表示 3D 对象的最佳方式
我想用 javascript 表示 3D 对象。实际上,我想表示视频中的对象(即 x、y 和时间,因此它就像 3D 对象)。我将有一组由 X、Y 和 Z(时间)边界定义的对象。将有一个函数getObject(x,y,z)
,给定一个点(X,Y,Z),它将返回包含该点的对象。不会有重叠的对象,因此每个点只能映射到一个对象。
我可以使用 3D 数组,它会变成一个非常快的 getObject 函数,但是这样我就会有大量数据,这将是一个问题,因为它是一个 Web 应用程序。另一方面,我可以只存储每个对象的 x、y 和 z 边界,但是函数 getObject 会更慢,因为它必须迭代所有对象。
我相信很多人以前都遇到过这个设计问题。
I want to represent 3D objects in javascript. Actually, I want to represent objects in a video (which would be x,y, and time, so it's like a 3D object). I will have a set of objects which are defined by boundaries of X,Y and Z (time). There wil be a function getObject(x,y,z)
which, given a point (X,Y,Z) will return the object in which that point is contained. There will be no overlapping objects, so each point can be mapped only to one object.
I could use a 3D array, which turns into a very fast getObject function, but then I'd have a huge amount of data, which would be a problem as it's a web application. On the other hand I could do it storing just the x,y and z boundaries for each object, but then the function getObject would be slower is it would have to iterate over all objects.
I am sure this design problem has been faced before by many people.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果不了解有关您的问题的更多细节(对象的大小/形状、运行时要求),很难说,但您可能对 八叉树数据结构,这是常用的3D场景管理器。
It's hard to say without knowing more specifics about your problem (size/shape of your objects, runtime requirements), but you may be interested in the Octree data structure, which is commonly used 3D scene managers.