문제

회전 행렬 값을 얻으려면 다음이 포함됩니다. public static boolean getRotationMatrix (float[] R, float[] I, float[] gravity, float[] geomagnetic)여기서 어떻게 계산할 수 있나요? float[] gravity?계산하는 코드 샘플을 찾았습니다. orientation 둘 다 사용 Accelerometer 그리고 Magnetic field

boolean success = SensorManager.getRotationMatrix(
   matrixR,
   matrixI,
   valuesAccelerometer,
   valuesMagneticField);

if(success){
SensorManager.getOrientation(matrixR, matrixValues);

double azimuth = Math.toDegrees(matrixValues[0]);
double pitch = Math.toDegrees(matrixValues[1]);
double roll = Math.toDegrees(matrixValues[2]);

readingAzimuth.setText("Azimuth: " + String.valueOf(azimuth));
readingPitch.setText("Pitch: " + String.valueOf(pitch));
 readingRoll.setText("Roll: "+String.valueOf(roll));
}

내 질문은 다음과 같습니다

  • 방향 값이 회전 행렬 값입니까?
  • 그렇지 않다면 자기를 사용하여 회전 행렬 값을 얻기 위해 이 코드를 어떻게 구현할 수 있습니까?필드?

회전 행렬을 얻으려면 이 코드를 사용합니다.

 public void onSensorChanged(SensorEvent sensorEvent) {
    if (timestamp != 0) {
        final double dT = (sensorEvent.timestamp - timestamp) * NS2S;
            double magneticX = sensorEvent.values[0];
            double magneticY = sensorEvent.values[1];
            double magneticZ = sensorEvent.values[2];
                        double omegaMagnitude =Math.sqrt(magneticX*magneticX + magneticY*magneticY + magneticZ*magneticZ);

                        if (omegaMagnitude > EPSILON) {
                            magneticX /= omegaMagnitude;
                            magneticY /= omegaMagnitude;
                            magneticZ /= omegaMagnitude;
        }
                        double thetaOverTwo = omegaMagnitude * dT / 2.0f;
                        double sinThetaOverTwo =Math.sin(thetaOverTwo);
                        double cosThetaOverTwo = Math.cos(thetaOverTwo);
                        deltaRotationVector[0] = (double) (sinThetaOverTwo * magneticX);
                        deltaRotationVector[1] = (double) (sinThetaOverTwo * magneticY);
                        deltaRotationVector[2] = (double) (sinThetaOverTwo * magneticZ);
                        deltaRotationVector[3] = cosThetaOverTwo;


    }
     double[] deltaRotationMatrix = new double[9];
     SensorManager.getRotationMatrixFromVector(deltaRotationMatrix, deltaRotationVector);
}

그런데 문제는 이것이다 getRotationMatrixFromVector 센서에 대해 정의되지 않았다고 말합니다. 어떤 생각이 있나요?

도움이 되었습니까?

해결책

방향은 자북과 관련된 각도만 제공하므로 회전 행렬이 아닙니다.당신은 얻을 수 있습니다 회전 행렬 (방향 코사인 행렬)은 다음과 같이 장치 프레임의 좌표를 지구의 프레임으로 변환하는 데 도움이 됩니다.

DCM from Wikipedia

~와 함께

azimuth = 방위각(라디안)

pitch= 피치(라디안)

roll= 롤(라디안)

다른 팁

나는 이것이 오래된 스레드라는 것을 알고 있지만 도움이 될 경우 Android의 경우 3x3 회전 행렬이 실제로 승인된 답변의 변형에 의해 제공된다고 생각합니다.구체적으로 말하면 Android에서 회전 행렬은 다음과 같습니다.

     (cosφ cosψ - sinφ sinψ sinθ)     sinφ cosθ     ( cosφ sinψ + sinφ cosψ sinθ)
    -(sinφ cosψ + cosφ sinψ sinθ)     cosφ cosθ     (-sinφ sinψ + cosφ cosψ sinθ)
              -sinψ cosθ                 -sinθ                  cosφ cosθ

어디

    φ = azimuth
    θ = pitch
    ψ = roll

이는 다음을 통해 3x3 Android 회전 행렬 R[0] ~ R[8](질문의 행렬R)에 해당합니다.

    R[0] R[1] R[2]
    R[3] R[4] R[5]
    R[6] R[7] R[8]
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top