{"id":20656978,"url":"https://github.com/ahmedalmasri/worldmotion","last_synced_at":"2025-04-19T12:27:44.516Z","repository":{"id":56927680,"uuid":"360295399","full_name":"ahmedAlmasri/WorldMotion","owner":"ahmedAlmasri","description":"The coordinate system that represents device motion or position relative to the Earth","archived":false,"fork":false,"pushed_at":"2021-05-11T23:34:40.000Z","size":12926,"stargazers_count":17,"open_issues_count":0,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-10T21:04:00.882Z","etag":null,"topics":["3d","coremotion","ios","realworld","sensormanager","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ahmedAlmasri.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-04-21T20:18:49.000Z","updated_at":"2022-06-01T14:32:14.000Z","dependencies_parsed_at":"2022-08-21T05:50:50.194Z","dependency_job_id":null,"html_url":"https://github.com/ahmedAlmasri/WorldMotion","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmedAlmasri%2FWorldMotion","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmedAlmasri%2FWorldMotion/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmedAlmasri%2FWorldMotion/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ahmedAlmasri%2FWorldMotion/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ahmedAlmasri","download_url":"https://codeload.github.com/ahmedAlmasri/WorldMotion/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224952045,"owners_count":17397495,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["3d","coremotion","ios","realworld","sensormanager","swift"],"created_at":"2024-11-16T18:17:51.610Z","updated_at":"2024-11-16T18:17:52.288Z","avatar_url":"https://github.com/ahmedAlmasri.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🌏 WorldMotion 🧘🏼 (beta)\n\nUse a CoreMotion sensor to use a coordinate system that represents device motion or position relative to the Earth. In this coordinate system:\n\n- y points to magnetic north along the surface of the Earth.\n- x is 90 degrees from y , pointing approximately east.\n- z extends up into space. Negative z extends down into the ground\n\n\u003cp align=\"center\"\u003e\n  \u003cimg width=\"200\" src=\"images/world-coordinates.png\"\u003e\n\u003c/p\u003e\n\n[![CI Status](https://img.shields.io/travis/ahmed.almasri@ymail.com/WorldMotion.svg?style=flat)](https://travis-ci.org/ahmed.almasri@ymail.com/WorldMotion)\n[![Version](https://img.shields.io/cocoapods/v/WorldMotion.svg?style=flat)](https://cocoapods.org/pods/WorldMotion)\n[![License](https://img.shields.io/cocoapods/l/WorldMotion.svg?style=flat)](https://cocoapods.org/pods/WorldMotion)\n[![Platform](https://img.shields.io/cocoapods/p/WorldMotion.svg?style=flat)](https://cocoapods.org/pods/WorldMotion)\n\n## Determining device orientation\n\nDevice orientation is the position of the device in space relative to the Earth's coordinate system (specifically, to the magnetic north pole).\n\nThe `getRotationMatrix()` method generates a rotation matrix from the accelerometer and geomagnetic field sensor. A rotation matrix is a linear algebra concept that translates the sensor data from one coordinate system to another—in this case, from the device's coordinate system to the Earth's coordinate system.\n\nThe `getOrientation()` method uses the rotation matrix to compute the angles of the device's orientation. All of these angles are in radians, with values from -π to π. There are three components to orientation:\n\n*Azimuth* : The angle between the device's current compass direction and magnetic north. If the top edge of the device faces magnetic north, the azimuth is 0.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg width=\"200\" src=\"images/orientation-azimuth.png\"\u003e\n\u003c/p\u003e\n\n*Pitch* : The angle between a plane parallel to the device's screen and a plane parallel to the ground.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg width=\"200\" src=\"images/orientation-pitch.png\"\u003e\n\u003c/p\u003e\n\n*Roll* : The angle between a plane perpendicular to the device's screen and a plane perpendicular to the ground.\n\n\u003cp align=\"center\"\u003e\n  \u003cimg width=\"200\" src=\"images/orientation-roll.png\"\u003e\n\u003c/p\u003e\n\n\u003eNote: orientation angles use a different coordinate system than the one used in aviation (for yaw, pitch, and roll). In the aviation system, the x -axis is along the long side of the plane, from tail to nose.\n\n# Use case\n\nLet's assume that you want to know the angle of rotation around a certain object in the real world, so you need the value `x` from the Earth's coordinate system.\n\n1. Convert a rotation vector to a rotation matrix.\n\n```Swift\n  let matrixFromVector = rotationMatrix.getRotationMatrixFromVector()\n```\n\n2. Rotating the supplied rotation matrix so it is expressed in a different coordinate system using.\n\n```Swift\n let coordinateMatrix = matrixFromVector.coordinateSystem(CMRotationMatrix.axisX, CMRotationMatrix.axisY)\n```\n\n3. Compute the device's orientation based on the rotation matrix.\n\n```Swift\n let acceleration = coordinateMatrix.getOrientation()\n```\n\n\u003e The return values is a radius that needs to be converted into degrees using `toDegrees`\n\n##### Output\n\n\u003cp align=\"center\"\u003e\n  \u003cimg width=\"200\" src=\"images/angle_example.gif\"\u003e\n\u003c/p\u003e\n\n## Using\n\n- EarthCoordinate:\n\n```Swift\nlet earthCoordinate = EarthCoordinate()\n// .......\ndeinit {\n    earthCoordinate.stop()\n}\n override func viewDidAppear(_ animated: Bool) {\n        super.viewDidAppear(animated)\n\n    earthCoordinate.delegate = self\n    earthCoordinate.start(interval: 0.2, queue: .init())\n\n }\n\n // MARK: -  EarthCoordinate delegate\n\nextension ViewController: EarthCoordinateDelegate {\n\n   func onOrientationChange(x: Double, y: Double, z: Double) {\n       // ..... calculate value degrees\n\n    }\n}\n\n```\n\n- RotationMatrix\n\n```Swift\n\nlet rotationMatrix = deviceMotion.attitude.rotationMatrix\nlet matrixFromVector = rotationMatrix.getRotationMatrixFromVector()\nlet coordinateMatrix = safeSelf.getCoordinateSystem(with: matrixFromVector)\nlet acceleration = coordinateMatrix.getOrientation()\n```\n\n## Example\n\nTo run the example project, clone the repo, and run `pod install` from the Example directory first.\n\n## Requirements\n\n- Swift 4.2+\n- Xcode 10.0+\n- iOS 11.0+\n\n## Installation\n\nWorldMotion is available through [CocoaPods](https://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod 'WorldMotion'\n```\n\n## Author\n\nAhmad Almasri, ahmed.almasri@ymail.com\n\n## License\n\nWorldMotion is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahmedalmasri%2Fworldmotion","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahmedalmasri%2Fworldmotion","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahmedalmasri%2Fworldmotion/lists"}