Mobile Developer
Mobile Developer

Reputation: 5760

How to convert ARPlaneAnchor to 2d line (parallel projection)

I use ARKit to scan vertical planes in ARSCNView. I'd like to draw them later on as 2d lines (parallel projection from above). ARPlaneAnchor doesn't have start and end points, but only center point and width (ARPlaneAnchor.extent).

I also tried with SCNNode and its boundingBox object but the direct coordinates there were different than scanned planes.

How can I convert ARPlaneAnchor or SCNNode to 2d line (2d coordiantes)?

Upvotes: 0

Views: 142

Answers (1)

jfriesenhahn
jfriesenhahn

Reputation: 305

You should be able to use the center point and height/width to calculate the estimated plane edge positions and go from there. Just note that center is relative to the plane's anchor.

Assuming your plane is vertical as you note, something like this should get you started:

    let centerLocal = verticalPlane.center
    let centerWorld = centerLocal + verticalPlane.transform.translation
    let extents = verticalPlane.extent
    let upperLeft = centerWorld + SIMD3<Float>(-extents.x / 2, 0, extents.z / 2)
    let bottomRight = centerWorld + SIMD3<Float>(extents.x / 2, 0, -extents.z / 2)

Extension I used:

extension float4x4 {
    // Treats matrix as a transform matrix and grabs the 
    // translation component of the transform.       
    var translation: SIMD3<Float> {
        let translation = columns.3
        return SIMD3<Float>(translation.x, translation.y, translation.z)
    }
}

Upvotes: 1

Related Questions