Is there any number calculated from a point coordinates (I am calling it point property), that is same for two points only if they are at the exact same position?
For example the property "the distance of the point from other point", for example the origin [0,0], is not the property I am searching for, because every point on a circle with centroid in that other point has the same value of the property.
The best solution would be a property, that if I had such properties of two points I would be able to calculate the distance between them.
CodePudding user response:
You want to reduce the dimensionality of the space from 2 to 1. In theory this is possible for a limited domain because of the infinite nature of numbers. You’d accomplish this theoretical feat using a space-filling curve. You cannot construct a space-filling curve for the infinite 2D space.
But because we’re on a programming site, I assume you want to implement this in a computer. Now numbers are no longer infinite, we have a limited set of them. And this it is not possible to represent all the information in two floating-point numbers using a single floating-point number.
Now, if you are talking about a limited discrete domain (points in a grid with integer coordinates, such as the pixels of an image), then the problem is much simpler. MBo gave one arbitrary mapping, other mappings can be devised. The most typical solution to address grid elements or pixels is to compute x width * y
or y height * x
, with width
and height
the width and height of the grid/image, and the integer coordinates starting at 0. This leads to a compact representation, where each integer in a given range is mapped to a coordinate.
CodePudding user response:
Make union of coordinates to get single value. For example, if coordinates are 32-bits integer, it is not hard to make uint64 value for a point like this, using bit shift, multiplication, or type casting
val = pt.x (pt.y << 32)
val = pt.x pt.y * 4 294 967 296
val = (uint64) pt
Then extract components when needed
x = val & 0xFFFFFFFF
y = val >> 32
If coordinate range is rather small (say 10000), an int32
value can store both components