java距离最近_Java求平面内距离0,0点最近距离

package com.mingrui.soft_struct;

public class RadarPoint{

public static void main(String [] args){

double [][] point={{3,2},{5,4},{1,0},{4,1}};

operFunc(point);

}

//操作方法

public static void operFunc(double[][] point){

int line=point.length;

//int row=2;

//double tmpValue=0;

double lengthPos[][]=new double[line][4];

double lengthPosAFinal[]=new double[line];

for(int i=0;i

lengthPosAFinal[i]=pointLength(point,i);

//lengthPos[i][2]=tmpValue;

}

lengthPos=insertSort(point,lengthPosAFinal);

for(int i=0;i

System.out.println("֣jj"+lengthPos[i][0]+","+lengthPos[i][1]+

"քӤ׈ˇ"+lengthPos[i][2]+" Ǥλ׃ˇ"+(int)lengthPos[i][3]);

}

}

//计算距离方法

public static double pointLength(double pos[][],int p){

return Math.sqrt((Math.abs(pos[p][0]))*(Math.abs(pos[p][0]))+(Math.abs(pos[p][1]))*(Math.abs(pos[p][1])));

}

//排序方法,将对应点对应承相应的排位

public static double[][] insertSort(double[][] point,double lengthPos[]){

double tmpLength=0;

int tmpPos=0;

double [][] gradeLength=new double [point.length][4];

for(int i=0;i

for(int j=0;j<4;j++){

if(j<=1)

gradeLength[i][j]=point[i][j];

else if(j==2)

gradeLength[i][j]=lengthPos[i];

else

gradeLength[i][j]=i;

}

}

for(int i1=0;i1

tmpPos=i1;

for(int k=i1+1;k>0;k--){

if(lengthPos[k]

tmpLength=lengthPos[k];

lengthPos[k]=lengthPos[tmpPos];

lengthPos[tmpPos--]=tmpLength;

}

}

}

for(int i1=0;i1

for(int j=0;j

if(gradeLength[i1][2]==lengthPos[j])

gradeLength[i1][3]=j;

}

}

return gradeLength;

}

//解析输入方法

public static void inputParseToPoint(String str){

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值