Calculate how many boxes and their center coordinate given an area of map - geolocation

I have given a location defined by an area, example is Singapore area. Now I want to divide it into a circle given that each has radius of 50 KM. My objective is to find how many circles do I need to cover all the area of Singapore and what are the circle center coordinate.
Does someone know the formula of it and how do I do it in Python?
I found quite similar example here :
https://codesandbox.io/s/subbounds-8j0p6?file=/src/index.js:722-728
But I do need to know the idea behind it.

Related

Finding point height on a cup using OpenCV

Suppose that I want to find the 3D position of a cup with its rotation, with image input like this (this cup can be rotated to point in any direction):
Given that I have a bunch of 2D points specifying the top circle and bottom circle like the following image. (Let's assume that these points are given by a person drawing the lines around the cup, so it won't be very accurate. Ellipse fitting or SolvePnP might be needed to recover a good approximation. And the bottom circle is not a complete circle, it's just part of a circle. Sometimes the top part will be occluded as well so we cannot rely that there will be a complete circle)
I also know the physical radius of the top and bottom circle, and the distance between them by using a ruler to measure them beforehand.
I want to find the complete 2 circle like following image (I think I need to find the position of the cup and its up direction before I could project the complete circles):
Let's say that my ultimate goal is to be able to find the closest 2D top point and closest 2D bottom point, given a 2D point on the side of the cup, like the following image:
A point can also be inside of the cup, like so:
Let's define distance(a, b) as a function that find euclidean distance from point a and point b in pixel units.
From that I would be able to calculate the distance(side point, bottom point) / distance(top point, bottom point) which will be a scale number from 0 to 1, if I multiply this number to the physical height of the cup measured by the ruler, then I will know how high the point is from the bottom of the cup in metric unit.
What is the method I can use to find the corresponding top and bottom point given point on the side, so that I can finally find out the height of the point from the bottom of the cup?
I'm thinking of using PnP to solve this but my points do not have correct IDs associated with them. And I don't want to know the exact rotation of the cup, I only want to know the up direction of the cup.
I also think that fitting the ellipse might help somewhat, but maybe it's not the best because the circle is not complete.
If you have any suggestions, please tell me how to obtain the point height from the bottom of the cup.
Given the accuracy issues, I don't think it is worth performing a 3D reconstruction of the cone.
I would perform a "standard" ellipse fit on the top outline, which is the most accurate, then a constrained one on the bottom, knowing the position of the vertical axis. After reduction of the coordinates, the bottom ellipse can be written as
x²/a² + (y - h)²/b² = 1
which can be solved by least-squares.
Note that it could be advantageous to ask the user to point at the endpoints of the straight edges at the bottom, plus the lowest point, instead of the whole curve.
Solving for the closest top and bottom points is a pure 2D problem (draw the line through the given point and the intersection of the sides, and find the intersection points with the ellipse.

Finding points with various radiuses around user location

I'm using Firebase for one of my projects and was wondering if the following would be possible to achieve using Geofire.
I have a list of points with radiuses in which they are available (lat, lng, radius). In the image attached, the blue circle is created by the point and its radius.
I want to find all of the circles that reach user's location (red circle - just a point). The final effect I want to achieve is similar to seeing all the wifi networks around you - some of which might have a stronger signal.
Can it be done using Geofire? If yes, how should I approach the query?
Firebase can't handle a query like this, as you can't have logic in an orderBy. I'm not sure geofire can get around that limitation (from the docs I've browsed it cannot) so then we must come up with another way of doing it. If you know the max size one of the circles can be we might be able to figure out roughly which circles to select.
(Side note, I'm going to assume you only want things in the top hemisphere, there's a bit more math if you want to handle both but I won't go into details here)
I'm going to describe roughly how to do it, latitude/longitude are tricky as you move closer to poles and radius does not always translate 1 - 1 with a circle near the equator as it does farther north. For the most part this idea will work but the math for determining the min/max will change as well as the final step where you loop.
Based on the red point and max circle radius create the following variables
minLatitude: (red circle latitude) - (max circle radius)
maxLatitude: (red circle latitude) + (max circle radius)
minLongitutde: (red circle longitude) - (max circle radius)
maxLongitutde: (red circle longitude) + (max circle radius)
you'll have to update your databse to have an index that is searchable for each of the blue circles that contains both latitude and longitude with a certain decimal precision.
Something like LATITUDE_LONGITUDE.
Do a query like: ... orderByChild('_latitude_longitude').startAt(minLatitude + '_' + minLatitude).endAt(maxLatitude + '_' + maxLongitutde) (don't forget to make sure these all have the same precision)
This will return to you all circles that will be within a max radius of your red circle
You'll then have to loop through all of the circles returned and see if based on their own radius if the red circle is contained (very simple math formula here, plenty of examples online)
That's the only method I can think of that has no server side processing.

Is there an MKSquare in iOS?

I have a bunch of lat/long coordinates and I need to draw a square polygon around each one. Each square will be a set size (e.g. 50x50) with the coordinate in the centre. I see there is a MKCircle class but is there an MKSquare equivalent (I couldn't fine one but that doesn't mean there isn't) and if there isn't, any suggestions on how this could be achieved? I have done some searching and didn't produce any solid suggestions.
I would also like to make the square 3D as in if the map is tilted it would show a height kind of like buildings.
You can use MKPolygon for this. Simply provide four coordinates the correct distance from your center point and the four coordinates will form a square.

how can I get corners point from some windows region (HRGN)

I have some polygon region (HRGN), and I want receive array of corner points. How can I do it in simple way in Delphi
In general case, there is no way to retrieve initial polygon vertices from HRGN.
Internally windows region consists of some rectangles.
Exact representation is possible for rectilinear region, but any slanted edge gives a lot of small rectangles (and slightly different polygons could give equal regions)
If your problem is to obtain a set of rectangles, then use GetRegionData function.

Detecting a certain Latitude / Longitude is in a US State

I know that most people will view this question and point me to Google Geocode - but I'm looking for a mathematical formula that allows someone to take a Lat/Lng point and see if its inside a US state (or a bounding box). Is there a way via PHP, that I can do a calculation to see if a point is in a certain Box (such as California)?
Well, there's no formula that'll tell you anything about what states is where (it would have totally been a spoiler as to the outcome of the US-Mexico war if there was!) So you'll need to get that data from somewhere.
This then turns into one of two problems, depending on the degree of accuracy you want.
If you have details of a bounding box that is rectangular when shown on a Mercator or similar projection (that is, it has degrees of latitude for north and south, and of longitude for east and west), then the formula is simply:
inBox = latitude <= north && latitude >= south && longitude <= west && longitude >= east
If you have more detail, and have a series of points that defines the border of the state (obviously, the more points, the more precision) then it becomes a variant of the point-in-polygon problem, with a guarantee of only involving simple polygons (no US state has a border that crosses itself, nor completely surrounds that used in this C code. It's possible that there would be edge cases affected by the fact that this is a 2D-plane algorithm rather than a spherical one, but I imagine you'd need to have some pretty precise data on the boundaries of the states for the imprecision from the algorithm to be greater than that caused by the data.
The simplest way I would think is using bound box for each state, that can be found from Flicker Geo API, an example for CA- https://www.flickr.com/places/info/2347563

Resources