Example usage for javafx.geometry Point3D Point3D

List of usage examples for javafx.geometry Point3D Point3D

Introduction

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

Prototype

public Point3D(@NamedArg("x") double x, @NamedArg("y") double y, @NamedArg("z") double z) 

Source Link

Document

Creates a new instance of Point3D .

Usage

From source file:Main.java

private Parent createRoot() {
    Circle node1 = CircleBuilder.create().centerX(-50).centerY(-50).radius(100).fill(Color.RED).build();
    node1.translateZProperty().bind(translateZForNode1);
    final Rotate rotate = RotateBuilder.create().pivotX(0).pivotY(0).pivotZ(0).axis(new Point3D(1, 0, 0))
            .build();//from   w  w w  .j  av a  2s.  co m
    rotate.angleProperty().bind(angle);

    return GroupBuilder.create().children(node1).translateX(250).translateY(250).transforms(rotate).build();
}

From source file:eu.mihosoft.fx.tutorials.gravity.SolarSystem.java

/**
 * Runs the simulation./*from   w w  w .  j a  v a  2 s. com*/
 */
public void runSimulation() {

    // stop previous running simulation
    // does nothing if no simulation is running
    stopSimulation();

    // state vector
    int numBodies = particles.size();
    double[] y = new double[numBodies * ODEParticle.getStructSize()];
    double[] m = new double[numBodies];
    boolean[] ignoreFlags = new boolean[numBodies];

    // ui nodes
    nodes = new Node[numBodies];
    rotations = new Rotate[numBodies];

    // gravitational constant
    // see https://en.wikipedia.org/wiki/Gravitational_constant
    double G = 6.672e-11 * 0.000000001; // scaled G

    // initialize particles
    for (int i = 0; i < numBodies; i++) {
        Particle p = particles.get(i);
        p.apply(i, y, m);
        nodes[i] = p.toJFXNode();
        rotations[i] = new Rotate(0, new Point3D(0, 1, 0));
        nodes[i].getTransforms().add(rotations[i]);
    }

    // setup ODE system
    FirstOrderDifferentialEquations odeEqSys = createODE(numBodies, y, m, ignoreFlags, G);

    // start frame listener
    initFrameListener(odeEqSys, y, m, ignoreFlags, 0.001);

}

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

/**
 * Draws a line in 3D between 2 3D points on the given group.
 * //from   www.ja  v a  2s . com
 * @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;
}

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

/**
 * Draws the axes//from   w ww  .  j  a  va2  s  .  c  o m
 * 
 * @param group
 * @param distance
 */
private void drawAxes(Group group, long distance) {
    // TODO: add naming to axes ?
    drawLine3D(group, new Point3D(0.0, 0.0, 0.0), new Point3D(distance, 0.0, 0.0), MATERIAL_YELLOW);
    drawLine3D(group, new Point3D(0.0, 0.0, 0.0), new Point3D(0.0, distance, 0.0), MATERIAL_ORANGE);
    drawLine3D(group, new Point3D(0.0, 0.0, 0.0), new Point3D(0.0, 0.0, distance), MATERIAL_BLUE);
}

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

/**
 * Parses a line of gcode//from  w  w  w  .j  av a2 s .c  o  m
 * 
 * @param text
 * @param lineNumber
 * @param group
 */
private void parseGCodeline(String text, int lineNumber, Group group) {
    String textLine = text.replaceAll(";.*$", "").trim(); // remove comments
    // and
    // withespace
    Map<String, Double> args = new HashMap<String, Double>();
    Map<String, Double> newLine = new HashMap<String, Double>();
    if (!textLine.isEmpty()) {
        String[] tokens = textLine.split(" ");
        String cmd = tokens[0].toLowerCase();
        for (int i = 1; i < tokens.length; i++) {
            args.put(tokens[i].substring(0, 1).toLowerCase(), Double.valueOf(tokens[i].substring(1)));
        }
        if (cmd.equals("g0")) {
            if (args.containsKey("x")) {
                newLine.put("x", absolute(lastLine.get("x"), args.get("x")));
            } else {
                newLine.put("x", lastLine.get("x"));
            }
            if (args.containsKey("y")) {
                newLine.put("y", absolute(lastLine.get("y"), args.get("y")));
            } else {
                newLine.put("y", lastLine.get("y"));
            }
            if (args.containsKey("z")) {
                newLine.put("z", absolute(lastLine.get("z"), args.get("z")));
            } else {
                newLine.put("z", lastLine.get("z"));
            }
            if (args.containsKey("e")) {
                newLine.put("e", absolute(lastLine.get("e"), args.get("e")));
            } else {
                newLine.put("e", lastLine.get("e"));
            }
            if (args.containsKey("f")) {
                newLine.put("f", absolute(lastLine.get("f"), args.get("f")));
            } else {
                newLine.put("f", lastLine.get("f"));
            }
            newLine.put("init", 0.0);
            if (lastLine.containsKey("init")) {
                drawLine3D(group, new Point3D(lastLine.get("x"), lastLine.get("y"), lastLine.get("z")),
                        new Point3D(newLine.get("x"), newLine.get("y"), newLine.get("z")), MATERIAL_GREEN);
            }
            lastLine.clear();
            lastLine.putAll(newLine);
        } else if (cmd.equals("g1")) {
            if (args.containsKey("x")) {
                newLine.put("x", absolute(lastLine.get("x"), args.get("x")));
            } else {
                newLine.put("x", lastLine.get("x"));
            }
            if (args.containsKey("y")) {
                newLine.put("y", absolute(lastLine.get("y"), args.get("y")));
            } else {
                newLine.put("y", lastLine.get("y"));
            }
            if (args.containsKey("z")) {
                newLine.put("z", absolute(lastLine.get("z"), args.get("z")));
            } else {
                newLine.put("z", lastLine.get("z"));
            }
            if (args.containsKey("e")) {
                newLine.put("e", absolute(lastLine.get("e"), args.get("e")));
            } else {
                newLine.put("e", lastLine.get("e"));
            }
            if (args.containsKey("f")) {
                newLine.put("f", absolute(lastLine.get("f"), args.get("f")));
            } else {
                newLine.put("f", lastLine.get("f"));
            }
            newLine.put("init", 0.0);
            if (lastLine.containsKey("init")) {
                drawLine3D(group, new Point3D(lastLine.get("x"), lastLine.get("y"), lastLine.get("z")),
                        new Point3D(newLine.get("x"), newLine.get("y"), newLine.get("z")), MATERIAL_RED);
            }
            lastLine.clear();
            lastLine.putAll(newLine);
        } else if (cmd.equals("g99")) {
            this.isRelative = false;
        } else if (cmd.equals("g91")) {
            this.isRelative = true;
        } else if (cmd.equals("g20")) {
            // set unit to inches
        } else if (cmd.equals("g21")) {
            // set unit to mm
        }
    }
}