我知道如何在2D中得到2點之間的atan2角度,但是這是如何在3D中工作的: 可以說我有3點A,B,C(都是SCNVector3,帶有x ,y,z座標 第一條線端點A和B 第二條線端點B和C 現在我想要得到兩條線之間的角度......(在ios Swift中) 我讀了一些關於dot產品和acos的內容,但不知它不工作...3D中兩條線之間的夾角
其中i = 0:
var vector1 = SCNVector3((pointArray[i].x - pointArray[i+1].x), (pointArray[i].y - pointArray[i+1].y), (pointArray[i].z - pointArray[i+1].z))
var vector2 = SCNVector3((pointArray[i+2].x - pointArray[i+1].x), (pointArray[i+2].y - pointArray[i+1].y), (pointArray[i+2].z - pointArray[i+1].z))
var dotProduct = vector1.x * vector2.x + vector1.y * vector2.y + vector1.z * vector2.z
var theta = acos(dotProduct)
var tmp_winkel = GLKMathRadiansToDegrees(theta)
我明白了,忘了做正規化,謝謝!剩餘的問題:角度的方向...我怎麼知道它是順時針還是逆時針? – cheese
跨產品可以幫助,請參閱https://stackoverflow.com/questions/5188561/signed-angle-between-two-3d-vectors-with-same-origin-within-the-same-plane – mnuages