简体   繁体   English

立方体表面上的点之间的距离

[英]Distance between points on surface of cube

Let (x1, y1, z1) and (x2, y2, z2) be two points in Euclidian 3-space on the surface of an axis-aligned side-length-2 cube centered at the origin. (x1, y1, z1)(x2, y2, z2)是在以原点为中心的轴对齐的边长2 立方体的表面上的欧几里得3空间中的两个点。

How do I efficiently compute the distance (or squared distance) between the points over the surface of the cube ? 如何有效地计算立方体表面上的点之间的距离(或平方距离)?

Internally, I represent points as (offset1, offset2, faceNumber) but an (x,y,z) format (as referenced above) is readily available. 在内部,我将点表示为(offset1, offset2, faceNumber)但是(x,y,z)格式(如上所述)很容易获得。

I prefer C or Python code but I'll happily accept pseudocode or anything, really. 我更喜欢C或Python代码,但我会很乐意接受伪代码或其他任何东西。

EDIT: 编辑:

Some facts: 一些事实:

  1. Shortest paths are always monotone in x, y, and z. 最短路径在x,y和z中始终是单调的。
  2. If the points are on the same face then it's trivially just Euclidian distance. 如果这些点在同一张面孔上,那么它只是欧几里得距离。
  3. If the points are not on the same face, the shortest path could involve either 2 or 3 faces. 如果这些点不在同一面上,则最短路径可能包含2或3个面。

EDIT: What I would do, is turn the 3d cube into a 2d plane. 编辑:我要做的是将3d立方体变成2d平面。 The caveat is that, if the point is on the opposite side of the cube, you need to place the final surface on all ends of the cross. 需要注意的是,如果点在立方体的另一侧,则需要将最终曲面放置在十字的所有末端。

If a cube had sides like this that you could fold around so that 4 touched side 1. 如果一个多维数据集具有这样的侧面,则可以折叠以使4碰到侧面1。

5
1 2 3 4 
6

You would have a 2d plane that ultimately looked like this 您将拥有一个二维平面,最终看起来像这样

         3
    4/5  5   5/2
3   4    1   2   3
    4/6  6   2/6
         3

So, I modified this. 因此,我对此进行了修改。 Now each of the corner panels represents the connections that can take place between both panels. 现在,每个角面板代表两个面板之间可能发生的连接。 When you initially lay out this array, each point on panels 2, 4, 5, and 6, will map to three points. 最初布局此阵列时,面板2、4、5和6上的每个点都将映射到三个点。 The solution is then the shortest line to any of the given points, that represent point 2, in the event you need to map it to multiple points. 然后,如果需要将其映射到多个点,则解决方案是到任意给定点(代表点2)的最短线。

Mapping points from the 3d cube, to their initial 1 - 6 pains on the 2d graph is really quite simple. 将点从3d多维数据集映射到2d图上最初的1-6痛点确实非常简单。 The only difficulty left is figuring out how to map points from the 2 plane, onto the "2/6" plane and so forth. 剩下的唯一困难是弄清楚如何将点从2平面映射到“ 2/6”平面,依此类推。 This is just a matter of thinking through each situation. 这只是考虑每种情况的问题。 Ex: 2 -> 2/6 is different from 5 -> 5/2. 例如:2-> 2/6与5-> 5/2不同。 My intuition is that it's either going to be 90 degree or -90 degree rotation, before shifting the width of the cube in the appropriate direction. 我的直觉是,在将多维数据集的宽度沿适当的方向移动之前,它将旋转90度或-90度。

For example, to properly handle the situation you laid out we would have a value at the bottom left corner of plane one, and the bottom right corner of plane 2. After the following: ' 例如,要正确处理您所布置的情况,我们将在平面1的左下角和平面2的右下角具有一个值。

points in plane 2/6 = rot90(points in plane 2) - width of the cube.  

We will have a point in the bottom left corner of plane 2/6. 我们将在平面2/6的左下角有一个点。 This will then appropriately be the shortest path, and appropriately this path crosses the face of plane 6. 然后,这将适当地成为最短路径,并且该路径将适当地越过平面6的面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 计算2点之间的网格距离 - Calculate distance on a grid between 2 points 在“环绕地图”上的一组点之间的“质心”,可以最大限度地减少到所有点的平均距离 - “Center of Mass” between a set of points on a Toroidally-Wrapped Map that minimizes average distance to all points 使用浮点计算极坐标中两点之间的距离 - Computing the distance between two points in polar coordinates using floating-point 环形包裹(x和y包裹)地图上点之间的最短距离? - Shortest distance between points on a toroidally wrapped (x- and y- wrapping) map? 使用浮点算法来计算2点之间的距离的准确方法? - Accurate methods for computing distance between 2 points using floating-point arithmetic? 在给定距离的直线上查找点 - Finding points on a line with a given distance 寻找点之间的翻译 - Finding the translation between points 编辑两个图之间的距离 - Edit distance between two graphs 如何找到地球表面上从一点到路径的最短距离 - How can I find the shortest distance from a point to a path over the surface of the earth 查找彼此之间的距离是数字的倍数的点的子集 - Find subset of points whose distance among each other is a multiple of a number
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM