質問編集履歴

2

コードを補完しました。

2021/03/14 09:00

投稿

Masa_teratail
Masa_teratail

スコア9

test CHANGED
@@ -1 +1 @@
1
- CMMotionManagerを使っpitch角度取得方法を教えて下さい。
1
+ CMMotionManagerを使っpitch角度取得したい。
test CHANGED
@@ -6,11 +6,15 @@
6
6
 
7
7
  ```Swift5
8
8
 
9
- guard motionManager.isDeviceMotionAvailable else { return }
9
+ func startMotionManager(){
10
10
 
11
11
 
12
12
 
13
+ guard motionManager.isDeviceMotionAvailable else { return }
14
+
15
+
16
+
13
- motionManager.deviceMotionUpdateInterval = 0.1
17
+ motionManager.deviceMotionUpdateInterval = 1
14
18
 
15
19
 
16
20
 
@@ -32,13 +36,19 @@
32
36
 
33
37
  self?.currentYAngle = Int(motion.attitude.pitch * 180 / Double.pi)
34
38
 
35
- self?.currentZAngle = Int(motion.attitude.yaw * 180 / Double.pi)
39
+ self?.currentZAngle = Int(motion.attitude.yaw * 180 / Double.pi)
40
+
41
+
42
+
43
+ })
44
+
45
+ }
36
46
 
37
47
  ```
38
48
 
39
49
 
40
50
 
41
- しかし、取得できる角度のうち、**pitchだけ最大値が180°ではなく、90°**であることが分かりました。なお、二次元座標で表すと、第一象限は0°〜90°、第二象限は90°〜0°、第三象限は0°〜−90°、第四象限は−90°〜0°です。
51
+ しかし、取得できる角度のうち、**pitchだけ最大値が180°ではなく、90°**であることが分かりました。得られるpitchの角度は二次元座標で表すと、第一象限は0°〜90°、第二象限は90°〜0°、第三象限は0°〜−90°、第四象限は−90°〜0°です。
42
52
 
43
53
  __(*「なお、ピッチ角の値は90度から-90度の間までで表され、±90度を超えてデバイスを傾けると、角度の値は再び減って(マイナスの場合は増えて)いきます。その代わり、デバイスが裏返ったとみなされ、ロール角の値が180度回転した値となります。」(https://www.atmarkit.co.jp/fsmart/articles/ios_sensor02/03.htmlより))__
44
54
 

1

タイトルを変更しました。

2021/03/14 09:00

投稿

Masa_teratail
Masa_teratail

スコア9

test CHANGED
@@ -1 +1 @@
1
- CMMotionManagerを使ったpitch角度の取得方法
1
+ CMMotionManagerを使ったpitch角度の取得方法を教えて下さい。
test CHANGED
File without changes