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 pointvar end = Cesium.Cartesian3.fromDegrees(czml[3], czml[4], czml[5]);//end pointvar 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)With this code I get incorrect orientation of the cylinder (black)://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 OKvar position = new Cesium.Cartesian3(mid[0], mid[1], mid[2]);//position is okvar 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}});My question is: what is the correct way to get heading, pitch and roll from the two points.