任何人都知道如何将这些python程序转换为java?我不知道如何在java中添加/减去两个数组和规范化数组,或者我需要使用矩阵?
P1 = array([xA, yA, zA])
P2 = array([xB, yB, zB])
P3 = array([xC, yC, zC])
ex = (P2 - P1)/(numpy.linalg.norm(P2 - P1))
i = dot(ex, P3 - P1)
ey = (P3 - P1 - i*ex)/(numpy.linalg.norm(P3 - P1 - i*ex))
ez = numpy.cross(ex,ey)
d = numpy.linalg.norm(P2 - P1)
j = dot(ey, P3 - P1)
triPt = P1 + x*ex + y*ey + z*ez
答案 0 :(得分:3)
如果使用普通数组,则需要遍历元素。 考虑使用Matrix包,例如http://math.nist.gov/javanumerics/jama/
类似的东西(假设是一个二维数组):
import Jama.*
Matrix A = new Matrix(a);
Matrix B = new Matrix(b);
Matrix R = A.minus(B);
答案 1 :(得分:-1)
设置循环将是添加两个数组或矩阵的最简单方法:
//For two arrays a[n] and b[n], finding array c[n] such that c = a - b;
for (int i=0; i<n; i++)
c[i] = a[i] - b[i];
//For matrices A & B of order m X n when expressed as 2d arrays:
for (int i=0; i<n; i++)
for(int j=0; j<m; j++)
c[i][j] = a[i][j] + b[i][j];
对于用作对象的Matrix,您可以定义函数以处理上述行。
希望这有帮助!