Generating Quaternions to Properly Orient a CZML Object

Hi all,

I have been struggling over the last week to wrap my head around quaternions and how to use them to orient an object. I’ve been able to develop a general understanding of how each of the four terms should affect an object, but I’m still pretty slow with creating a mental image of the rotations. What I am trying to do is orient a rectangular sensor in the “correct direction” as it would be coming out of a radar for its field of view. The available data is the coordinates of the radar in ECF and the azimuth/elevation of the field of view.

The first thing I have found is a method that will point the base of the pyramid towards true north and the top half of it above the ground, which gives the base orientation for an azimuth = 0 and elevation = 0. The method I am using for this was borrowed from another post [!searchin/cesium-dev/pojo/cesium-dev/rHzL4jD4qfw/Tabu6FNijY0J] :

private static UnitQuaternion rotateObjectUpAndNorth(double latitude, double longitude){

double longOffset = Math.abs(Math.abs(longitude) - 90.0 );

double latOffset = 90.0 - latitude;

longOffset = Math.toRadians(longOffset/2.0);

latOffset = Math.toRadians(latOffset/2.0);

UnitQuaternion yawQuaternion = new UnitQuaternion(Math.cos(longOffset),0.0,0.0,Math.sin(longOffset));

UnitQuaternion pitchQuaternion = new UnitQuaternion(Math.cos(latOffset),-Math.sin(latOffset),0.0,0.0);

return UnitQuaternion.multiply(yawQuaternion, pitchQuaternion);



I am trying to use this as an ad-hoc reference frame because the azimuth and elevation will both be relative to this starting position. What I have tried to do with the azimuth and elevation is modify this method to get rid of the two initial 90 degree offsets and just plug the azimuth in longOffset/2 and the elevation in latOffset/2. Then at the end multiply the rotateObjectUpAndNorth result with the yawQuaternion, then multiply that result by the pitchQuaternion.

Unfortunately this second set of rotations does not give the results I was looking for. And the results end up twisting the pyramid in the wrong directions. Google seemed to give mixed results in whether determining a quaternion based on azimuth and elevation is possible or not. Hopefully I’m at least semi-on track with my approach, and any other ideas very welcome.