JavaFX 8 3D : conduct Cylinder from point A to point B, by Point3D objects



  • Need arose connect two cylindrom points♪ There are coordinates of the two points requested as copies Point3D:

    Point3D pointA = new Point3D(100,200,150);
    Point3D pointB = new Point3D(200,150,-100);
    

    There's a band.javafx.scene.Groupin which constructions are made:

    Group space3D = new Group();
    

    Objective: connect these two virtual points (possible to include a copy in these coordinates) Sphere radius 10for illustration) by a copy javafx.scene.shape.Cylinder radius 2, height of equal distance from point A to point B with a minimum number of actions.

    P.C.: What alternatives would be more effective for the visual connection of two points in 3D space?



  • I'll start with it. Example of the decision:

    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:

    Cylinder 2 point  javaFx :

    Now closer to specific issues:

    This has been the case that it is easier to understand the procedure for the rotation of the object is a steady rotation of 3 coordinates (and often applied) But if we look at it, it's natural to turn the object once into one particular angle. And if the coordinates of the soba on one plane are completely accurate, the points of the beginning and end of the arc are turned.
    Work could also be done https://ru.wikipedia.org/wiki/%D0%9C%D0%B0%D1%82%D1%80%D0%B8%D1%86%D0%B0_%D0%BF%D0%BE%D0%B2%D0%BE%D1%80%D0%BE%D1%82%D0%B0 and as an example of working with her https://stackoverflow.com/questions/30145414/rotate-a-3d-object-on-3-axis-in-javafx-properly ♪ Of course, this approach is faster than working with a steady turn on three axles, but I want to point out that the author himself is the answerer. https://github.com/Birdasaur/FXyz - FXyz, on my observations, it's not exactly a matrical implementation.
    Uses (observation of an open code on GitHub).




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2