M
M
maks789452018-08-14 12:42:46
JavaScript
maks78945, 2018-08-14 12:42:46

How to determine if a point is in a circle?

Good afternoon, tell me how to determine if a point is in a circle, the
radius of the circle is set in meters through the property

var Circle = new google.maps.Circle({
                          strokeColor: 'blue',
                          strokeOpacity: 0.8,
                          strokeWeight: 2,
                          fillColor: 'blue',
                          fillOpacity: 0.35,
                          map: myMap,
                          center: {lat: 50.013770, lng: 36.214603},
                          radius: 70000,
                          draggable: true
                        });

I get the center of the circle when it is moved and compare according to the formula whether it enters the circle or not
var x = Circle.getCenter().lat();
var y = Circle.getCenter().lng();
var r = 0.63; //радиус, высчитывал как 1 меридиан 111,111 км, а у меня 70 км, и приблизительно получилось такое значение
var xt = 50.431005;
var yt = 30.538288;

To check, I use this formula:
Math.pow((x-xt),2)+Math.pow((y-yt),2)<=Math.pow(r,2
) from the bottom of the circle, the check of the hit of the circle works well, but on the right and left sides of the circle, the check works somewhere almost to the center of the circle, it turns out that the check is checked not in a circle, but in an ellipse.
Tell me what I'm doing wrong, how can I calculate exactly in a circle, and not in an ellipse

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2018-08-14
@maks78945

https://stackoverflow.com/questions/8766218/detect...

google.maps.Circle.prototype.contains = function(latLng) {
  return this.getBounds().contains(latLng) && google.maps.geometry.spherical.computeDistanceBetween(this.getCenter(), latLng) <= this.getRadius();
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question