Way to mapping N dimensional vector to a point - algorithm

I'm facing a problem with mapping, I need mapping N dimensional vectors to one group/point, like [0,1....N-1] to 1 | [1,2....N-1] to 2.
The problem is that, right now I have one function where receive a dimensional vector and the return a point, that point is the result, I want avoid call the function, I already have all results stored in a table, the problem is, I'll remove the function and now I need mapping the new entry to a existing point.
There is some way to mapping the entry to a correct point?
There is some algorithm to mapping to the correct point?
Some help or advice?
I already saw this topic, but I'm not sure whether Hilbert Curve is the solution, I need study more about it.
Mapping N-dimensional value to a point on Hilbert curve
I'll be grateful.

Mapping an n dimensional data to a one dimensional data is called projection. There are lots of ways to project an n dimensional data to a lower dimension the most well-known ones are PCA, SVD, or using radial basis functions. If you do not have your method of projection anymore, you probably can't project another point unless you have a hash-table of the previous projected points. If you happen to have exactly the same point, then you can map it to the same point. However, pay attention that the projection is not one-to-one meaning that there may exist two points that are mapped to the same point in the lower dimension. An example of such a case is the projection of 3D points on the screen on which many points may get mapped to exactly the same points on the screen. As a result, inverse projecting the points usually have ambiguities. About the link that you sent about Hilbert curve, this is a general approach to project a point in ND to a point on a space filling curve (SFC) such as Hilbert, Peano, etc. This website at MIT has interesting stuff about dimension reduction using SFC:
http://people.csail.mit.edu/jaffer/Geometry/MDSFC

Related

Determine whether a point is inside a cube using only distance queries

Given a 3D distance field that contains the distance to points in a grid (e.g. an ESDF or TSDF), I want to efficiently check whether a cube at an arbitrary orientation contains a point.
A straightforward approach is to perform raytracing to identify which cells are contained inside of the cube and check if any of those cells have 0 distance. This solution is unsatisfying because it throws away the distance information and is tightly coupled to the underlying ESDF via raytracing. It seems like we should be able to solve this problem more generally using the distance information and the resolution parameter.
One could imagine a more sophisticated approach which first checks the distance from the center of the cube to a point - if the value is large enough we know the cube is empty, or if it is small enough we know there is a point inside the cube. If the value is somewhere in between, we could recursively check the ambiguous regions. Because the distance function is discretized this algorithm should eventually terminate if the bookkeeping is done properly during the search.
Of course the devil is in the details and that is why I'm asking this question. What is the most efficient method to identify if there is a point inside the cube? If this is a classical problem, what is it called?

Using a spatial index to find points within range of each other

I'm trying to find a spatial index structure suitable for a particular problem : using a union-find data structure, I want to connect\associate points that are within a certain range of each other.
I have a lot of points and I'm trying to optimize an existing solution by using a better spatial index.
Right now, I'm using a simple 2D grid indexing each square of width [threshold distance] of my point map, and I look for potential unions by searching for points in adjacent squares in the grid.
Then I compute the squared Euclidean distance to the adjacent cells combinations, which I compare to my squared threshold, and I use the union-find structure (optimized using path compression and etc.) to build groups of points.
Here is some illustration of the method. The single black points actually represent the set of points that belong to a cell of the grid, and the outgoing colored arrows represent the actual distance comparisons with the outside points.
(I'm also checking for potential connected points that belong to the same cells).
By using this pattern I make sure I'm not doing any distance comparison twice by using a proper "neighbor cell" pattern that doesn't overlap with already tested stuff when I iterate over the grid cells.
Issue is : this approach is not even close to being fast enough, and I'm trying to replace the "spatial grid index" method with something that could maybe be faster.
I've looked into quadtrees as a suitable spatial index for this problem, but I don't think it is suitable to solve it (I don't see any way of performing repeated "neighbours" checks for a particular cell more effectively using a quadtree), but maybe I'm wrong on that.
Therefore, I'm looking for a better algorithm\data structure to effectively index my points and query them for proximity.
Thanks in advance.
I have some comments:
1) I think your problem is equivalent to a "spatial join". A spatial join takes two sets of geometries, for example a set R of rectangles and a set P of points and finds for every rectangle all points in that rectangle. In Your case, R would be the rectangles (edge length = 2 * max distance) around each point and P the set of your points. Searching for spatial join may give you some useful references.
2) You may want to have a look at space filling curves. Space filling curves create a linear order for a set of spatial entities (points) with the property that points that a close in the linear ordering are usually also close in space (and vice versa). This may be useful when developing an algorithm.
3) Have look at OpenVDB. OpenVDB has a spatial index structure that is highly optimized to traverse 'voxel'-cells and their neighbors.
4) Have a look at the PH-Tree (disclaimer: this is my own project). The PH-Tree is a somewhat like a quadtree but uses low level bit operations to optimize navigation. It is also Z-ordered/Morten-ordered (see space filling curves above). You can create a window-query for each point which returns all points within that rectangle. To my knowledge, the PH-Tree is the fastest index structure for this kind of operation, especially if you typically have only 9 points in a rectangle. If you are interested in the code, the V13 implementation is probably the fastest, however the V16 should be much easier to understand and modify.
I tried on my rather old desktop machine, using about 1,000,000 points I can do about 200,000 window queries per second, so it should take about 5 second to find all neighbors for every point.
If you are using Java, my spatial index collection may also be useful.
A standard approach to this is the "sweep and prune" algorithm. Sort all the points by X coordinate, then iterate through them. As you do, maintain the lowest index of the point which is within the threshold distance (in X) of the current point. The points within that range are candidates for merging. You then do the same thing sorting by Y. Then you only need to check the Euclidean distance for those pairs which showed up in both the X and Y scans.
Note that with your current union-find approach, you can end up unioning points which are quite far from each other, if there are a bunch of nearby points "bridging" them. So your basic approach -- of unioning groups of points based on proximity -- can induce an arbitrary amount of distance error, not just the threshold distance.

Algorithm and data representation to query point density

If I have a set of points on a 2D plane (x, y) and I want to be able to find the place on that plane where the points are most densely clustered, what algorithm could I use and what would be an appropriate way to store those data points (e.g. some form of tree maybe?). I understand that 'most dense' could probably be calculated in different ways but I'm open to various interpretations (e.g. most points within a given radius).
I'd like to query and adjust the points that are on the plane in real-time: I'll happily take a hit on the time it takes to add and remove points as long as the lookup time is fast.
And forgive me, maybe my question is too vague. If so, I'd welcome pointers to how you can generally query a 'density map' (and whether that is the right term?).

Find the Best fit plane from a list of 3D coordinates

I would like to find the best fit plane from a list of 3D points. It means the plane has the least square distance from all the points. I read the article
Best fit plane by minimizing orthogonal distances
and
3D Least Squares Plane
I fully understand the solutio but it turns other to be impractical in my situation. I need to read a very very large list of 3d points, direcltly impementation would result in ill posed problem. Even I subtract the data with their average,(refere to the document here-> part3 : http://www.geometrictools.com/Documentation/LeastSquaresFitting.pdf) the number is still very large. So what can I do?
Is there an iterative way to implement it ?
I have changed the way to ask the question, I hope may be there are someone can give me more advices on it ?
Given a list of 3D Points
{(x0,y0,z0),
(x1,y1,z1)...
(xn-1,yn-1,zn-1)}
I would like to construct a plane by fitting all the 3D points. In this sense, I mean to find the plane with format (Ax+By+Cy+D = 0), thus its uses four parameters(A,B,C,D) to characterize a plane. The sum of distance between each point and the plane should be minimium.
I do try the menthod provided in the below link
http://www.geometrictools.com/Documentation/LeastSquaresFitting.pdf
But there are two problems:
-During calculation, the above algorithm needs to do summation of all points value, which lead to overflow problem if my number of points increases
-given newly added points, it has to do all the calculation again, is there a way to use the before calculated plane parameter and the newly given points to somehow fine tune the planes parameters?
PS:I am a bit greedy, if we need to involve all the points, it is possible that the plane finally obtained isn't good enough.I am thinking of using random sample consensus(RANSAC), is it the right direction?
If you are expecting a plane then most of the points are not that useful since even a handful should give you a good approximation of the final solution (module a bit more noise).
So here's the solution. Sample down your data set to something that works and run the smaller set through the fitting algorithm.
If you are not expecting that the points are on a plane then sub-sampling should still work, but you must consider error ranges for any solution (since they will likely be fairly big).

How do I distribute 5 points evenly onto an irregular shape?

Here is a problem I am trying to solve:
I have an irregular shape. How would I go about evenly distributing 5 points on this shape so that the distance between each point is equal to each other?
David says this is impossible, but in fact there is an answer out of left field: just put all your points on top of each other! They'll all have the same distance to all the other points: zero.
In fact, that's the only algorithm that has a solution (i.e. all pairwise distances are the same) regardless of the input shape.
I know the question asks to put the points "evenly", but since that's not formally defined, I expect that was just an attempt to explain "all pairwise distances are the same", in which case my answer is "even".
this is mathematically impossible. It will only work for a small subset of base shapes.
There are however some solutions you might try:
Analytic approach. Start with a point P0, create a sphere around P0 and intersect it with the base shape, giving you a set of curves C0. Then create another point P1 somewhere on C0. Again, create a sphere around P1 and intersect it with C0, giving you a set of points C1, your third point P2 will be one of the points in C1. And so on and so forth. This approach guarantees distance constraints, but it also heavily depends on initial conditions.
Iterative approach. Essentially form-finding. You create some points on the object and you also create springs between the ones that share a distance constraint. Then you solve the spring forces and move your points accordingly. This will most likely push them away from the base shape, so you need to pull them back onto the base shape. Repeat until your points are no longer moving or until the distance constraint has been satisfied within tolerance.
Sampling approach. Convert your base geometry into a voxel space, and start scooping out all the voxels that are too close to a newly inserted point. This makes sure you never get two points too close together, but it also suffers from tolerance (and probably performance) issues.
If you can supply more information regarding the nature of your geometry and your constraints, a more specific answer becomes possible.
For folks stumbling across here in the future, check out Lloyd's algorithm.
The only way to position 5 points equally distant from one another (other than the trivial solution of putting them through the origin) is in the 4+ dimensional space. It is mathematically impossible to have 5 equally distanced object in 3D.
Four is the most you can have in 3D and that shape is a tetrahedron.

Resources