Collision / distance to volumes from point in OpenGL ES on Android - java

is user inside volume OpenGL ES Java Android
I have an opengl renderer that shows airspaces.
I need to calculate if my location already converted in float[3] is inside many volumes.
I also want to calculate the distance with the nearest volume.
Volumes are random shapes extruded along z axis.
What is the most efficient algorithm to do that?
I don t want to use external library.

What you have here is a Nearest Neighbor Search problem. Since your meshes are constant and won't change, you should probably use a space partioning algorithm. It's a big topic but, in short, you generally need to use a tree structure and sort all the objects to be put into various tree nodes. You'll need to pre-calculate the tree itself. There are plenty of books and tutorials on the net about space partioning, and you could also at source code of, for example, id Software products like Doom, Quake etc. to see how this algorithms (BSP, at least) are used. The efficiency of each algorithm depends on what you have and what you need. Using BSP trees, for example, you'll have the objects sorted from nearest to farthest so you can quickly get the one you need.

Related

Java library to find all polygons containing a point

I have to store a set of 2D polygons in memory (less than 1000) in a structure which allows to find efficiently the ones containing a point. Polygons never change and contain about 10 points.
I have to launch the query about 10000 times per second.
I guess a structure using quad trees or similar and bounding boxes of the polygons would do this as I need.
Does anybody know a free java library offering this service ?
I don't think there's such a service, but as a structure you can use https://docs.oracle.com/javase/8/docs/api/java/awt/Polygon.html. You even have a method to check for point inclusion.

The lightest JavaFX container for Polygon

Due to the lack of easily accessible and readable libraries or methods for two-dimensional contour plotting in Java 8 environment, I decided to write such functionality myself. My solution is based on the approach described here and it can be summed up as follows:
I create a rectangular container with specific layoutX and layoutY describing its position on the contour map. I draw in this container appropriate polygon depends on the ternary index assigned to the aforementioned container.
Taking into account, that each container is created for four data values from given dataset, it is easy to calculate, that for matrix with size of [11,11] there will be 10^2 containers, but for matrix with size of [1001, 1001] it will be 10^6.
In this case, it is necessary to choose appropriate container for polygon, in order to optimize plotting for larger datasets as much as it is possible.
Which container should I choose in order to provide best execution times for the creation of contour map based on the assumptions described above?
The lites container is probably a Group or no container at all if you just apply the appropriate transform to your Polygon. But I don't understand why you are actually looking for this. The algorithm that you linked to is for computing iso-lines but is not efficient to use the same setup to display the result of this computation.

Lookup algorithm that returns regions?

I have a large list of regions with 2D coordinates. None of the regions overlap. The regions are not immediately adjacent to one another and do not follow a placement pattern.
Is there an efficient lookup algorithm that can be used to let me know what region a specific point will fall into? This seems like it would be the exact inverse of what a QuadTree is.
The data structure you need is called an R-Tree. Most RTrees permit a "Within" or "Intersection" query, which will return any geographic area containing or overlapping a given region, see, e.g. wikipedia.
There is no reason that you cannot build your own R-Tree, its just a variant on a balanced B-Tree which can hold extended structures and allows some overlap. This implementation is lightweight, and you could use it here by wrapping your regions in rectangles. Each query might return more than one result but then you could check the underlying region. Its probably an easier solution than trying to build a polyline-supporting R-tree version.
What you need, if I understand correctly, is a point location data structure that is, as you put it, somehow the opposite of quad or R-tree. In a point location data structure you have a set of regions stored, and the queries are of the form: given point p give me the region in which it is contained.
Several point location data structures exists, the most famous and the one that achieves the best performance is the Kirkpatrick's one also known as triangulation refinement and achieves O(n) space and O(logn) query time; but is also famous to be hard to implement. On the other hand there are several simpler data structures that achieves O(n) or O(nlogn) space but O(log^2n) query time, which is not that bad and way easier to implement, and for some is possible to reduce the query time to O(logn) using a method called fractional cascading.
I recommend you to take a look into chapter 6 of de Berg, Overmars, et al. Computational Geometry: Algorithms and Applications which explains the subject in a way very easy to grasp, though it doesn't includes Kirkpatrick's method, which you can find it in Preparata's book or read it directly from Kirkpatrick's paper.
BTW, several of this structures assumes that your regions are not overlapping but are expected to be adjacent (regions share edges), and the edges forms a connected graph, some times triangular regions are also assumed. In all cases you can extend your set of regions by adding new edges, but don't you worry for that, since the extra space needed will be still linear, since the final set of regions will induce a planar graph. So you can blindly extend your sets of regions without worrying with too much growth of space.

Android Algorithm for find all Geopoints within a given distance

In my naive beginning Android mind I thought the way to do this would be to loop through each of the objects checking if proximity falls within X range and if so, include the object. This is being done with Google Maps and GeoPoints.
That said, I know this is probably the slowest way possibly. I did a search for Android Proxmity algorithm's and did not get much really. What I am looking for is best options with regard to this the more efficiently.
Are there any libraries I have not been able to find?
If not, should I load these Location objects into SQL then go from there or keep them in a JSONArray?
Once I establish my best datastructure, what is he best method to find all Locations located with X miles of user?
I am not asking for cut and paste code, rather the best method to this efficiently. Then, I can stumble through the code :)
My first gut feeling is to group the Locations by regions but I'm not exactly sure how to do this.
I could potentially have tens of thousands of datapoints.
Any help in simply heading in the right direction is greatly appreciated.
As a side note, I reach this juncture after discovering that a remote API I had been using was.. well.. just PLAIN WRONG and ommiting datapoints from my proximity search. I also realized that if just placed on the datapoints on the phone, then I could allow the user to run the App without internet connection, and only GPS and this would be a HUGE plus. So, with all setbacks come opportunnities!
The answer depends on the representation of the GeoPoints: If these are not sorted you need to scan all of them (this is done in linear time, sorting wrt. distance or clustering will be more expensive). Use Location.distanceTo(Location) or Location.distanceBetween(float, float, float, float, float[]) to calculate the distances.
If the GeoPoints were sorted wrt. distance to your position this task can be done much more efficiently, but since the supplier does not know your position, I assume that this cannot be done.
If the GeoPoints are clustered, i.e. if you have a set of clusters with some center and a radius select each cluster where the distance from your position to the cluster's center is within the limit plus the radius. For these clusters you need to check each GeoPoint contained in the cluster (some of them are possibly farther away from your position than the limit allows). Alternatively you might accept the error and include all points of the cluster (if the radius is relatively small I would recommend this).

How to find nearest City of out of a selected set

I need to get the nearest city out of a selected set of cities.
Our company has a list of subsidiaries (some 100 in my country). We get around 3000 requests a day. This requests should be assigned to the subsidiaries (by geographical distance).
Is there an API to do this?
The best would be a (java) GoogleMaps API or similar webservice.
Best Regards,
Christian.
What I would do is to construct a Voronoi diagram of your subsidiaries, based on geographical distance and store that diagram in the form that can be used in your code. Then, look for the containing cell for each request and that will tell you which subsidiary is the closest one.
If you really want to make it precise, you could use OSM's road network to construct the diagram based on the driving distance, not simply geographical one.
Get the coordinates from Nominatim, it should be straight forward to make requests from a java application.
Calculate the great circle distance for every city to every city. I have to admit that the result might by an 300 by 300? array. However it may contain only integer. Hold it in memory for future requests.
Find the entry with the lowest number in the row or column.
Bit of an old question and maybe too late an answer for you.
A good approximation for speed concerns where absolute precision is not of the essence is to draw a rectangle around a point (the one you need to find the closest subsidiaries here). That rectangle would natively have NE and SW coordinate boundaries (or NW/SE).
To find the closest subsidiaries, ones need to find all of which the NE coordinate is "less" than that of the rectangle and "more" than that of the SW boundary.
I am quoting "more" and "less" because they might mean differently based of where on earth you are.
I wrote https://github.com/grumlimited/geocalc for my own need a few years back. Take a look at the section about names "BoundingArea".

Categories

Resources