iPhone - основное движение (относительное вращение)

StackOverflow https://stackoverflow.com/questions/5053793

  •  15-11-2019
  •  | 
  •  

Вопрос

Есть ли способ получить относительное вращение от основного движения?

Что мне нужно: насколько он вращается в одной оси и в каком направлении (+ знак= против часовой стрелки, -= по часовой стрелке, в соответствии с правым правилом).

Я нашел свой недвижимость Rotationrate, но теперь я уверен, что вы извлеките угол из него, так как это дает мне радианы в секунду.

Я сделал все виды вещей в последние дни, но ничего не дает мне стабильных ценностей.Я попытался сделать пример пример данных основных данных, используя NSTIMER и рассчитать разницу между двумя образцами, поэтому у меня будет насколько она вращается с последнего образца, но от времени до момента, что мне дает сумасшедшие числа, такие как 13600 градусовДаже когда iPhone отдыхает на столе.

Любые мысли о том, как это может быть достигнуто?

Спасибо

Это было полезно?

Решение

There is indeed. You can get what you're looking for by drilling down into the properties of CMMotionManager, through CMDeviceMotion and finally to CMAttitude. The attitude of the device is defined as:

the orientation of a body relative to a given frame of reference.

In the case of DeviceMotion's CMAttitude, that frame of reference is established by the framework when starting device motion updates. From that point in time on, the attitude of the device is reported relative to that reference frame (not relative to the previous frame).

The CMAttitude class provides some handy built in functionality to convert a CMAttitude to a form that is actually useful for something, like Euler Angles, a rotation matrix, or a quaternion. You sound like you're looking for the Euler Angle representation (Pitch, Yaw, Roll).

Другие советы

The answer provided above isn't quite accurate, though it's probably sufficient to answer this question. Core Motion tries to determine the device's absolute attitude at all times, meaning that the definition of the axes can vary depending on the device's orientation. For example, if the device is face-up, then pitch up/down is a rotation about the y-axis, but if the device is in landscape orientation, then pitch is a rotation about the z-axis (perpendicular to the plane of the screen). This is somewhat helpful if your application will only be used in one orientation, or you want a delta like the question asked for, but makes it excessively complicated if you want to know absolute orientation.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top