Java:关于弧度,Math.cos,Math.sin,double和long的问题 [英] Java: questions about radians, Math.cos, Math.sin, double and long

查看:105
本文介绍了Java:关于弧度,Math.cos,Math.sin,double和long的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我的java代码中实现harvesine距离。

I need to implement the harvesine distance in my java code.

我在Javascript中找到了这个片段,我需要将它转换为java。

I found this snippet in Javascript, and I need to convert it to java.


  1. 如何在Java中将纬度和经度转换为弧度?

  2. Math.sin想要在Java中使用double。我应该以弧度为单位传递先前转换的值吗?

  3. Math.sin和Math.cos返回long。我应该声明一个长的并将其传递给Math.sqrt或将其转换为double吗?

谢谢

dLat = (lat2-lat1).toRad();
dLon = (lng2-lng1).toRad(); 
a = Math.sin(dLat/2) * Math.sin(dLat/2) +
    Math.cos(lat1.toRad()) * Math.cos(lat2.toRad()) * 
    Math.sin(dLon/2) * Math.sin(dLon/2); 
c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 
d = R * c;
return d;


推荐答案

我在这里找到了解决方案:

I've found the solution here:

如何测量距离和根据Java中的两个纬度+经度点创建一个边界框?

这篇关于Java:关于弧度,Math.cos,Math.sin,double和long的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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