How to create a geometry circle with radius and center coordinates using MySQL Spatial Extensions?

I am trying to create circle geometry in MySQL using center and radius coordinates. I searched everywhere ... everything that I could find in the MySQL document on the site was for polygons. Maybe I'm looking in the wrong place. can someone help me with the appropriate SQL which can help me create a table that stores this circle geometry as one of the columns in the table? Also, I'm not even sure if there is a way to do this in MySQL? .. The version I'm using is MySQL 5.6.

Thanks in advance.

+7
source share
2 answers

With MySQL v5.6.1 you can use Buffer(g, d) :

Returns a geometry that represents all points whose distance from the geometry value g less than or equal to the distance d .

Obviously, in your case, g should be a point in the center of the circle, and d should be its radius.

+8
source

There are two parts: A. For the given tested points, you must check their connection with the given circle. B. You want to create points on the circumference of a given circle.

A. Yes, first of all, take the distance between your point (test point) and the center of the circle. Both of these points are defined in latitude and longitude. The formula for the distance between two points (x1, y1) and (x2, y2) is the distance d = sqrt [(x2-x1) ^ 2 + (y2-y1) ^ 2]. Now,

  • If this distance is less than the radius of the circle, your test point is inside your circle.
  • If this distance is greater than the radius, then the test point is outside the circle.
  • If this estimated distance is equal to the radius of the circle, then this test point is located on your circle, that is, on the circumference of your circle.

B. In a circle, the full angle of theta is 360 degrees or 2 * Pi in radians. For a given circle whose center is (x1, y1) and radius r.

x = x1 + r * cos (theta)

y = y1 + r * sin (theta)

where theta works from zero to 2 * Pi and Pi is 3.1415.

Depending on how you do it. Example: if you want 10 points in a circle, then increment = (2 * Pi-Zero) / 10.

fist theta is zero, then theta is Zero + increment, then theta is Zero + increment + increment ie 2 * increment and then zero + 3 * increment and then and so on. if you do not get theta equal to 2 * Pi.

For all of the above, we compute x and y. All x and y coordinate points are on the circle circle.

+1
source

All Articles