Friday 15 June 2012

geometry - How do I draw a mysql polygon circle, and not a square? -


The function below creates a polygon square out of 4 points and I believe the last 5th digit closed the square Given that, I need it at least 24 points and any ideas for creating a circle?

  function getRadius ($ point = "numeral (-29.8368 30.90 9)", $ radius = 2) {$ km = 0.009; $ Center = "GeomFromText ('$ point')"; $ Radius = $ radius * $ km; $ Bbox = "CONCAT ('Polygon ((', $ center) - $ radius, '' y ($ center) - $ radius, ',', x ($ center) + $ radius, '', y $ Center) - $ radius, ',', x ($ center) + $ radius, '', y ($ center) + $ radius, ',', x ($ center) - $ radius, '', y $ Center) + $ radius, ',', x ($ center) - $ radius, '', y ($ center) - $ radius, '))') "; $ Query = $ this- & gt; Db- & gt; Query ("SELECT id, asText (latLng) AS latLng, (SQRT (POW (ABS (X (latitude) - X ({$ center}), 2) + POW (Latgang, GeofromText ($ Bbox)) and SQL POS (AB (X (Litlang) - ABS (Y (Latleng) - Y ({$ Center}), 2)) 0.00 / X ({$ center}), 2) + POW (ABS (Y (Lat) - Y ({$ center}), 2)) & lt; $ distance from radius command "); If ($ query-> num_rows ()> 0) {return ($ query-> result ()); } Other {return false; }}  

below JS version and it works correctly

  var findCirclePolygons = function (point, r) {var d2r = Math.PI / 180; This.circleLatLngs = New Array (); Num Points = 24; Var circle lat = R * 0.009; // change in km var circle leg = circleLat / Math.cos (point.lat () * d2r); (Var i = 0; i & lt; numpoints + 1; i ++) for (var theta = Math.PI * (i / (numpoint / 2)) Var vartex lat = point.lit () + (circle) Late * Math (Thita)); var vertexLng = parseFloat (point.lng ()) + parsflot ((circle lang * math kos (theta)); var vertextLatLng = new google.maps.LatLng (Vertaxlat, Vertax lung) ; This.circleLatLngs.push (vertextLatLng);} // set option var option = {path: circle layouts, stroke color: "# 0055ff", stroke opacity: 1, strokewhite: 1, fill: "# 0055ff", fillipcity : 0.35}; Return Return option;};  

You A loop can (in the phonetic code):

 <$> $ radius * cos (i) "$. $ Radius for sin (i)  i <= ii = 0; I + = 360/24) {$ extra_point = "POINT (". ")"}  

edit

  • However, if you just want a bounding box, using a square is the right way to do this, there is no need to find the Circle box. You can filter later with sorting.
  • To measure the distance, there is no need to use ABS. Squareing does this for you (as an additional, instead of computing the root of the square, instead of comparing the radius class,
  • Do not forget to add the spatial index or the display will be unusable

2 ADIT Some pseudo-code In;) (This is the same age that I did not work with PHP did).

  $ lane = 42; $ Lat = 2; $ Radius = 0.01; $ Bbox = "Polygon ((; (i = 0; i & lt; = 360; i + = 360/24) {$ bbox. = $ Radius * cos (djrad (i)) $ lon." "$ Radius * Sin (deg2rad (i)) + $ latitude; if (i <360) "$ bbox. =", "} $ Bbox. =")) About " 

In the distance, you have Pove (stomach (X), 2) == PAU (x, 2) for any x, you can just write (for simplicity):

  SQRT (POW (x (latleng) - x ({$ center}), 2) + pau (wai (lattelle) - y ({$ center}), 2)) & lt; To abandon the calculation of the radius of $ radius  

or even square root (in this case it will change absolutely nothing and quick optimization is a bad thing, so whatever you want to do) POW (X (latlng)) - x ({$ center}), 2) + pow (wai (lattelle) - y ({$ center}), 2) pow ($ radius , 2)


No comments:

Post a Comment