unique number from 3D coordinates

540 Views Asked by At

Is it possible to get a unique real number from $(x,y,z)$ coordinates? I need to sort a list of coordinates so i am looking for a simple function that generates one unique number with which to sort. It doesn't have to work all the time but something that works most of the time. First thing I thought was $x^2+y^2+z^2$ but then it fails for all points on a sphere so i have now $x^2+y^2+z^2+x-y+2z$ which i can't think of an example to make it fail. $x,y,z$ could at most be radius of the earth 6870000m.

2

There are 2 best solutions below

3
On BEST ANSWER

I'll assume that you want a function $f: \mathbb{R}^3 \rightarrow \mathbb{R}$ that is injective.

This is a bit messy - there is probably a better way to do this, but here goes. Let your inputs for $f$ be

$$x = a_na_{n-1}a_{n-2}\cdots a_2a_1.b_1b_2b_3\cdots$$

$$y = c_nc_{n-1}c_{n-2}\cdots c_2c_1.d_1d_2d_3\cdots$$

$$z = e_ne_{n-1}e_{n-2}\cdots e_2e_1.f_1f_2f_3\cdots$$

The decimal points are between $a_1$ and $b_1$, $c_1$ and $d_1$, and $e_1$ and $f_1$. We allow leading zeroes and simply take $n$ to be the number of digits of the maximum of $\lfloor x \rfloor$, $\lfloor y \rfloor$, and $\lfloor z \rfloor$.

Then we let $$f(x,y,z)=a_nc_ne_na_{n-1}c_{n-1}e_{n-1}\cdots a_1c_1e_1.b_1d_1f_1b_2d_2f_2\cdots$$

This function is injective. It also satisfies $$f(x,y,z) < 10^{3n}$$

2
On

You need an injective function from $\mathbb R^3$ to $\mathbb R$ You can take the following: Given $x,y,z$ take the decimal representation (if there are two take the finite one). And send $(x,y,z)$ to the following number: The part of the number before the decimal is going to be $2^{\lfloor{x}\rfloor}3^{\lfloor{y}\rfloor}5^{\lfloor{z}\rfloor}$ and the part after the decimal is going to be constructed by alternating $x,y$ and $z$.

Suppose $x$ has the following decimal expansion after the decimal: $.x_1x_2x_3\dots$

$y$ has $.y_1y_2y_3\dots $ and $z$ has $.z_1z_2z_3\dots$

Then we send $(x,y,x)$ to $2^{\lfloor{x}\rfloor}3^{\lfloor{y}\rfloor}5^{\lfloor{z}\rfloor}+.x_1y_1z_1x_2y_2z_2x_3y_3z_3x_4y_4z_4\dots$