Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何验证点是否位于由地理坐标形成的扇区内_Java_Google Maps_Geometry - Fatal编程技术网

Java 如何验证点是否位于由地理坐标形成的扇区内

Java 如何验证点是否位于由地理坐标形成的扇区内,java,google-maps,geometry,Java,Google Maps,Geometry,我编写了一个Java代码,用于验证点是否位于圆定义半径的扇区内。点和圆心都用经纬度表示 Java代码如下所示- public boolean isPointWithin(float centreLat,float centreLong,float pointLat,float pointLong,int maxDistance) { float adjFactor=0.0f; double an

我编写了一个Java代码,用于验证点是否位于圆定义半径的扇区内。点和圆心都用经纬度表示

Java代码如下所示-

public boolean isPointWithin(float centreLat,float centreLong,float pointLat,float pointLong,int maxDistance)
    {                               
        float adjFactor=0.0f;
        double angleRange,bisectorIVector,bisectorJVector,IVector,JVector,VectorLength,dotProduct,EnodeBAngle,
        latScale=0.0,longScale=0.0,distance,lower,upper,count,adjustmentFactor=0.0,jVector,dist1,dist2;
        dist1=Math.pow(centreLat-pointLat, 2)+Math.pow(centreLong-pointLong, 2);
        dist2=Math.pow(centreLat-pointLat, 2)+Math.pow(360-(Math.abs(centreLong)+Math.abs(pointLong)), 2);
        if(dist1>dist2)
        {
            adjFactor=360-(Math.abs(pointLong)+Math.abs(centreLong));
            if(centreLong>0)
                pointLong=(centreLong+adjFactor);
            else
                pointLong=(centreLong-adjFactor);
        }
        latScale=(111132.954-(559.822*Math.cos(2*Math.toRadians(pointLat)))+1.175*Math.cos(4*Math.toRadians(pointLat)))/1000;

        angleRange=Math.toRadians(sectorAngle);

        bisectorIVector=maxDistance*Precision.round(Math.sin(Math.toRadians(sectorDirection)),8);
        bisectorJVector=maxDistance*Precision.round(Math.cos(Math.toRadians(sectorDirection)),8);

        IVector=pointLong-centreLong; 
        JVector=pointLat-centreLat;

        if(pointLong<centreLong)
        {
            lower=pointLong;
            upper=centreLong;
        }
        else
        {
            upper=pointLong;
            lower=centreLong;
        }
        count=lower;
        while(Math.ceil(count)<Math.floor(upper))
        {
            jVector=((JVector/IVector)*(count-centreLong))+centreLat;
            longScale+=Math.cos(Math.toRadians(jVector)); 
            count++;
        }
        longScale*=latScale;
        if((upper-lower)>Math.floor((upper-lower)))
        {
            jVector=((JVector/IVector)*(upper-centreLong))+centreLat;
            adjustmentFactor=Math.cos(Math.toRadians(jVector))*latScale*((upper-lower)-Math.floor((upper-lower)));
        }
        longScale+=adjustmentFactor;


        distance=Math.sqrt(Math.pow(longScale,2) + Math.pow(JVector*latScale,2));
        VectorLength=Math.sqrt(Math.pow(IVector,2) + Math.pow(JVector,2));
        if(VectorLength==0.0)
            return true;

        dotProduct=bisectorIVector*IVector+bisectorJVector*JVector;
        EnodeBAngle=Precision.round(Math.acos(dotProduct/(maxDistance*VectorLength)),8);

        if(EnodeBAngle<=Precision.round(angleRange/2,8) && distance<=maxDistance)
            return true;
        else
            return false;
    }
public boolean isPointWithin(float-centreLat、float-centreLong、float-pointLat、float-pointLong、int-maxDistance)
{                               
浮动调整系数=0.0f;
双角度范围,平分向量,平分向量,向量,向量长度,点积,EnodeBAngle,
latScale=0.0,longScale=0.0,距离,下限,上限,计数,调整因子=0.0,jVector,距离1,距离2;
dist1=数学功率(centreLat pointLat,2)+数学功率(centreLong pointLong,2);
dist2=Math.pow(centrelatapointlat,2)+Math.pow(360-(Math.abs(centreLong)+Math.abs(pointLong)),2);
如果(dist1>dist2)
{
adjFactor=360-(数学abs(点长)+数学abs(中心长));
如果(中心长度>0)
pointLong=(中心长度+调整因子);
其他的
pointLong=(中心长度调整因子);
}
latScale=(111132.954-(559.822*数学常数(2*数学常数(pointLat)))+1.175*数学常数(4*数学常数(pointLat)))/1000;
角度范围=数学托拉迪安(扇形);
平分器=maxDistance*精度.round(Math.sin(Math.toRadians(sectorDirection)),8);
平分线jvector=maxDistance*Precision.round(Math.cos(Math.toRadians(sectorDirection)),8);
IVector=点长中心线;
JVector=pointLat centreLat;

如果(pointLong地球表面的距离不是纬度和长距离的斜边,你必须找到大圆弧的长度。看第一部分

JavaScript摘录:

var R = 6371000; // metres
var φ1 = lat1.toRadians();
var φ2 = lat2.toRadians();
var Δφ = (lat2-lat1).toRadians();
var Δλ = (lon2-lon1).toRadians();

var a = Math.sin(Δφ/2) * Math.sin(Δφ/2) +
        Math.cos(φ1) * Math.cos(φ2) *
        Math.sin(Δλ/2) * Math.sin(Δλ/2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));

var d = R * c;
您提到了扇区-但扇区参数(起始角或中心角、扫描角)在哪里?
您可能会计算方向角(方向角),如“方向角”部分中提到的链接所示