I am using ARKit 1.5 beta to detect vertical plane. How can I go about finding the orientation of detected vertical plane?
By orientation, I am referring to the rotational angle around y-axis, since vertical plane is paralel to gravity and perpendicular to the x-z plane.
I have tried the following method:
// point1 and point 2 are 2 points on the vertical plane I found by performing hit-test with 3d coordinates relative to the world coordinate system
let vector : SCNVector3 = point1 - point2
let projection = SCNVector3Make(vector.x, 0.0, vector.z).normalized() // project vector onto x-z plane
let xVector = SCNVector3Make(1, 0, 0)
let angle = xVector.angleBetweenVectors(projection)
func angleBetweenVectors(_ vectorB:SCNVector3) -> Float {
let cosineAngle = (dotProduct(vectorB) / (magnitude * vectorB.magnitude))
return Float(acos(cosineAngle))
}
This method does not give me the correct orientation. I also wonder if I can find orientation through anchor.worldTransform.