我正在website中阅读解决方案3(2D)并尝试将其转换为java代码。如果java是正确的,请评论。而不是x和y坐标,我使用纬度和经度坐标(注意:loc.getLongitude(),loc.getLatitude()是在矩形内部检查的点集合,给定坐标(double)不是真实坐标爱好。
double lat0 = 0.2;
double long0 = 0.3;
double lat1 = 1.2;
double long1 = 1.3;
double lat2 = 1.2;
double long2 = 1.3;
double lat3 = 1.2;
double long3 = 1.3;
double rel1 = (loc.getLongitude()- long0)*(lat1 - lat0)- ((loc.getLatitude()-lat0)*(long1-long0));
double rel2 = (loc.getLongitude()- long1)*(lat2 - lat1)- ((loc.getLatitude()-lat1)*(long2-long1));
double rel3 = (loc.getLongitude()- long2)*(lat3 - lat2)- ((loc.getLatitude()-lat2)*(long3-long2));
double rel4 = (loc.getLongitude()- long3)*(lat0 - lat3)- ((loc.getLatitude()-lat3)*(long0-long3));
if (rel1 >= 0 && rel2 >= 0 && rel3 >= 0 && rel4 >= 0 )
{
try
{
..........
..........
}
else
{
.........
}
}
答案 0 :(得分:1)