How is VisionOS RealityKit calculating it’s rotation (roll pitch yaw)?

Problem

Apple has an object for tracking the wrist such as anchor.originFromAnchorTransform and on this object, there is a rotation field that is protected so I can’t access it, but it gets printed if you print anchor like this. I’m trying to reproduce the values that HandAnchor has calculated from the transformation matrix but I can never get what the HandAnchor has calculated

HandAnchor(
 chirality: left,
 id: F37E231E-ED08-4E3A-8888-AD99CA814F70,
 isTracked: true, 
 originFromAnchorTransform:
   <translation=(-0.124833 0.765254 -0.135481) 
   rotation=(76.86° -119.53° 144.82°)>,
 handSkeleton: HandSkeleton(jointCount: 27))

Data

Here is the original 4×4 matrix. Note: Apple uses column major, so each array is a column.

simd_float4x4([
[-0.08531584, 0.13101268, -0.987703, 0.0],
[0.9765112, -0.18586183, -0.10900249, 0.0],
[-0.19785702, -0.97380245, -0.1120784, 0.0],
[-0.12483275, 0.7652545, -0.13548124, 1.0]])

These are the numbers I keep calculating based on the code below

(-96.56549, 11.411671, 94.99314)
(94.99314, 11.411671, -96.56549)
(-173.70236, 6.522802, -101.485016)

but the expected is

(76.86° -119.53° 144.82°)

Code

I’ve tried a bunch of different formulas, but no matter what, I can’t get the same calculations that it’s getting.

  func getIntrinsicRotation(_ anchor: HandAnchor) -> (Float, Float, Float) {
      let rotationMatrix = extractUpperLeft3x3(from: anchor.originFromAnchorTransform)
      
      // Compute yaw, pitch, roll from rotationMatrix in intrinsic order
      let sy = sqrt(rotationMatrix[0, 0] * rotationMatrix[0, 0] + rotationMatrix[1, 0] * rotationMatrix[1, 0])
      let singular = sy < 1e-6 // If singularity is detected
      
      let yaw: Float
      let pitch: Float
      let roll: Float

      if !singular {
          yaw = atan2(rotationMatrix[1, 0], rotationMatrix[0, 0])
          pitch = atan2(-rotationMatrix[2, 0], sy)
          roll = atan2(rotationMatrix[2, 1], rotationMatrix[2, 2])
      } else {
          yaw = atan2(-rotationMatrix[1, 2], rotationMatrix[1, 1])
          pitch = atan2(-rotationMatrix[2, 0], sy)
          roll = 0
      }

      // Convert radians to degrees
      let yawDegrees = yaw * 180 / .pi
      let pitchDegrees = pitch * 180 / .pi
      let rollDegrees = roll * 180 / .pi
      
      return (yawDegrees, pitchDegrees, rollDegrees)
  }
  
  func getExtrinsicRotation(_ anchor: HandAnchor) -> (Float, Float, Float) {
      let rotationMatrix = extractUpperLeft3x3(from: anchor.originFromAnchorTransform)
      
      // Compute roll, pitch, yaw from rotationMatrix in extrinsic order
      let sy = sqrt(rotationMatrix[0, 0] * rotationMatrix[0, 0] + rotationMatrix[1, 0] * rotationMatrix[1, 0])
      let singular = sy < 1e-6 // If singularity is detected
      
      let roll: Float
      let pitch: Float
      let yaw: Float

      if !singular {
          roll = atan2(rotationMatrix[1, 2], rotationMatrix[0, 2])
          pitch = atan2(-rotationMatrix[2, 2], sy)
          yaw = atan2(rotationMatrix[2, 1], rotationMatrix[2, 0])
      } else {
          roll = atan2(-rotationMatrix[1, 0], rotationMatrix[0, 0])
          pitch = atan2(-rotationMatrix[2, 0], sy)
          yaw = 0
      }

      // Convert radians to degrees
      let rollDegrees = roll * 180 / .pi
      let pitchDegrees = pitch * 180 / .pi
      let yawDegrees = yaw * 180 / .pi
      
      return (rollDegrees, pitchDegrees, yawDegrees)
  }
  
  func getRotation(_ anchor: HandAnchor) -> (Float, Float, Float) {
    let rotationMatrix = extractUpperLeft3x3(from: anchor.originFromAnchorTransform)
    
    // Compute roll, pitch, yaw from rotationMatrix
    let sy = sqrt(rotationMatrix[0, 0] * rotationMatrix[0, 0] + rotationMatrix[1, 0] * rotationMatrix[1, 0])
    let singular = sy < 1e-6 // If singularity is detected

    let x: Float
    let y: Float
    let z: Float

    if !singular {
        x = atan2(rotationMatrix[2, 1], rotationMatrix[2, 2])
        y = atan2(-rotationMatrix[2, 0], sy)
        z = atan2(rotationMatrix[1, 0], rotationMatrix[0, 0])
    } else {
        x = atan2(-rotationMatrix[1, 2], rotationMatrix[1, 1])
        y = atan2(-rotationMatrix[2, 0], sy)
        z = 0
    }

    // Convert radians to degrees
    let rollDegrees = x * 180 / .pi
    let pitchDegrees = y * 180 / .pi
    let yawDegrees = z * 180 / .pi
    
    return (rollDegrees, pitchDegrees, yawDegrees)
  }

After doing every single combination of XYZ, YXZ, ZXY…. etc, etc. I figured out that the order was YZX and instead of people roll, pitch, yaw. It’s pitch, yaw, roll. I haven’t figured out why I have to negate the pitch and roll to get it to be the same value as the HandAnchor though.

  func getRotationYZX(_ anchor: HandAnchor) -> (Float, Float, Float) {
    let rotationMatrix = extractUpperLeft3x3(from: anchor.originFromAnchorTransform)
    let roll = atan2(-rotationMatrix[0, 1], rotationMatrix[1, 1])
    let pitch = atan2(rotationMatrix[2, 1], sqrt(rotationMatrix[2, 2] * rotationMatrix[2, 2] + rotationMatrix[2, 0] * rotationMatrix[2, 0]))
    let yaw = atan2(rotationMatrix[2, 0], rotationMatrix[2, 2])
    
    let rollDegrees = roll * 180 / .pi
    let pitchDegrees = pitch * 180 / .pi
    let yawDegrees = yaw * 180 / .pi
    
    return (-pitchDegrees, yawDegrees, -rollDegrees)
  }

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật