Cartesian to Latitude/Longitude - geometry

I have a 3D model of a 10km x 10km topographic map which I've imported from sketch-up , the model is just a bunch of X,Y,Z points (where X+ is the north and Z+ is straight up, perpendicular to the ground)
I know the Latitude Longitude values of the (0,0,0) point. So given a X,Y,Z point how do I get its Latitude Longitude values?
I need to be pretty accurate so you can't assume the earth is a perfect sphere (you can however assume it's an ellipsoid)

For best accuracy you need to know what map projection the map was drawn in. You should be able to find that out from the map. For example in the UK the Ordnance Survey maps use the OSGB36 datum, and the projection is Transverse mercator. The projection tells you how to convert geographic (lat,long for the datum ellipsoid) coordinates to map coordinates (easting and northing) and how to do the reverse calculation, which is pretty much what you want.
If you don't know the projection, the next best thing would be if you could find out -- again from the map, they are often written on it -- the scale-factor and convergence of the projection at some points on the map. The point is that there is usually a slowly spatially varying difference between map north (the direction the north axis points in) and true north (the direction of the north pole from a point, the direction of the latitude axis) and there is always a slowly spatiallty varying scale factor, the ratio of a distance in map coordinates and the true distance. Note that this not the same thing as the scale of the printed map (an inch to a mile or whatever), it is a property of the projection.
Over a 10km square, it would be reasonably accurate to treat both the scale and convergence as constants. Then given an x,y point you compute the map bearing from 0,0 using
b = atan2(x,y)
and convert this to a true bearing by subtracting the convergence.
You also compute the map distance by
r = hypot(x,y)*S
where S is the scale of the map, e.g. if your a change of 1 in x coordinates represents a distance of 100m, S is 100
and convert r to a true distance by dividing by the scale-factor.
Finally you want to compute the lat,long a given distance and bearing from a given point (the lat,long of 0,0). An accurate way to do this is to use Vincenty's formulae.
One thing to note here is that the scale and convergence, if quoted on the map will be relative to the ellipoid used in construction of the map, so you will be computing lat,long coordinates for that ellipsoid.

Related

Compute points at a given geodesic distance on a mesh

Repeating this question for better visibility. I have a triangular mesh (assume a manifold mesh). I want to sample corners of a square on a mesh that is independent of the triangulation.
I am following these steps
Sample a triangle (based on the areas of the triangles)
Sample a point uniformly on the triangle/face
Sample a pair of random perpendicular directions
I want to calculate the distance of three other corners of the square given an edge length. Since the corners can be on any other face, the output should be of the format (Face, barycentric coordinates on that face).
I am looking at libraries such as Polyscope or pygeodesic that use the heat method to compute the geodesic distance between two vertices of the mesh, but I am not sure how to get points at an arbitrary geodesic distance from another point.

Finding the Dimension of OBJ objects

I am having a Three OBJ file, Cone, Sphere and Cube. How can I find the dimension of these objects, so that I can use it in my collision detection class?
i.e How can I find Radius, Length of Cube and Radius and Height of cone? Or is there any better way for collision detection, I have hundreds of random particle in my game which may or may not collide with these objects.
Length of the cube would be the distance of two consecutive points in one face.
If by radius of a cube you mean its diagonal it would be sqrt{3} of its length.
For a sphere, you can find its center by averaging all the vertices.
Its radius would be the distance between any vertex and the center.
It works fine if the sphere is not high resolution.
Otherwise, you have to solve a system of equations to find the sphere that passes through four points. You can take a look at this:
https://www.quora.com/How-do-you-find-the-center-and-radius-of-a-sphere-given-any-four-arbitrary-points-x_1-y_1-z_1-x_2-y_2-z_2-x_3-y_3-z_3-x_4-y_4-z_4
For the cone: there is probably one vertex that is connected to all other vertices. This vertex is probably easy to find for you. Let's call that p.
Take three vertex other than p. Find the circle passing through those vertices. Call that c. The distance between p and c is the height. The distance between c and any vertex other than p would be the radius. To find the circle passing through three points, you again need to solve a system of equations with three unknowns. As the equation of a circle is (x-a)^2+(y-b)^2=r^2. You need to put the values of your three points in the equation and find a,b, and r. Note that this equation assumes that the circle is in 2D. To use it for 3D, you need to first find the plane passing through these three points. If you do not want to go through all these. you can again average all vertices except p and find the center of the circle. the radius would be the distance between the center and any point. I actually assumed that the circles and spheres in your input are uniformly sampled which is the case for most of the available Obj files for these shapes.

Finding two points' center of mass on a sphere (k-means on a sphere)

Please, help me to solve subproblem in my programming task (k-means clustering on a sphere).
Suppose the Earth is a sphere. And there are two points (we know their latitudes and longitudes) with masses m_1 and m_2 on it.
The problem is to find latitude and longitude of these two points' center of mass on a sphere, if the distance is measured as the great-circle distance.
You want to find a point that lies on the great circle arc at distance
l = L * m1 / (m1 + m2)
from the first point, where L is full distance between points.
You can use or
spherical linear interpolation : translate spherical coordinates to Descartes' coordinate system, work with vectors, translate back
or
geodesic approach - find bearing from the first point to the second, find distance L, and move distance l with bearing found. All formulae are at this page: Destination point given distance and bearing from start point

How to find points in a certain distance to a Latitude/Longitude Coordinate

I'm working with Latitude/Longitude Coordinates and i'm trying to find an equation for a circle on the surface that includes all points that have a certain distance(on the surface) from the center.
It's important that this should work also with very big distances (for example half the perimeter of the earth), so the flat-earth approximation probably won't work, but assuming it's a perfect sphere is okay.
Can anybody help?
Thanks in advance!
I have this very same problem.
What I do is to convert the latitude and longitude to Cartesian coordinates fixed at the center of the Earth (which I assume is spherical).
I interpret these coordinates as a mathematical vector.
I also convert the desired "distance from center of circle"
to an angle at the center of the Earth,
that is, if the distance is d then the angle is alpha = d/R
where R is the Earth's radius.
I then find three vectors.
The first vector, v1, is just cos(alpha) times my original vector,
that is, it points from the center of the Earth to the center of my circle
and it has length R*cos(alpha).
The other two vectors, v2 and v3, have length R*sin(alpha),
and they are both perpendicular to v1 and to each other.
I can then get any point on the desired circle by taking
v1 + cos(beta)*v2 + sin(beta)*v3
where beta can range from 0 to 2*pi.
Finally, if I want the latitude and longitude of that point,
I convert it back from Cartesian coordinates.
If you never actually care about the Cartesian coordinate model but will
instead use only the latitudes and longitudes that result,
you can simplify the procedure slightly by assuming R == 1.
You can then simplify the formulas so that you never have to define
the variable R.
The coordinate conversions in either direction can be fairly straightforward.
An easy way to find vector v2 is to take the x and y coordinates of v1
(ignoring z), rotate the resulting vector 90 degrees in the x-y plane
(so if you started with (x,y,z), the new vector is (-y,x,0)),
and then scale the vector to the desired size.
Of course if the x and y coordinates of v1 are zero then you can
let v2 be any vector in the x-y plane.
To get v3 you can take the cross product of v1 and v2 and scale
as desired.

Decimal "constant" for lat and long in miles

Understanding that it would only be an estimate...
How what decimal constant would be able to be used to find a point X Miles away from a point in latitude and longitude to facilitate creating a lat long bounding box.
Unfortunately there is no such simple constant. As you go farther north, the "walking distance" between lines of longitude becomes smaller and smaller. If you were right next to the north pole, you could walk in a circle around it, covering almost no distance at all, and yet you'd still have touched every line of longtiude.
What you need is the great-circle distance between two points on a sphere.
Not sure what you are trying to do. You want a create a bounding box based on distance from a point? Are you looking for a way to calculate new lat/long from given lat/long using a distance in miles?
You can use the manhattan function to get an approximation of distance (realizing that lat/long are based on a spheroid approximating the earth, and truly calculating this requires more math), calculating x and y values with a forumla to follow
Manhattan function:
sqrt(x*x + y*y)
X and Y from Lat/Long:
x = 69.1 * (lat2 - lat1)
y = 53 * (lon2 - lon1)
Still, that method is pretty error-prone.
There's the great circle distance formula too, gotta use some trig for it, but it's probably worth it since you can get pretty good error in approximation depending upon what part of the spheroid (e.g. the lat/long) you start at.
Check out this page:
http://www.meridianworlddata.com/Distance-Calculation.asp

Resources