Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do i create a circle Geometry with a radius and co-ordinates of center, using MySQL Spatial Extensions?

I am trying to create a Circle Geometry in MySQL using the co-ordinates of the center and a radius. I searched everywhere...all i could find in the MySQL doc on the site were for polygons. May be i am looking in the wrong place. can anybody help me with an appropriate SQL that can help me create a table that stores this Circle geometry as one of the columns in the table? Also, i am not even sure if there is a way to do so in MySQL?..The version i am using is MySQL 5.6.

Thanks in advance.

like image 538
user2052129 Avatar asked Jun 10 '13 18:06

user2052129


2 Answers

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

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

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

like image 186
eggyal Avatar answered Nov 15 '22 15:11

eggyal


There are two Parts: A.For given tested points you have to check their relation with given circle. B.You want to generate points on circumference of given circle.

A.Yes, First of all take the distance between your given point(test Point) and the centre of circle point. Both of these points are defined in Latitude and longitude. Distance formula between two points(x1,y1) and (x2,y2) is distance d= sqrt[ (x2-x1)^2 + (y2-y1)^2 ]. Now,

  1. If this distance is less than radius of circle then your tested point is inside your circle.
  2. If this distance is Greater than radius then tested point is outside the circle.
  3. If this calculated distance is equal to radius of circle then this tested point is on your circle i.e. on the circumference of your circle.

B. In a circle the total angle theta is 360 degree or 2*Pi in radians. For given Circle whose centre is (x1, y1) and radius is r.

x = x1 + r * cos(theta)

y = y1 + r * sin(theta)

where, theta is running from Zero to 2*Pi and Pi is 3.1415.

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

fist theta is zero, then theta is Zero+increment, then theta is Zero +increment+increment i.e. 2* increment and then zero + 3*increment and then so on. unless you get theta equal to 2*Pi.

For all above thetas calculate x and y. These all x and y coordinate points are on the circumference of the circle.

like image 31
Azeem Rehman Avatar answered Nov 15 '22 15:11

Azeem Rehman