How to get heading, pitch and roll from the two points

If you have the two points, you can compute the vector direction by subtracting one from the other.

Here’s a function you can use to get a rotation matrix from the origin and the vector.

Lastly, you can use Quaternion.fromRotationMatrix to get a quaternion, and HeadingPitchRoll.fromQuaternion to get the HPR object.

Hello Gabby,

I'm trying to follow your approach to determine the orientation between two points but I don't get correct results. I think the function you referring to is `Cesium.Transform.rotationMatrixFromPositionVelocity`?

I created a Sandcastle example with my code (the blue cone should point to the green 'target' point):

Do you know what I did wrong?

Thanks!

Ulrich

Nevermind, I got it working:

(my previous example applied a wrong transform for the orientation)

This is great! Thanks for posting your solution. I imagine this will be useful to a lot of others as well.

This is a great work of two points and a cone orientation drawing. Thanks for sharing your solution!

hello, can you send the code i got the same problem. thank you very much

here‘s the code (for some reason the original link doesn’t work anymore):

2 Likes

thank you very much!

I was able to use the example provided above to correctly orient a cone entity in the ecef reference frame, but my teams project is able to switch between ecef and eci. When switching to eci the cone updates to use the eci coordinates of my two entities, but the orientation is incorrect. Are there adjustments that would need to be made to the logic to use eci coordinates?

Thank you very much in advance

Why doesn’t it work also for camera?


viewer.scene.camera.flyTo({
	destination: origin,
    orientation: Cesium.Quaternion.fromRotationMatrix(
        rotationMatrix
    ),
	complete: function() {
      //
    }
});