NullPointer_PP 2018-09-11 09:37 采纳率: 100%
浏览 568
已采纳

谁能帮我这个C代码转换成JAVA,高奖励

double GetPointDistance(double point_st, double point_end) {
double y2 = point_end[1];
double y1 = point_st[1];
double x1 = point_st[0];
double x2 = point_end[0];
return sqrt((x1 - x2) (x1 - x2) + (y1 - y2) (y1 - y2));
}

double GetNearestDistance(double point, double point_st, double* point_end) {

double a = 0.0, b = 0.0, c = 0.0;

a = GetPointDistance(point_end, point);

b = GetPointDistance(point_st, point);

c = GetPointDistance(point_end, point_st);



if (a  a >= b  b + c * c) 
    return b;     
if (b  b >= a  a + c * c)  
    return a;    


float l = (a + b + c) / 2;     
float s = sqrt(abs(l  (l - a)  (l - b) * (l - c))); 
return 2 * s / c;

}

static int PolygonIsContainPoint_with_gap(double point, double polyline, int pointcount, double* middle, double gap) {
int result = -1, tempI,temp2;
if (gap != 0)
gap = gap * 11.52339 / 1000000;

double maxx = 0, minx = 0, maxy = 0, miny = 0;
if (polyline == NULL || point == NULL)
    return result;
int i;
double dis=10000.0;

int j = pointcount-1;
for (i = 0; i < pointcount; i++) {
    if (i == 0) {
        tempI = j+j;
        temp2=0;
    }
    else{
        tempI = i+i;
        temp2 = tempI-2;
    }

    dis = GetNearestDistance(point, polyline+tempI, polyline+temp2);
    if (dis <= gap) {
        ems_log_debug("spe_cal",
                "PolygonIsContainPoint gap find dis=%f <= gap=%f", dis,
                gap);
        result = 1;
        break;
    }
}

return result;

}

  • 写回答

2条回答 默认 最新

  • threenewbee 2018-09-11 09:58
    关注
     你的代码首先根本也不对
    double GetPointDistance(double point_st, double point_end) 
    这里明显应该是指针类型,但是没有写。
    if (a  a >= b  b + c * c) 
    这个在c语言里也不符合语法。你得先把原始程序搞对。
    
    你的代码无非就是把double * 改写成 double[]
    别的语法和java是一样的。
    
    “高奖励”就算了。能回答你,多少分我都会回答你。高奖励其实没什么用,那种悬赏分挺高,但是解决问题不采纳就跑了的垃圾我见多了。
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退