JohnyBro
JohnyBro

Reputation: 361

Circle intersect MySQL

I have two circle on a map with Longitude, Latitude (point()) and Radius and now I would know if there is a SQL function that return true if those circle intersect ?

Thx for help.

Upvotes: 3

Views: 887

Answers (3)

Shadow
Shadow

Reputation: 34284

You indeed need to use the ST_*() functions and spatial operator functions, but Zamrony's answer is rather vague. So, what you need to do is to convert your circles into geometry data types and then you can use st_intersect() to see if the 2 circles intersect:

  1. Use ST_Buffer() function to convert point and radius into geometry data type:

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

Pls read the description of ST_Buffer_Strategy() as well on how points making up the circle geometries are determined.

  1. Use ST_Intersects() function to determine if the two geometries intersect each other.

Upvotes: 0

Ran Locar
Ran Locar

Reputation: 561

Try:

If(ST_Distance(POINT(Long1, Lat1),POINT(Long2, Lat2))<=Radius1+Radius2, "INTERSECT","NO INTERSECTION")

Which is basically asking if the distance between the centers of the circles is <= the sum of their radii. If it is - they intersect.

Upvotes: 1

Related Questions