-1

有人知道如何将这些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
4

2 回答 2

3

如果您使用普通数组,则需要遍历元素。考虑使用 Matrix 包,例如http://math.nist.gov/javanumerics/jama/

类似于(假设 a 是二维数组):

import Jama.*

Matrix A = new Matrix(a);
Matrix B = new Matrix(b);
Matrix R = A.minus(B);
于 2013-08-25T15:12:53.910 回答
-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];

对于用作对象的矩阵,您可以定义函数来处理上述行。

希望这可以帮助!

于 2013-08-25T16:08:32.130 回答