Change attachment point and rotate a cone

By default, the center of a CylinderGraphics will be the origin. When you want to use the top of a cylinder (or the “tip” of a cone, in your example) as some sort of a “reference point”, then you have to take this into account when computing the rotation- and translation matrices.

Assuming that you have a rotationMatrix for the orientation and a translationMatrix for the desired position, you can compute

  • a toOriginMatrix to move the center of the coordinate system to the top of the cylinder
  • a fromOriginMatrix to move the center of the coordinate system back

The final modelMatrix for the cylinder can then be computed like this:

  const modelMatrix = Cesium.Matrix4.clone(Cesium.Matrix4.IDENTITY);
  Cesium.Matrix4.multiply(modelMatrix, translationMatrix, modelMatrix);
  Cesium.Matrix4.multiply(modelMatrix, toOriginMatrix, modelMatrix);
  Cesium.Matrix4.multiply(modelMatrix, rotationMatrix, modelMatrix);
  Cesium.Matrix4.multiply(modelMatrix, fromOriginMatrix, modelMatrix);

An example can be found in the sandcastle that I posted in Create a cylinder at a coordinate and point at another coordinate - #2 by Marco13 . It offers a function that receives to points, and generates a cylinder between these points. (Applying arbitrary rotations could be done similarly)

1 Like