How to get GPS coordinates of the centre of an rectangular area? - geometry

I have 4 GPS points that form the boundaries of a marine area. I need to know the GPS coordinates of the centre of this area, to use it as a basis for calculating the distance to other marine areas. To do this I was thinking of calculating the distances of the diagonals separating the GPS points of my area to obtain a centre point, but I am stuck on the method and the choice of the package to use to obtain the GPS coordinates of the centre of the area. Does anyone have an idea? Thanks in advance
(PS: I already tried to use marmap, but the study area is too small)
library(geosphere)
coor_zone <- c(3.15917,3.1725, 42.46783, 42.47033, 3.1745, 3.16033, 42.4655, 42.4625)
matrice_coord_zone <- matrix(coor_zone, nrow=2, ncol = 4)
colnames(matrice_coord_zone) <- c("long1", "lat1","long2", "lat2")
matrice_coord_zone <- data.frame(matrice_coord_zone)
matrice_coord_zone$distance <- distHaversine(matrice_coord_zone[,1:2], matrice_coord_zone[,3:4])
# result
long1 lat1 long2 lat2 distance
1 3.15917 42.46783 3.17450 42.4655 1285.298
2 3.17250 42.47033 3.16033 42.4625 1326.077

Related

Why does the projection of an image over 3d points show this distortion?

I have a question regarding the projection of an image over a set of 3D points. The image is given to me as a JPG, together with position and attitude information of the camera relative to a cartesian coordinate system (Xc,Yc,Zc and yaw, pitch, roll), as well as the horizontal and vertical field of view (in degrees).
Points are given using solely their 3d position in the same coordinate system (Xp,Yp,Zp).
In my coordinate system, Z is up. To project the image onto the points, I
compute the vector from camera to each point
Vector3 c2p = (Xp,Yp,Zp)-(Xc,Yc,Zc);
rotate c2p according to my camera's attitude (quaternion):
Vector3 c2pCamFrame = getCamQuaternion().conjugate().rotate(c2p);
compute azimuth and elevation from the camera's "center ray" to the point:
float azimuth = atan2(c2pCamFrame.x(),c2pCamFrame.y()));
float elevation = atan2(c2pCamFrame.z(),sqrt(pow(c2pCamFrame.x(),2)+pow(c2pCamFrame.y(),2)));
if azimuth and elevation are within the field of view, I assign the color of the corresponding pixel to the point.
This works almost perfectly, and the "almost" motivates my question. Let me show you:
I cannot figure out why the elevation of the projection is distorted. In the bottom right of the image, you can see that points outside the frustum (exceeding the elevation) actually become colored - and this distortion is null at an azimuth of 0 degrees and peaks at the left and right edges of the image, creating the pillow distortion.
Why does this distortion appear? I'd love to understand this problem both in geometrical as well as mathematical terms. Thank you!
The field of view angles are only valid on the principal axes. But you can do it the other way around. I.e. calculate the x/y bounds from the angles:
maxX = tan(horizontal_fov / 2)
maxY = tan(vertical_fov / 2)
And check
if(abs(c2pCamFrame.x() / c2pCamFrame.z()) <= maxX
&& abs(c2pCamFrame.y() / c2pCamFrame.z()) <= maxY)
Additionally, you might want to check if the points are in front of the camera:
... && c2pCamFrame.z() > 0
This assumes a left-handed coordinate system.

Geometry of a radial coordinate to Cartesian with bounding points

I need to find 4 points in Latitude/Longitude format surrounding a given center point and a resulting algorithm (if possible).
Known information:
Equal distances for each "bin" from center of point (Radar) outward.
Example = .54 nautical miles.
1 Degree beam width.
Center point of the "bin"
This image is in Polar coordinates (I think this is similar to Radial coordinates???):
I need to convert from Polar/Radial to Cartesian and I should be able to do that with this formula.
x = r × cos( θ )
y = r × sin( θ )
So now all I need to do is find the "bin" outline coordinates (4 corners) so I can draw a polygon in a Cartesian coordinate space.
I'm using Delphi/Pascal for coding, but I might be able to convert other languages if you have a sample algorithm.
Thanks for any suggestions or sample algorithms.
Regards,
Bryan
You need to convert everything to the same coordinate system and then impose the distance criteria as follows:
Convert your center point from geographic coordinates to polar coordinates to yield (rC, θC)
Convert your center point from polar to Cartesian coordinates using your equations yielding (xC, yC)
The corner points on the right side of the center points (xR, yR) satisfy the equation
(xR - xC)2 + (yR - yC)2 = D2
[rRcos(θC+0.5o) - xC]2 + [rRsin(θC+0.5o) - yC]2 = D2
where D=distance between the center point and corner points
Everything is known in the above equation except rR. This should yield a quadratic equation with two solutions which you can easily solve. Those are your two corner points on the right side.
Repeat step 3 with angle θC-0.5o to get the corner points on the left side.

finding value of a point between measured points on a 2D plane

I'm trying to find the best way to calculate this. On a 2D plane I have fixed points all with an instantaneous measurement value. The coordinates of these points is known. I want to predict the value of a movable point between these fixed points. The movable point coodinates will be known. So the distance betwwen the points is known as well.
This could be comparable to temperature readings or elevation on topography. I this case I'm wanting to predict ionospheric TEC of the mobile point from the fixed point measurements. The fixed point measurements are smoothed over time however I do not want to have to store previous values of the mobile point estimate in RAM.
Would some sort of gradient function be the way to go here?
This is the same algorithm for interpolating the height of a point from a triangle.
In your case you don't have z values for heights, but some other float value for each triangle vertex, but it's the same concept, still 3D points.
Where you have 3D triangle points p, q, r and test point pt, then pseudo code from the above mathgem is something like this:
Vector3 v1 = q - p;
Vector3 v2 = r - p;
Vector3 n = v1.CrossProduct(v2);
if n.z is not zero
return ((n.x * (pt.x - p.x) + n.y * (pt.y - p.y)) / -n.z) + p.z
As you indicate in your comment to #Phpdevpad, you do have 3 fixed points so this will work.
You can try contour plots especially contour lines. Simply use a delaunay triangulation of the points and a linear transformation along the edges. You can try my PHP implementations https://contourplot.codeplex.com for geographic maps. Another algorithm is conrec algorithm from Paul Bourke.

How to calculate a circle's latitude/longitude bounding rectangle?

I have a database with latitudes and latitudes.
I want to retrieve all points that are within 1 mile of a given lat/lng point on planet Earth.
I'll do this in two steps: first retrieving the points that are within the circle's bounding rectangle, to take advantage of database indexing, then calculating the exact distances to every candidate point to filter down to the proper results.
Great Arc Distance is a well-known algorithm for calculating distance from two given lat/lng points.
But how can I calculate a 2nd lat/lng given a lat/lng and a distance?
What have I tried
Google leads me to Great Arc Distance. See above paragraph.
You should uses the haversine formula to calculate the great-circle distance between two points, you got a starting point and the distance which is 1 mile.
Haversine formula:
a = sin²(Δlat/2) + cos(lat1).cos(lat2).sin²(Δlong/2)
c = 2.atan2(sqrt(a), sqrt(1−a))
d = R.c
where :
- R is earth's radius (`mean radius = 6,371km`);
- Δlat = lat2 - lat1
- Δlong = long2 - long1
- atan2(y,x) = arc tan(y/x)
- d = 1 mile
or you can use the Equirectangular approximation which is much easier :
x = Δlong.cos(lat)
y = Δlat
d = R.sqrt(x² + y²)
So what you have is the distance d=1 and the starting point let say (lat1 , long1) so you have to solve the equation and get all the pairs (lat,long) that verify your equation.
Enjoy.
Perhaps you should hire a developer? Since your "question" is more like a work request you'd see on sites such as oDesk than it is like a question that helps you solve a problem you are facing after actually doing some work yourself...
Besides, what does "1mile" mean by itself? (answer = nothing)
You really need to supply, along with a DISTANCE of 1 (in miles), a REFERENCE POINT! And the fact you don't know/realise that supports the suggestion:you should hire someone to do this.
Lol.

Convert 3D(x,y,z) to 2D(x,y) (orthogonal) along its direction

I have gone through all available study resources in the internet as much as possible, which are in form of simple equations, vectors or trigonometric equations.
I couldn't find the way of doing following thing:
Assuming Y is up in a 3D world.
I need to draw two 2D trajectories orthogonally (not the projections) for a 3D trajectory, say XY-plane for side view of the trajectory w.r.t. the trajectory itself and XZ-plane for top view for the same.
I have all the 3D points of the 3D trajectory, initial velocity, both the angles can be calculated by vector mathematics.
How should I proceed further?
refer:
Below a curve in different angles, which can loose its significance if projected along XY-plane. All I want is to convert the red curve along itself, the green curve along green curve and so on. and further how would I map side view to a plane. Top view is comparatively easy and done just by taking X and Z ordinates of each points.
I mean this the requirement. :)
I don't think I understand the question, but I'll answer my interpretation anyway.
You have a 3D trajectory described by a sequence of points p0, ..., pN. We are given an angle v for a plane P parallel to the Y-axis, and wish to compute the 2D coordinates (di, hi) of the points pi projected onto that plane, where hi is the height coordinate in the direction Y and di is the distance coordinate in the direction v. Assume p0 = (0, 0, 0) or else subtract p0 from all vectors.
Let pi = (xi, yi, zi). The height coordinate is hi = yi. Assume the angle v is given relative to the Z-axis. The vector for the direction v is then r = (sin(v), 0, cos(v)), and the distance coordinates becomes di = dot(pi, r).

Resources