Compare the 3D orientation of the device with the position of the sun

I am working on an application that requires the user to aim his iPhone in the sun to trigger a special event.

I can get the quaternion of the 3D orientation of the device based on the gyroscope and the CoreMotion frame, from this I can get the rotation angles, roll and height. I can also calculate the azimuth and zenith angle of the sun based on the current date and time (GMT), as well as latitude and longitude. Now I'm trying to figure out how to compare these two sets of values ​​(phone orientation and position of the sun) to accurately determine the alignment of the device with the sun.

Any ideas on how to achieve this?

+4
source share
1 answer

I managed to solve the problem,

To achieve this, I used an example code using the augmented reality available in Apple Developer Resources: pARk

The idea was to first transform the spherical coordinates of the Sun into Cartesian coordinates in order to get its position in the sky as a simple vector: {x, y, z}. The formula is available on Wikipedia: Spherical coordinates . Since the distance from the Sun (radius in spherical coordinates) does not matter here, I used 1.

CoreMotion, iPhone. pARk . , .

. UIView x y, , .

Github, !

+6