Android Open Source - latrobe-datacapture-dir Quaternion Difference Data Transform From Project Back to project page latrobe-datacapture-dir .
License The source code is released under:
MIT License
If you think the Android project latrobe-datacapture-dir listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code package com.example.DataCaptureApp.transforms;
/ / f r o m w w w . j a v a 2 s . c o m
import com.example.DataCaptureApp.utils.Quaternion;
import com.example.DataCaptureApp.data.Data;
import com.example.DataCaptureApp.data.DataTransform;
/**
* Created by Tom on 26/10/2014.
*/
public class QuaternionDifferenceDataTransform extends DataTransform
{
private String mMagnitudeField;
// 0 = X, 1 = Y, 2 = Z, 3 = W
private String[] mDifferenceFields;
private String[] mPrevFields;
private String[] mNewFields;
public QuaternionDifferenceDataTransform(String[] prevFields, String[] newFields, String[] differenceFields, String magnitudeField)
{
if (prevFields.length != 4 || newFields.length != 4 || differenceFields.length != 4)
throw new IllegalArgumentException("Field arrays for quaternions must be 4 wide!" );
mMagnitudeField = magnitudeField;
mDifferenceFields = differenceFields;
mPrevFields = prevFields;
mNewFields = newFields;
}
@Override
public synchronized Data transform (Data data)
{
// Perform domain calculations
return performKneeCalculations(data);
}
private Data performKneeCalculations(Data data)
{
// Extract prev quaternion
float [] pQuaternion;
Float pW = data.get(mPrevFields[3]);
if (pW == null || pW == 0)
{
pQuaternion = new float [3];
pQuaternion[0] = data.get(mPrevFields[0]);
pQuaternion[1] = data.get(mPrevFields[1]);
pQuaternion[2] = data.get(mPrevFields[2]);
}
else
{
pQuaternion = new float [4];
pQuaternion[0] = data.get(mPrevFields[3]);
pQuaternion[1] = data.get(mPrevFields[0]);
pQuaternion[2] = data.get(mPrevFields[1]);
pQuaternion[3] = data.get(mPrevFields[2]);
}
// Extract new quaternion
float [] nQuaternion;
Float nW = data.get(mNewFields[3]);
if (nW == null || nW == 0)
{
nQuaternion = new float [3];
nQuaternion[0] = data.get(mNewFields[0]);
nQuaternion[1] = data.get(mNewFields[1]);
nQuaternion[2] = data.get(mNewFields[2]);
}
else
{
nQuaternion = new float [4];
nQuaternion[0] = data.get(mNewFields[3]);
nQuaternion[1] = data.get(mNewFields[0]);
nQuaternion[2] = data.get(mNewFields[1]);
nQuaternion[3] = data.get(mNewFields[2]);
}
// Prepare difference quarternion array
float [] dQuaternion = new float [4];
// Perform calculations
Quaternion.getDifferenceQuaternion(dQuaternion, nQuaternion, pQuaternion);
float magnitude = Quaternion.getQuaternionMagnitude(dQuaternion);
magnitude = (float )Math.toDegrees(magnitude);
// Clamp magnitude between 0 and 180
if (magnitude > 180)
{
magnitude = 360 - magnitude;
}
// Save difference quaternion
data.set(mDifferenceFields[0], dQuaternion[3]);
data.set(mDifferenceFields[1], dQuaternion[0]);
data.set(mDifferenceFields[2], dQuaternion[1]);
data.set(mDifferenceFields[3], dQuaternion[2]);
// Save magnitude
data.set(mMagnitudeField, magnitude);
return data;
}
}
Java Source Code List com.example.DataCaptureApp.AdvConfigActivity.java com.example.DataCaptureApp.ConfigActivity.java com.example.DataCaptureApp.MasterActivity.java com.example.DataCaptureApp.MasterService.java com.example.DataCaptureApp.SlaveActivity.java com.example.DataCaptureApp.SlaveService.java com.example.DataCaptureApp.data.DataServiceConnection.java com.example.DataCaptureApp.data.DataService.java com.example.DataCaptureApp.data.DataTransform.java com.example.DataCaptureApp.data.Data.java com.example.DataCaptureApp.data.Event.java com.example.DataCaptureApp.data.FailedInitialisationException.java com.example.DataCaptureApp.data.IDataEventListener.java com.example.DataCaptureApp.data.IDataListener.java com.example.DataCaptureApp.data.IDataSource.java com.example.DataCaptureApp.data.IDataTransform.java com.example.DataCaptureApp.data.IEventListener.java com.example.DataCaptureApp.data.IEventSource.java com.example.DataCaptureApp.services.BluetoothConnectivityService.java com.example.DataCaptureApp.services.BluetoothThread.java com.example.DataCaptureApp.services.DataDbContract.java com.example.DataCaptureApp.services.DataDbHelper.java com.example.DataCaptureApp.services.DataStoreService.java com.example.DataCaptureApp.services.HttpThread.java com.example.DataCaptureApp.services.RemoteConnectivityService.java com.example.DataCaptureApp.services.SensorSampleService.java com.example.DataCaptureApp.services.SensorSampler.java com.example.DataCaptureApp.testing.BluetoothActivity.java com.example.DataCaptureApp.testing.DataStoreActivity.java com.example.DataCaptureApp.testing.DataTester.java com.example.DataCaptureApp.testing.IServiceListener.java com.example.DataCaptureApp.testing.MainService.java com.example.DataCaptureApp.testing.MasterTestActivity.java com.example.DataCaptureApp.testing.RandomService.java com.example.DataCaptureApp.testing.RemoteActivity.java com.example.DataCaptureApp.testing.SensorSampleActivity.java com.example.DataCaptureApp.testing.ServiceTestActivity.java com.example.DataCaptureApp.testing.SlaveTestActivity.java com.example.DataCaptureApp.testing.TestActivity.java com.example.DataCaptureApp.transforms.AggregatorDataTransform.java com.example.DataCaptureApp.transforms.ArithmeticDataTransform.java com.example.DataCaptureApp.transforms.ArrayCollectDataTransform.java com.example.DataCaptureApp.transforms.ArraySplitDataTransform.java com.example.DataCaptureApp.transforms.DeserialiseDataTransform.java com.example.DataCaptureApp.transforms.FieldCopyDataTransform.java com.example.DataCaptureApp.transforms.FieldModifyDataTransform.java com.example.DataCaptureApp.transforms.FieldRenameDataTransform.java com.example.DataCaptureApp.transforms.IntervalAggregatorDataTransform.java com.example.DataCaptureApp.transforms.PackDataTransform.java com.example.DataCaptureApp.transforms.QuaternionDifferenceDataTransform.java com.example.DataCaptureApp.transforms.RemoveDataTransform.java com.example.DataCaptureApp.transforms.SetDataTransform.java com.example.DataCaptureApp.transforms.UnpackDataTransform.java com.example.DataCaptureApp.utils.BroadcastDataSource.java com.example.DataCaptureApp.utils.ByteUtils.java com.example.DataCaptureApp.utils.DataEventHandler.java com.example.DataCaptureApp.utils.DataHandlerThread.java com.example.DataCaptureApp.utils.JSONReader.java com.example.DataCaptureApp.utils.Quaternion.java com.example.DataCaptureApp.utils.SerialisationUtils.java