In python I am busy calculating the closest point of approach between two aircraft for which I have radar point coordinates AND the speed vectors.
To test the algorithm, I am setting up some standard positions and speed vectors and calculate the closest point of approach.
To study the result, I want to create in Plotly Express:
the two starting points
the two speed vectors of the aircraft, each represented by an arrow from their starting point.
a line between the two paths at the location of the closest point of approach. The two points could each be (probably) on the extended line of the initial speed vectors.
Why Plotly Express? Because you can move and swivel around them to investigate.
I had it working in Matplotlib, but then I cannot move around them to study the interaction in 3D.
Related
I have the coordinates of curves in 3D space (point curve). The pairs of these curves lie in each other or have pretty much the same coordinates for a while until they branch off. I want to find the point where the two curves branch off of each other or the best estimate of that point.
I tried to find the closest distance along the points of the two curves and then look when this distance is higher than a certain small threshold which I estimated experimentally. This works, however, only roughly to find the splitting point and differs from pair to pair of my curves.
I guess a good solution would be to interpolate both point curves with (cubic) splines with scipy or splipy and then calculate the (last) intersection point of these two curves. I don't know how to do that though.
Example picture of two point curves
Splitting Point I am searching for
Thanks for the help!
I’m trying to write an algorithm in python to create automatically polygons (cluster of exagons maybe) that have same “fall to ground” orders in a certain amount of time (i have a quite huge amount of geo data about it order: DATE,latitude,longitude, product ordered)
I need it to assign proper coverage to stores managing the avg number of orders per sore according to given properties.
So I need to be able to define polygons with equal probability of being the place of an e-commerce order and later be able to cluster them around a store and merging intona single polygon
I have no clue on how to set up the process.
U have some suggestion? Thanks
Generate a hexagonal grid, clip grid to the research area, aggregate point data using the Spatial Join/Spatial Index function or your custom metric for Hexagonal geometric grid.
To achieve this can use the h3 and geopandas python library or the GIS software.
Result like this:
Advantages of using the Hexagonal grid:
Finding neighbors is easier with the hexagonal grid. For a rectangular grid, we have 4
neighbors N units away and N^2 apart in a hexagonal grid the distances are equal to
each of the six neighbors.
Hexagons reduce the sample bias due to the grid shape boundary effects, which is related to
a low ratio of the circumference to the area of the hexagon (a circle would be best but cannot be used).
Over a large area, the hexagonal grid will be less distorted due to the curvature of the earth than the grid rectangular.
When comparing polygons with equal areas, each point inside the hexagon is closer to the center
hexagon than a given point in a square or triangle with an equal area (this is due to more acute angles
square and triangle in relation to the hexagon).
And more benefits…
When looking for the best place for business, it is also a good idea to do a neighborhood analysis. Result like this:
I currently have 2 paths generated by a motion planning algorithm in Python. I interpolated into two 3D Polylines with equidistant points. Next I need to find whether these two paths of different lengths intersect (OR even ideally the point(s) at which they get near a certain distance of each other, if any). This is to eventually simulate a collision avoidance algorithm.
After much searching I have found multiple libraries and algorithms that can return points/line intersections of two Polylines, however they are all in 2D. I tried using the Bentley-Ottmann algorithm/python library, the Shapely library, the Geometry3D library, and other 2D solutions found on SO, but none have worked in a 3D environment. Next I tried using a 2D geometry library to find the intersections in the x-y, x-z, and y-z planes individually as shown in the graphs below showing a simple case, but I'm not sure where to go from there or whether that's even the right approach. The Polylines would usually contain 300+ points.
Any help pointing me towards a 3D algorithm or simple adjustments to make to the 2D libraries work in 3D would be really appreciated!
3D graph view, x-y view, z-y view.
I have no real experience with GIS data, so when what I believed to be a simple problem has turned out to have more subtleties to it, I am dangerously unprepared!
I want to be able to classify a GPS position as inside/outside a polygon defined by GPS co-ordinates. It turns out this is the well-known (but not to me) point-in-polygon problem. I have read many questions/answers on https://gis.stackexchange.com/ (and here e.g. this).
Shapely seems a good solution, but assumes the co-ordinates are on the same cartesian plane, i.e. not GPS? So I would first need to transform my GPS points to UTM points.
Do I need to introduce this extra step, however, if the points being compared (i.e. the point and the polygon) are always going to be naturally within the same UTM zone. They should always be within the same town/city, so can I just leave them as GPS and use the lat/long co-ordinates in Shapely?
I also came across this UTM-WGS84 converter so I could convert my lat/long pairs using this package, and then use those UTM pairs in Shapely, but I would like to avoid any extra dependencies where possible.
Point-in-polygon already assumes a 2D restriction, and GPS coordinates are 3D. Right away, that gets you in trouble.
A simple workaround is to discard the GPS height, reducing it to 2D surface coordinates. Your next problem is that that your 2D surface is now a sphere. On a spherical surface, a polygon divides the surface in two parts, but there is no obvious "inside". There's a left-hand side and a right-hand side which follows from the order of points in the polygon, but neither side is the obvious "inside". Consider the equator as a trivial polygon - which hemisphere is "inside" the equator?
Next up is the issue of the polygon edges. By definition, these are straight, i.e. line segments. But lines on a spherical surface are weird - they're generally known as great circles. And any two great circles cross in exactly two points. That's not how cartesian lines behave. Worse, the equations for a great circle are not linear when expressed in GPS coordinates, because those are longitude/latitude pairs.
I can imagine that at this point you're feeling a bit confused. You might want to look at this from another side - we have a similar problem with maps. Globe maps are by definition attempts to flatten that non-flat surface. Since that's not exactly possible, you end up with map projections. You can also project the corner points of your polygons on such projections. And because the projections are flat, you can draw the edges on the projection. You now see the problem visually: On two different projections, identical polygons will contain different parts of the world!
So, since we agreed that in the real world, the edges of the polygons are great circles, we should really consider a projection that keeps the great circles straight. There's exactly one family of projections that has this property, and that's the Gnomonic projection. It's a family of projections because you can pick any point as the center.
As it happens, we have one natural point to consider here: the GPS point we're considering. If you put that in the center, draw a gnomonic projection around it, project the polygon edges, and then draw the polygon, you have an exact solution.
Except that the actual earth isn't spherical. Sorry. How exact did you need the test to be, anyway?
I have this object/point cloud,rendered with pyopengl and pygame.
My object is a numpy array of the co-ordinates of the point. I wish to generate a 3d triangular mesh of this object, also it would be nice if you could decrease the number of triangles.
I have tried scipy.spatial.Delaunay and it doesnt generate triangles for 3d objects.
Dual Contouring would probably work well here, it's an algorithm that takes voxelized data and turns it into a mesh. I don't understand it trivially enough to outline it here, but basically you'd take your array of points and place them into a 3D grid array where if that grid cell contains a point it's set to equal 1 (full), and if it doesn't it is set to 0 (empty), you would then run the DC algorithm on this grid and it would output a mesh. The nice thing about this algorithm is it supports internal cavities and concave shapes.
Here's some links I found that may help you if you decide to use DC:
Basic Dual Contouring Theory
http://ngildea.blogspot.com/2014/11/implementing-dual-contouring.html
This is the github repo to the source I used when I implemented this algorithm in Unity3D:
https://github.com/nickgildea/DualContouringSample