首先,我在應用於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