Why compute geodistance with lat/lon instead of caching cartesean points? - sql

When researching on how to do the classic "get POI in range" problem I've found that the most used algorithms are Haversine and if you need real accuracy then Vincenty's formula. I went the first one because high accuracy wasn't an issue. However, it got me thinking on something that hits me as odd, why is that I found no references to caching the Cartesean coordinates on the database instead of using the haversine formula with the lat/lon?
The issue here is, of course, performance. The haversine formula requires a ton of cos/sin function calls, but wouldn't it be simpler to store the projected X, Y and Z of a lat/lon point on the database and apply the dot product directly? That would require a single arccos call unless I'm mistaken.

Because any given Cartesian projection will only give the correct answer for certain points - a projection which gives the right distance between two points on one particular circle around a sphere will distort distances along another particular circle.
Formulas such as Haversine are independent of the relative locations of the various points on the sphere; they return the correct distance regardless.

No, you are not mistaken. Two things, though. First, obviously, your performance benefits will depend on the nature of your application. If you need to use the same points many times in your calculations, you will improve performance by doing what you suggest.
Second, the formula you use is not the issue here. If you precompute and store sin and cos of lat/lon and use haversine, you will get the exact same performance improvements.

Calculating the distance between two X,Y,Z coordinates will give you the straight line distance (as the arrow flies). The Haversine formula gives the shortest path on the surface of the curved earth (spherical distance). Most geographic software applications need to compute the distance across the earth's surface, thus the Haversine or similar spherical trigonometry algorithms are used.

Related

Scale Bezier Curve

I need to adjust the length of a (cubic) Bezier curve to match that of another one, without disturbing its overall shape. This involves, I guess, proportionately scaling it recursively until the length is of the right magnitude (or is there any better approach?).
I have got the function that calculates the length. For scaling, I am stuck at calculating the coordinates of the new control points. There is this question that seems to have the answer but I am unable to figure out to what the variables a, b etc. refer in the answer. Also, I need to write a function from scratch, without having recourse to any API library (except python math).
Any help is appreciated.
Denoting the length of your curve by L and the desired length D, it seems to me that you just need to scale your curve (D/L)-times. Thanks to affine invariance, it should be enough to scale all your control points. That is, multiply each coordinate of each of your control points by D/L.
Or did I miss something?

Calculating heading value in a quad copter

I'm building an autonomous quad copter I'm trying to move the quad to a target GPS co-ordinate, I'm calculating the distance of the target using haversine formula, and now I want to calculate the heading.
For example, I want the quad to turn to the direction of the target and move forward until it reaches the destination (this part is already done).
How do I calculate the yaw so that it turns to the direction of target?
Calculating it using only the GPS co-ordinates is very inaccurate. If I use a magnetometer, the declination angle changes from place to place.
How do I calculate this? How does ardu pilot do this calculation?
One way to develop control algorithms that deal with inaccurate measures is to combine different measures by some sort of filtering. In that sense, your set point reference is built based on both GPS and magnetometer measures.
There are several ways to accomplish this task. Many applications use data fusion based on Kalman Filters. The general idea is that you are going to use a predictor (or state observer) to achieve a better estimate of the heading. I suggest some research on these topics: data fusion, Kalman filtering.
Here is an example:
http://scholarscompass.vcu.edu/cgi/viewcontent.cgi?article=4188&context=etd

CGAL 3D surface mesh generation for unbounded implicit surfaces

This is again a question about the CGAL 3D surface mesher.
http://doc.cgal.org/latest/Surface_mesher/index.html#Chapter_3D_Surface_Mesh_Generation
With the definition
Surface_3 surface(sphere_function, // pointer to function
Sphere_3(CGAL::ORIGIN, 64.0)); // bounding sphere
(as given too in the example code) I define an implicit surface given by 'sphere function' and a Sphere_3 of radius 8.
The difference is now, that the zeros of 'sphere function' are (contrary to its now misleading name) no longer bounded and inside Sphere_3. Instead 'sphere_function' represents an unbounded surface (think of x^2 + y^2 - z^2 - 1 = 0) and my intention is to triangularize its part that is in the Sphere_3.
In my examples up to now this worked quite well, if only for some annoying problem, I do not know how to overcome: The boundaries, where the implicit surface meets the Sphere, are very "rough" or "jagged" in a more than acceptable amount.
I already tried the 'Manifold_with_boundary_tag()', but it gave no improvements.
One road to improve the output that I am contemplating, is converting the triangulated mesh (a C2t3) into a Polyhedron_3 and this in a Nef_polyhedron and intersect that with a Nef_polyhedron well approximating a slightly smaller Sphere. But this seems a bit like shooting with cannons for sparrows, nevertheless I have currently no better idea and googling gave me also no hint. So my question: What to do about this problem? Can it be done with CGAL (and moderate programming effort) or is it necessary or better to use another system?
(Just for explanation for what I need this: I try to develop a program that constructs 3D-printable models of algebraic surfaces and having a smooth and also in the boundaries smooth triangulation is my last step that is missing before I can hand the surface over to OpenSCAD to generate a solid body of constant thickness).
The only solution I see is to use the 3D Mesh Generation with sharp feature preservation and no criteria on the cells. You will have to provide the intersection of the bounding sphere with the surface yourself.
There is one example with two intersecting spheres in the user manual.

interpolation and projection on geo-spatial data

everyone
recently I am trying to solve the location error generated by GPS, so I came up with an idea of projecting the GPS points to the nearest road, as shown bellow [1]. But I know that indeed earth is not a flat plane and general projection method is not adaptive to this problem. What should I do to deal with the projection problem that exists on sphere to get a better precision?
![1]: http://imgur.com/nL7tB7m
Similarly, when it comes to interpolation between two points, same problem emerged. I did once assume two points were closed so I could ignore the flatness
effect, but failed if their distance was long enough. Regular interpolation method won't give me a better-precision result.
![2]: http://imgur.com/rOSu8gk

Continuous modification of a set of points - find all nearest neighbors

I have a 3D set of points. These points will undergo a series of tiny perturbations (all points will be perturbed at once). Example: if I have 100 points in a box, each point may be moved up to, but no more than 0.2% of the box width in each iteration of my program.
After each perturbation operation, I want to know the new distance to each point's nearest neighbor.
This needs to use a very fast data structure; I'm optimizing this for speed. It's a somewhat tricky problem because I'm modifying all points at once. Approximate NN algorithms are not suitable for this problem.
I feel like the answer is somewhere between kd-trees and Voronoi tessellations, but I am not an expert on data structures, so I am baffled about what to do. I sure this is a very hard problem that would require a lot of research to reach a truly optimal solution, but even something fairly optimal will work for me.
Thanks
You can try a quadkey or monster curve. It reduce the dimension and fills the plane. Microsoft bing maps quadkey is a good start to learn.