Example usage for javafx.geometry Point3D getX

List of usage examples for javafx.geometry Point3D getX

Introduction

In this page you can find the example usage for javafx.geometry Point3D getX.

Prototype

public final double getX() 

Source Link

Document

The x coordinate.

Usage

From source file:be.makercafe.apps.makerbench.editors.GCodeEditor.java

/**
 * Draws a line in 3D between 2 3D points on the given group.
 * //from   w  w  w  . j  a va 2 s  . c  o m
 * @param origin
 *            Origin point
 * @param target
 *            Target point
 * @return 3D line (cylinder) between to points
 */
private Cylinder drawLine3D(Group group, Point3D origin, Point3D target, Material color) {
    if (color == null) {
        color = MATERIAL_BLACK; // default to orange
    }
    Point3D yAxis = new Point3D(0, 1, 0);
    Point3D diff = target.subtract(origin);
    double height = diff.magnitude();

    Point3D mid = target.midpoint(origin);
    Translate moveToMidpoint = new Translate(mid.getX(), mid.getY(), mid.getZ());

    Point3D axisOfRotation = diff.crossProduct(yAxis);
    double angle = Math.acos(diff.normalize().dotProduct(yAxis));
    Rotate rotateAroundCenter = new Rotate(-Math.toDegrees(angle), axisOfRotation);

    Cylinder line = new Cylinder(1, height);
    line.setMaterial(color);

    line.getTransforms().addAll(moveToMidpoint, rotateAroundCenter);

    if (group != null) {
        group.getChildren().add(line);
    }

    return line;
}