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

1,319 views
Skip to first unread message
Message has been deleted

Gabby Getz

unread,
Aug 2, 2018, 2:44:05 PM8/2/18
to cesium-dev
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.

On Tuesday, July 31, 2018 at 12:15:44 PM UTC-4, Alen Kelemen wrote:
To represent a valve in a pipe I want to make two cylinder entites or to insert a model. To accomplish any of that I need position and orientation.
So I have two points representing start and end of a valve.

 Position is determined like this:
            var start = Cesium.Cartesian3.fromDegrees(czml[0], czml[1], czml[2]);//start point
            var end = Cesium.Cartesian3.fromDegrees(czml[3], czml[4], czml[5]);//end point
            var dist = Cesium.Cartesian3.distance(start, end);
            var mid = [(start.x + end.x) / 2, (start.y + end.y) / 2, (start.z + end.z) / 2 - dist / 4];//middle point == position

I have trouble to determine heading, pitch and roll of the valve from start and end point.
My code so far (not giving a correct hpr)
//get angles in all three planes
xDx = (end.x - start.x)
xDy = (end.y - start.y)
xDx = (end.x - start.x)
xDz = (end.z - start.z)
xDy = (end.y - start.y)
xDz = (end.z - start.z)
var heading = Math.atan2(xDy, xDx)
var pitch = Math.atan2(xDz, xDx)
var roll = Math.atan2(xDy, xDy)
var hpr = new Cesium.HeadingPitchRoll(heading, pitch, roll);//not OK
var position = new Cesium.Cartesian3(mid[0], mid[1], mid[2]);//position is ok
var valve = entities.add({
                id: "Valve" + feature.getId(),
                name: "",
                description: "",
                position: position,
                orientation: Cesium.Transforms.headingPitchRollQuaternion(position, hpr),
                cylinder: {
                    length: dist / 2,
                    topRadius: 0.0,
                    bottomRadius: radius_m,
                    material: Cesium.Color.BLACK
                }
            });
With this code I get incorrect orientation of the cylinder (black):



My question is: what is the correct way to get heading, pitch and roll from the two points.


Message has been deleted
Message has been deleted

Alen Kelemen

unread,
Aug 3, 2018, 11:58:05 AM8/3/18
to cesium-dev


Dana petak, 3. kolovoza 2018. u 17:54:05 UTC+2, korisnik Alen Kelemen napisao je:
Thank you Gabby.
I solved the issue somewhat different, but anyway your advices are pressius.
Especially when there are no courses or comprehensive book about Cesium API (as far I know).

ulrich...@dimetor.com

unread,
Feb 26, 2019, 7:00:55 AM2/26/19
to cesium-dev
Message has been deleted

m...@ulrichlehner.com

unread,
Feb 28, 2019, 7:03:38 AM2/28/19
to cesium-dev

Omar Shehata

unread,
Feb 28, 2019, 7:28:09 AM2/28/19
to cesium-dev
This is great! Thanks for posting your solution. I imagine this will be useful to a lot of others as well.

artille...@gmail.com

unread,
Aug 11, 2019, 12:49:11 PM8/11/19
to cesium-dev
This is a great work of two points and a cone orientation drawing. Thanks for sharing your solution!


On Thursday, February 28, 2019 at 7:03:38 AM UTC-5, m...@ulrichlehner.com wrote:
Reply all
Reply to author
Forward
0 new messages