I'll start from the reverse. An example of a solution:
public Cylinder paintCylinder(Point3D A, Point3D B) { Point3D temp = A.subtract(B); double Y = temp.getX() != 0 || temp.getZ() != 0 ? B.getY() : B.getY() > A.getY() ? B.getY() : A.getY(); Point3D dir = A.subtract(B).crossProduct(new Point3D(0, -1, 0)); double angle = Math.acos(A.subtract(B).normalize().dotProduct(new Point3D(0, -1, 0))); double h1 = A.distance(B); Cylinder c = new Cylinder(2d, h1); c.getTransforms().addAll(new Translate(B.getX(), Y - h1 / 2d, B.getZ()), new Rotate(-Math.toDegrees(angle), 0d, h1 / 2d, 0d, new Point3D(dir.getX(), -dir.getY(), dir.getZ()))); return c; }
As a result:
:
Now closer to specific issues:
It happened so that it is easier to understand the rotation of an object, this is a sequential rotation along 3 coordinates (and this approach is often used). But if you figure out, it’s quite natural to rotate an object only once at one particular angle. And to be completely accurate, turn the coordinate system so that the planes turned out to be the points of the beginning and end of the turning arc. It is also possible to work with the rotation matrix and as an example of working with it this answer. Yes, of course, this approach is faster than working with a consistent rotation on three axes, but I want to note that the author of the answer itself (he is by the way and the library developer - FXyz) according to my observations matrix implementation is not
enjoys (observing the framework of open source on GitHub).