Create a cylinder at a coordinate and point at another coordinate

You can compute the difference between the base point and the apex. The distance between these points will be the height of the cylinder/cone. In order to align the cylinder with the line between these points, you can

  • compute the cross product between the difference and the Z-axis (to obtain a rotation axis)
  • compute the angle between the Z-axis and the difference (which is the rotation angle)

From that, you can create a quaterinion, put that into a matrix, and apply that matrix to the cylinder geometry.

Here is a sandcastle with a few examples, with the “entry point” being the function

function createCylinderPrimitive(
  position0,
  position1,
  topRadius,
  bottomRadius,
  color
) {
...
}

that allows creating arbitrarily-aligned cylinder primitives.

(Edited to properly rotate around the base of the cylinders)