Drawing a line from a 3D model based on the 3D model's orientation

I'm looking for some help as to how I can accomplish the following task with Cesium... I have a 3D model that I would like to have a polyline emanate from. I'll know the line's heading and pitch in relation to the 3D model's orientation and I also know the length of the line.

So far, my approach has been to calculate the 3D model's direction by calculating a Cartesian3 velocity vector based on the 3D model's last two positions. I then convert the vector to spherical coordinates and add it to the spherical coordinates that are produced based on the desired heading, pitch, and magnitude of the line. So at this point I should have the theta and phi components for the line in reference to the earth because I have taken the 3D model's orientation into account. I also know the magnitude because that was given with the line's desired length. I convert the result into Cartesian coordinates and then draw the line from the 3D model's position to the result of adding the 3D model and the line's Cartesian coordinates.

What I have so far works if the heading and pitch are both 0 (i.e. I want to draw a line from the front of the 3D Model) but that's about it.

I'm assuming that there is an easier way to do this within Cesium's framework by using quaternions but this is my first exposure to them so I'm a little lost as to how to use them.

Does anyone have any advice or an example?


I didn’t quite understand what you’re trying to accomplish. Are you trying to draw the line pointing in front or behind the model? Like pointing in the direction it’s moving or tracing where it has been?



I want to draw a line in a given direction based on the entity's orientation. For example, if the entity was facing north and parallel to the earth's surface (i.e. pitch is 0) and I wanted to draw a line that was 1000m in length and pointing 10 degrees left and 10 degrees down from the front of the plane, how would I do that?

After putting some more thought into it... I think I might be able to get the orientation of the entity (a quaternion), create another quaternion to represent the line's orientation with respect to the entity and then multiply them together to get the actual orientation of the line with respect to the earth.

function drawLine(entity, length, azimuth, elevation) {
  var entityOrientation = Cesium.Quaternion.clone(entity.orientation);
  var lineOrientation = Cesium.Quaternion.fromHeadingPitchRoll(Cesium.Math.toRadians(azimuth), Cesium.Math.toRadians(elevation), 0, new Cesium.Quaternion());
  Cesium.Quaternion.multiply(entityOrientation, lineOrientation, lineOrientation);
  var arbitraryPoint = //cartesian coordinate that is desired length away from entity's position
  var beam = viewer.entities.add({
    positions : [entity.position, arbitraryPoint],
    polyline : Cesium.Color.BLUE,
    orientation : lineOrientation
  //then add an offset to the positions to take the line's new orientation into account so that it starts at the entity...

Maybe a better way to explain it would be that I want to point a line away from the entity in a certain direction with respect to the entity's current orientation. Does that make sense?

I don’t think a polyline will use the orientation property. You will have to compute the position of the point before creating the polyline. I think you’re on the right track with using the quaternions. You can use that to compute the correct position.



Clint, did you figure this out? I want to do the exact same thing! If you have anything to share, that'd be great.

I did find this blog post from ages ago that may help some, but if you already figured it out, I'd love to know what you did!