While playing around with just a single sphere and its marker circle, it seemed to be the case that when the sphere was in the upper-left corner (i.e., near coordinate 0,0, according to the printed output), the marker circle was near the center of the screen. Similarly, when the sphere was near the center of the screen, the marker circle was in the lower-right corner of the screen.
After consulting some sample code, to see if there might be any functions that are used to adjust for this unexpected offset, nothing seemed obvious.
Then I noticed that SwiftUI's Circle is described as, "centered on the frame of the view containing it". So, when it is at offset 0,0, it will be centered, not in the upper-left corner.
To test this, I added a framingOffset(_:) function to my ContentView struct:
func framingOffset(_ point: CGPoint?) -> CGPoint {
guard var ret = point else { return CGPoint(x: -1, y: -1) }
guard let arView = coord.arView else { return CGPoint(x: -1, y: -1) }
// Adjust for Circle being "centered on the frame of the view containing it".
// https://developer.apple.com/documentation/swiftui/shape/circle
ret.x -= arView.frame.width / 2.0
ret.y -= arView.frame.height / 2.0
return ret
}
Then changed the circle creation from:
Circle().offset(projectedPosition(of: obj))
To:
Circle().offset(framingOffset(projectedPosition(of: obj)))
With these changes, the marker circle for the the gray sphere placed at the anchor correctly follows its sphere, but when additional spheres are added their marker circles are still a bit off.
So, what else am I missing?