Public Static voidMain (String args[]) {Try{ floatpoint[]=New float[3]; Location Loc=NewLocation (); //Get coordinatesPoint[0] = 0; point[1] = 0; point[2] = (float) 0.5; Loc.set_point (Point,1); point[0] = 0; point[1] = 1; point[2] = 2; Loc.set_point (Point,2); point[0] = 0; point[1] = 1; point[2] = 0; Loc.set_point (Point,3); point[0] = 1; point[1] = 0; point[2] = 3; Loc.set_point (Point,4); //DistanceLoc.set_distance (); Loc.set_distance (The); Loc.set_distance (2,3); Loc.set_distance (1,4); //Calc floatX[] =Loc.calc (); if(x = =NULL) {System.out.println ("Fail"); } Else{System.out.println (x[0]+ "," +x[1]+ "," + x[2]); } } Catch(Exception ex) {ex.printstacktrace (); } }
Packagecom.qmall.location; Public classLocation {//space known 4 point coordinates floatP[][] =New float[4] [3]; //space known 4 point distance floatD[] =New float[4] ; //Initialize Space 4 point coordinates//p: coordinates, array//num:1-4 voidSet_point (floatPoint[],intNumthrowsException {intj = 0; for(j = 0;j < 3;j++) {P[num-1][J] =Point[j]; } } //Initialize 4-point distance of space//Distance: Distance//num:1-4 voidSet_distance (floatDistanceintNumthrowsException {d[num-1] =distance; } //Calculate unknown point coordinates//p: Calculated return value//fail:back-1 float[] Calc ()throwsException {floatpoint[]=New float[3]; //matrix A floatA[][] =New float[3] [3]; //Matrix B floatb[]=New float[3]; inti = 0; intj = 0; //initializing the B-matrix for(i = 0;i < 3;i++) {B[i]= (Locationmath.d_p_square (p[i + 1])-Locationmath.d_p_square (P[i])-(d[i + 1] * d[i + 1]-d[i] * d[i])/2; } //Initialize a matrix for(i = 0;i < 3;i++) { for(j = 0;j < 3;j++) {A[i][j]= P[i + 1][j]-P[i][j]; } } //Calculate unknown point coordinatesPoint =Locationmath.solve (A, b); returnPoint ; } }
Packagecom.qmall.location; Public classLocationmath { Public Static voidPrintf_matrix (floatM[][])throwsexception{inti = 0; intj = 0; for(i = 0;i < 3;i++) { for(j = 0;j < 3;j++) {System.out.println (m[i*][j]); } } } //values for three-dimensional determinant//M:3 * 3 array Public Static DoubleDetfloatM[][])throwsexception{DoubleValue = 0.0; Value= m[0][0] * m[1][1] * m[2][2] +m[0][1] * m[1][2] * M[2][0] +m[0][2] * m[1][0] * m[2][1]-m[0][1] * m[1][0] * m[2][2]-m[0][2] * m[1][1] * m[2][0]-m[0][0] * m[1][2] * m[2][1]; returnvalue; } //assigns the value of one determinant to another//Src,dst:3 * 3 array Public Static voidCopy_matrix (floatSrc[][],floatDst[][])throwsException {inti = 0; intj = 0; for(i = 0;i < 3;i++) { for(j = 0;j < 3;j++) {Dst[i][j]=Src[i][j]; } } } //Solution Equation//m: Phalanx, 3 * 3 array//B: Solution//x: Return value//fail:back-1 Public Static float[] Solve (floatM[][],floatB[])throwsException {floatdet_m; floatdet_m_temp; floatM_temp[][] =New float[3] [3]; inti = 0; intj = 0; floatx[]=New float[3]; Det_m= (float) det (m); if(Det_m = = 0) { return NULL; } for(j = 0;j < 3;j++) { //get a new determinantCopy_matrix (m,m_temp); for(i = 0;i < 3;i++) {M_temp[i][j]=b [i]; } det_m_temp= (float) det (m_temp); //solvingX[J] = det_m_temp/det_m; } returnx; } //calculates the square of the distance from the space point to the Origin . Public Static floatD_p_square (floatP[])throwsException {floatd = 0; inti = 0; for(i = 0;i < 3;i++) {D+ = p[i] *p [i]; } returnD; }}
Java space Four-point positioning, which coordinates the location of a known four-point coordinate (x, y, z) and distance