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条)

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料