How to get surface normal of a plane in RealityKit?

I have a plane that I'm trying to find the normal vector of.
Code Block swift
let plane = ModelEntity(mesh: .generatePlane(width: 1.0, height: 1.0), materials: [SimpleMaterial(color: .red, isMetallic: false)])
let anchor = AnchorEntity()
anchor.addChild(plane)
self.arView.scene.addAnchor(anchor)

Here's my function for deriving the surface normal from 3 points along the plane. This part seems to be fine. I'm having trouble figuring out how to derive the points from the plane to use.
Code Block swift
func getSurfaceNormal(_ a: SIMD3<Float>, _ b: SIMD3<Float>, _ c: SIMD3<Float>) -> GLKVector3 {
let vectorA = GLKVector3Make(a.x, a.y, a.z)
let vectorB = GLKVector3Make(b.x, b.y, b.z)
let vectorC = GLKVector3Make(c.x, c.y, c.z)
let AB = GLKVector3Subtract(vectorB, vectorA)
let BC = GLKVector3Subtract(vectorC, vectorB)
let crossProduct = GLKVector3CrossProduct(BC, AB)
let normal = GLKVector3Normalize(crossProduct)
return normal
}

My plan was to use the plane position, then offset the x and y values to get the other two points along the plane. Right now, I'm only rotating about the y-axis, so I can get a second point by just translating the y position. I'm not sure exactly how to get the third point with the correct rotation for the plane. I've tried using simd_act with the plane's orientation, but that doesn't seem to work. I've also tried using the plane.visualBounds(relativeTo: nil).min as the third point, but that didn't work either.

Code Block swift
func getPointsAlongPlane() -> (Float3, Float3, Float3) {
let center = plane.position
let yOffsetPoint = Float3(x: center.x, y: center.y + 0.1, z: center.z)
let xOffsetPoint = simd_act(plane.orientation, Float3(x: center.x + 0.01, y: center.y, z: center.z))
return (center, yOffsetPoint, xOffsetPoint)
}


Does anyone know of a different/better way to get the surface normal or how to derive points along a plane using the center position and orientation?

Thanks
Answered by wadeww in 650570022
I figured it out without using the getSurfaceNormal function. Applying the orientation quaternion to this unit vector did the trick.

Code Block swift
let unitVector = SIMD3<Float>(0, 0, -1)
let rotated = plane.orientation.act(unitVector)
let normal = GLKVector3Make(rotated.x, rotated.y, rotated.z)


Accepted Answer
I figured it out without using the getSurfaceNormal function. Applying the orientation quaternion to this unit vector did the trick.

Code Block swift
let unitVector = SIMD3<Float>(0, 0, -1)
let rotated = plane.orientation.act(unitVector)
let normal = GLKVector3Make(rotated.x, rotated.y, rotated.z)


How to get surface normal of a plane in RealityKit?
 
 
Q