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.
Related
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.
I'm trying to figure out what is the best way to calculate the overlap area of two arbitrary polygons in Java.
Here's the research I've done so far:
I've read the documentation of Area class (from java.awt.geom). It doesn't seem to support this option.
I've tried looking at other classes that may support this, and were offered in other similar occasions (classes that implement Shape interface for example). None of them seemed to have this option.
I am aware that there are 3rd party modules that support this, but I'm looking for one with free license for every use (including commercial use).
Some more details about the Polygons:
The only assumption about the polygons is that they are "simple" - i.e - not containing any holes.
Polygons are given as a list of coordinates. I also have the Area and GeneralPath objects that represents them.
Is there any way to achieve this task in Java without downloading external libraries?
The only solution I thought of this far is to create for both a set of inner points by finding the bounding rectangle, and using Area's contain function, and then finding the union of both of these sets. The problem with this solution is that it's very inefficient.
You need polygon clipping algorithm suitable for non-convex polygons. Some known algorithms:
Vatti's algorithm, works with arbitrary polygons, including complex, used in Clipper library
Weiler-Atherton algorithm
Greiner-Hormann algorithm , page has links to some implementations
I've been writing a program to graph datapoints in Java. I need a lots of flexibility and speed so I don't want to use an existing library as much as possible. Right now, it essentially uses Graphics2D to draw lines and dots representing the points in a file of data.
My problem is, some of my datasets have upwards of 100,000 points.When it is going to be rendered with all full drag/zoom functionality, it is getting quite slow.
My question is, how can I reduce this dataset or make a simplification of it so that I can display the graph without changing the overall shape?
I could only draw every third point, for instance, but what if that skipped over and didn't display an important outlier? I could try averaging groups of points, but that could have the same problem.
And for services like Google Finance, where they probably have millions of points to display, how do they deal with this?
You may want to check for range differences between points before rendering them. Give them a threshold that they need to stay within in order to not be re-rendered.
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".
I have thousands of data points and each data point has 50 dimensions. I would like to see the sparseness of data using java. Is there any java package/methods to plot such high dimensional data.
What you need to look for is multidimensional scaling. It basically reduces the dimensionality of the data space, trying to maintain the distances.
So you take a MDS package, reduce your data to 2D (or 3D) and plot them using 2D/3d graphics library (swing, jogl).
It might work or not, depending on the number of the data points and the space they're in. For 50 dimensions you might be out of luck, but it really depends.
A quick google for java implementation got me this
There's a package in R too, so you can use that.