首先,我在应用于Vector3d时遇到了数学矢量的概念。我理解一个向量就像一条线,除了它有一个方向属性。Java Vector3d和矢量逻辑
现在,Vector3d只在其构造函数中接受3个参数(x,y,z)。我认为这是因为矢量最初被假定为从原点开始并穿过指定点。如果Vector3d中包含的唯一属性是x,y,z,我们怎么能有一个不与原点相交的向量?
例如,我想程序,计算球体上的两点之间的距离的函数:
//Returns the shortest distance between two points on a sphere
public static double getGreatCircleDistance(Point3d p1, Point3d p2){
Vector3d v1 = getVector(viewSphereOrigin, p1);
Vector3d v2 = getVector(viewSphereOrigin, p2);
v1.normalize();
v2.normalize();
return Math.acos(v1.dot(v2)*(viewSphereDiameter/2));
}
//Returns a vector through two given Points in 3d space
public static Vector3d getVector(Point3d start, Point3d terminal){
return new Vector3d(terminal.x-start.x, terminal.y-start.y, terminal.z-start.z);
}
我不但是明白getVector()如何返回穿过两个向量给点。我研究了如何获取连接两个点的矢量:
http://emweb.unl.edu/math/mathweb/vectors/vectors.html#vec6
但是从根本上我还是不明白这一点。有人可以为我清除Vector3d背后的逻辑吗?它可以如何在3D空间中表示任意矢量,但它只包含x,y,z?
谢谢!
你有一个小错误:应该是'Math.acos(v1.dot(v2))*(viewSphereDiameter/2)' – Joni 2012-03-29 07:04:55
噢,谢谢Joni! – user1170679 2012-03-29 07:16:25