如何检测点是否在圆内? [英] How to detect if a point is in a Circle?

查看:32
本文介绍了如何检测点是否在圆内?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何测试 LatLng 点是否在圆的边界内?(谷歌地图 JavaScript v3)

getBounds() 方法返回圆的边界框,它是一个矩形,所以如果一个点落在圆外但在边界框内,你会得到错误的答案.

解决方案

使用球面几何库

a>(务必将其包含在 API 中)

function pointInCircle(point, radius, center){返回(google.maps.geometry.sphereal.computeDistanceBetween(点,中心)<=半径)}

How can I test if a LatLng point is within the bounds of a circle? (Google Maps JavaScript v3)

The getBounds() method returns the bounding box for the circle, which is a rectangle, so if a point falls outside the circle but within the bounding box, you'll get the wrong answer.

解决方案

Use the spherical geometry library (be sure to include it with the API)

function pointInCircle(point, radius, center)
{
    return (google.maps.geometry.spherical.computeDistanceBetween(point, center) <= radius)
}

这篇关于如何检测点是否在圆内?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆