static int distance(Point3D first, Point3D second) {
   return (int)
       (Math.sqrt(
               Math.pow(second.getX() - first.getX(), 2)
                   + Math.pow(second.getY() - first.getY(), 2))
           + Math.pow(second.getZ() - first.getZ(), 2));
 }
Exemple #2
0
 /**
  * Returns a String containing all Arrow3D values for saving to a data file. The String is
  * processed by the Arrow3D(String) constructor to recreate a Arrow3D object when reading a saved
  * data file.
  *
  * @return String capturing all Arrow3D field values
  */
 public String outString() {
   String ms = null;
   if (m != null) {
     if (m.getDiffuseColor() != null) {
       ms = m.getDiffuseColor().toString();
     }
     if (m.getSpecularColor() != null) {
       ms = ms.concat(", " + m.getSpecularColor().toString());
     }
   }
   return "Arrow: "
       + p1.getX()
       + ", "
       + p1.getY()
       + ", "
       + p1.getZ()
       + ", "
       + p2.getX()
       + ", "
       + p2.getY()
       + ", "
       + p2.getZ()
       + ", "
       + arrowRadius
       + ", "
       + ms;
 }
Exemple #3
0
 public static final Point3D minus(final Point3D p, final Point3D q) {
   return Point3DBuilder.create()
       .x(p.getX() - q.getX())
       .y(p.getY() - q.getY())
       .z(p.getZ() - q.getZ())
       .build();
 }
Exemple #4
0
 public static final Point3D crossProduct(final Point3D p, final Point3D q) {
   return Point3DBuilder.create()
       .x(p.getY() * q.getZ() - p.getZ() * q.getY())
       .y(p.getZ() * q.getX() - p.getX() * q.getZ())
       .z(p.getX() * q.getY() - p.getY() * q.getX())
       .build();
 }
Exemple #5
0
  /**
   * Provides the Arrow3D line mid-point (in user coordinate space)
   *
   * @return midpoint Point3D location of the Arrow midpoint
   */
  public Point3D midpoint() {
    double x, y, z;
    x = (p1.getX() + p2.getX()) / 2.0;
    y = (p1.getY() + p2.getY()) / 2.0;
    z = (p1.getZ() + p2.getZ()) / 2.0;

    return new Point3D(x, y, z);
  }
Exemple #6
0
  /**
   * Provides the projected Arrow3D angle between xz axes
   *
   * @return theta Double value of angle of projected xz arrow line
   */
  public double theta() {
    // Relocate line start point to origin
    double x = p2.getX() - p1.getX();
    double y = p2.getY() - p1.getY();
    double z = p2.getZ() - p1.getZ();

    // Compute theta
    return Math.atan2(z, x);
  }
  private static Point3D rotateY(Point3D p, Point3D axis, double radians) {
    Point3D input =
        new Point3D(p.getX() - axis.getX(), p.getY() - axis.getY(), p.getZ() - axis.getZ());

    return new Point3D(
        input.getZ() * Math.sin(radians) + input.getX() * Math.cos(radians) + axis.getX(),
        input.getY() + axis.getY(),
        input.getZ() * Math.cos(radians) - input.getX() * Math.sin(radians) + axis.getZ());
  }
Exemple #8
0
  public void SetTickSeperationXYZ(Point3D newTickSpeperation) {
    this.tickSeperationXYZ = newTickSpeperation;

    xAxisGrid.setTickSeperationXY(new Point2D(tickSeperationXYZ.getY(), tickSeperationXYZ.getZ()));

    yAxisGrid.setTickSeperationXY(new Point2D(tickSeperationXYZ.getZ(), tickSeperationXYZ.getX()));

    zAxisGrid.setTickSeperationXY(new Point2D(tickSeperationXYZ.getX(), tickSeperationXYZ.getY()));
  }
Exemple #9
0
 /**
  * Creates a new Arrow3D object scaled by the value t
  *
  * @param t double scalar value to multiply Arrow line components
  * @return Arrow3D scaled by t
  */
 public Arrow3D multiply(double t) {
   double x2 = t * (p2.getX() - p1.getX()) + p1.getX();
   double y2 = t * (p2.getY() - p1.getY()) + p1.getY();
   double z2 = t * (p2.getZ() - p1.getZ()) + p1.getZ();
   Point3D newp = new Point3D(x2, y2, z2);
   Arrow3D newa = new Arrow3D(p1, newp);
   newa.setMaterial(m);
   newa.setArrowRadius(arrowRadius);
   return newa;
 }
Exemple #10
0
  public void checkScale(Point3D newMaxLengthXYZ) {
    // yz
    xAxisGrid.updateGrid(new Point2D(newMaxLengthXYZ.getY(), newMaxLengthXYZ.getZ()));
    // zx
    yAxisGrid.updateGrid(new Point2D(newMaxLengthXYZ.getZ(), newMaxLengthXYZ.getX()));
    // xy
    zAxisGrid.updateGrid(new Point2D(newMaxLengthXYZ.getX(), newMaxLengthXYZ.getY()));

    reDeclareLabels();
  }
Exemple #11
0
 private void reDeclareLabels() {
   xAxisGrid.reDeclareLabels(
       new Point2D(axisLimitMin.getY(), axisLimitMin.getZ()),
       new Point2D(axisLimitMax.getY(), axisLimitMax.getZ()));
   yAxisGrid.reDeclareLabels(
       new Point2D(axisLimitMin.getZ(), axisLimitMin.getX()),
       new Point2D(axisLimitMax.getZ(), axisLimitMax.getX()));
   zAxisGrid.reDeclareLabels(
       new Point2D(axisLimitMin.getX(), axisLimitMin.getY()),
       new Point2D(axisLimitMax.getX(), axisLimitMax.getY()));
 }
Exemple #12
0
  /**
   * Provides the Arrow3D angle with y axis
   *
   * @return phi Double value of angle of arrow line to y axis
   */
  public double phi() {
    double x, y, z;
    // Relocate line start point to origin
    x = p2.getX() - p1.getX();
    y = p2.getY() - p1.getY();
    z = p2.getZ() - p1.getZ();

    // Compute phi
    double rho = Math.sqrt(x * x + y * y + z * z);
    return Math.acos(-y / rho);
  }
Exemple #13
0
 private AxisGrid createBasicAxisGrid(
     Point3D planeVectorXYZ, Point2D tickSeperationXY, Point2D axisLengthXY, double thickness) {
   AxisGrid tempGrid =
       new AxisGrid(
           planeVectorXYZ, tickSeperationXY, axisLengthXY, thickness, tickSeperationXYZ.getX());
   return tempGrid;
 }
    /**
     * Rotates the Cell towards the Viewer when it is close to the center. Also mirrors the cells
     * after they passed the center to keep the Cells correctly visible for the viewer.
     */
    public void applyViewRotation() {
      if (index < 3) {
        double angle = index > -3 ? Math.PI / 2 * -index / 3 + Math.PI / 2 : Math.PI;

        Point3D axis = new Point3D((ul.getX() + ur.getX()) / 2, 0, (ul.getZ() + ur.getZ()) / 2);

        ul = rotateY(ul, axis, angle);
        ur = rotateY(ur, axis, angle);
        ll = rotateY(ll, axis, angle);
        lr = rotateY(lr, axis, angle);

        if (reflection != null) {
          ulReflection = rotateY(ulReflection, axis, angle);
          urReflection = rotateY(urReflection, axis, angle);
        }
      }
    }
Exemple #15
0
  AxisLineOld(double radius, double height, Rotate rotate, Point3D offset) {
    super(radius, height);
    this.rotate = rotate;
    this.offset = new Translate(offset.getX(), offset.getY(), offset.getZ());
    ;

    this.getTransforms().addAll(this.rotate, this.offset);
  }
 public Point3D unTransform(Point3D p) {
   try {
     javafx.geometry.Point3D ta = a.inverseTransform(p.x, p.y, p.z);
     return new Point3D((float) ta.getX(), (float) ta.getY(), (float) ta.getZ());
   } catch (NonInvertibleTransformException ex) {
     System.out.println("p not invertible " + p);
   }
   return p;
 }
Exemple #17
0
 public static final Point3D absoluteSum(final Collection<Point3D> c) {
   double x = 0d;
   double y = 0d;
   double z = 0d;
   for (Point3D p : c) {
     x += Math.abs(p.getX());
     y += Math.abs(p.getY());
     z += Math.abs(p.getZ());
   }
   return new Point3D(x, y, z);
 }
Exemple #18
0
  private Cylinder createScaleAxis(Point3D direction, double length, double thickness) {
    // generate the cylinder
    // default position is centered on (0,0,0) in direction (0,1,0)
    Cylinder tempBox = new Cylinder(thickness, length * 1.05d);

    // rotate the axis to face the right direction
    // in this case the axis
    tempBox.getTransforms().add(Vector3DUtil.rotateVector(new Point3D(0, 1, 0), direction));
    tempBox.getTransforms().add(new Translate(0, (length * 1.05d) / 2, 0));

    // create the material to colour the axis
    PhongMaterial mat = new PhongMaterial();
    mat.setDiffuseColor(new Color(direction.getX(), direction.getY(), direction.getZ(), 1));
    mat.setSpecularColor(new Color(direction.getX(), direction.getY(), direction.getZ(), 1));

    // set the material -> ie colour the axis
    tempBox.setMaterial(mat);

    return tempBox;
  }
Exemple #19
0
 /**
  * Returns a String containing all Box3D values for saving to a data file. The String is processed
  * by the Box3D(String) constructor to recreate a Box3D object when reading a saved data file.
  *
  * @return String capturing all Box field values
  */
 public String outString() {
   String ms = null;
   if (m != null) {
     if (m.getDiffuseColor() != null) {
       ms = m.getDiffuseColor().toString();
     }
     if (m.getSpecularColor() != null) {
       ms = ms.concat(", " + m.getSpecularColor().toString());
     }
   }
   return "Box: " + p.getX() + ", " + p.getY() + ", " + p.getZ() + ", " + width + ", " + height
       + ", " + depth + ", " + xr + ", " + yr + ", " + zr + ", " + dm + ", " + cf + ", " + ms;
 }
Exemple #20
0
  public AxisGroup(
      Point3D origin, Point3D maxLength, double axisThickness, Point3D tickSeperationXYZ) {

    this.tickSeperationXYZ = tickSeperationXYZ;

    // create axis grids
    // yz plane
    this.getChildren()
        .add(
            xAxisGrid =
                createBasicAxisGrid(
                    new Point3D(1, 0, 0),
                    new Point2D(tickSeperationXYZ.getY(), tickSeperationXYZ.getZ()),
                    new Point2D(maxLength.getY(), maxLength.getZ()),
                    axisThickness / 10));

    // zx plane
    this.getChildren()
        .add(
            yAxisGrid =
                createBasicAxisGrid(
                    new Point3D(0, 1, 0),
                    new Point2D(tickSeperationXYZ.getZ(), tickSeperationXYZ.getX()),
                    new Point2D(maxLength.getZ(), maxLength.getX()),
                    axisThickness / 10));

    // xy plane
    this.getChildren()
        .add(
            zAxisGrid =
                createBasicAxisGrid(
                    new Point3D(0, 0, 1),
                    new Point2D(tickSeperationXYZ.getX(), tickSeperationXYZ.getY()),
                    new Point2D(maxLength.getX(), maxLength.getY()),
                    axisThickness / 10));
  }
Exemple #21
0
 public static String getRightRotation(Point3D p, String selFaces) {
   double radius = p.magnitude();
   double angle = Math.atan2(p.getY(), p.getX());
   String face = "";
   if (radius >= radMinimum && selFaces.contains("-") && selFaces.split("-").length == 2) {
     String[] faces = selFaces.split("-");
     // select rotation if p.getX>p.getY
     if (-Math.PI / 4d <= angle && angle < Math.PI / 4d) { // X
       face = faces[0];
     } else if (Math.PI / 4d <= angle && angle < 3d * Math.PI / 4d) { // Y
       face = faces[1];
     } else if ((3d * Math.PI / 4d <= angle && angle <= Math.PI)
         || (-Math.PI <= angle && angle < -3d * Math.PI / 4d)) { // -X
       face = reverseRotation(faces[0]);
     } else { // -Y
       face = reverseRotation(faces[1]);
     }
     System.out.println("face: " + face);
   } else if (!face.isEmpty() && radius < radMinimum) { // reset previous face
     face = "";
   }
   return face;
 }
Exemple #22
0
 public static final Point3D plus(
     final Point3D p, final double dx, final double dy, final double dz) {
   if (dy == 0d && dy == 0d && dz == 0d) return p;
   else return new Point3D(p.getX() + dx, p.getY() + dy, p.getZ() + dz);
 }
Exemple #23
0
 public static final Point3D multiply(final double f, final Point3D p) {
   return Point3DBuilder.create().x(p.getX() * f).y(p.getY() * f).z(p.getZ() * f).build();
 }
Exemple #24
0
 public static final Point3D divide(final Point3D p, final double f) {
   return Point3DBuilder.create().x(p.getX() / f).y(p.getY() / f).z(p.getZ() / f).build();
 }
 private Point3D transform(Point3D p) {
   javafx.geometry.Point3D ta = a.transform(p.x, p.y, p.z);
   return new Point3D((float) ta.getX(), (float) ta.getY(), (float) ta.getZ());
 }
Exemple #26
0
 public static final double scalarProduct(final Point3D p, final Point3D q) {
   return p.getX() * q.getX() + p.getY() * q.getY() + p.getZ() * q.getZ();
 }
 private static Point2D project(Point3D p, double viewDistance, double fov, double cw, double ch) {
   return new Point2D(
       p.getX() * fov / (p.getZ() + viewDistance) + cw,
       p.getY() * fov / (p.getZ() + viewDistance) + ch);
 }
 private Point3D transform(double x, double y, double z) {
   javafx.geometry.Point3D ta = a.transform(x, y, z);
   return new Point3D((float) ta.getX(), (float) ta.getY(), (float) ta.getZ());
 }
Exemple #29
0
  public static String getPickedRotation(int cubie, MeshView mesh) {
    Point3D normal = getMeshNormal(mesh);
    String rots = ""; // Rx-Ry
    switch (cubie) {
      case 0:
        rots =
            (normal.getZ() > 0.99)
                ? "Ui-Li"
                : ((normal.getX() < -0.99) ? "Ui-F" : ((normal.getY() > 0.99) ? "Ui-Li" : ""));
        break;
      case 1:
        rots =
            (normal.getZ() > 0.99)
                ? "F-Mi"
                : ((normal.getY() > 0.99) ? "Ui-Mi" : ""); // between L and R, as L
        break;
      case 2:
        rots =
            (normal.getZ() > 0.99)
                ? "Ui-R"
                : ((normal.getX() > 0.99) ? "Ui-Fi" : ((normal.getY() > 0.99) ? "Ui-R" : ""));
        break;
      case 3:
        rots =
            (normal.getZ() > 0.99)
                ? "E-F"
                : ((normal.getX() < -0.99) ? "E-Li" : ""); // between U and D, as D
        break;
      case 4:
        rots = (normal.getZ() > 0.99) ? "Yi-X" : "";
        break;
      case 5:
        rots =
            (normal.getZ() > 0.99)
                ? "E-Fi"
                : ((normal.getX() > 0.99) ? "E-R" : ""); // between U and D, as D
        break;
      case 6:
        rots =
            (normal.getZ() > 0.99)
                ? "D-Li"
                : ((normal.getX() < -0.99) ? "D-F" : ((normal.getY() < -0.99) ? "D-Li" : ""));
        break;
      case 7:
        rots =
            (normal.getZ() > 0.99)
                ? "Fi-Mi"
                : ((normal.getY() < -0.99) ? "Fi-Mi" : ""); // between L and R, as L
        break;
      case 8:
        rots =
            (normal.getZ() > 0.99)
                ? "D-R"
                : ((normal.getX() > 0.99) ? "D-Fi" : ((normal.getY() < -0.99) ? "D-R" : ""));
        break;

      case 9:
        rots =
            (normal.getY() > 0.99)
                ? "S-U"
                : ((normal.getX() < -0.99) ? "L-S" : ""); // between U and D, as D
        break;
      case 10:
        rots = (normal.getY() > 0.99) ? "Z-X" : "";
        break;
      case 11:
        rots =
            (normal.getY() > 0.99)
                ? "S-Ui"
                : ((normal.getX() > 0.99) ? "R-Si" : ""); // between U and D, as D
        break;
      case 12:
        rots = (normal.getX() < -0.99) ? "Yi-Z" : "";
        break;
      case 14:
        rots = (normal.getX() > 0.99) ? "Yi-Zi" : "";
        break;
      case 15:
        rots =
            (normal.getY() < -0.99)
                ? "D-S"
                : ((normal.getX() < -0.99) ? "Li-S" : ""); // between U and D, as D
        break;
      case 16:
        rots = (normal.getY() < -0.99) ? "Zi-X" : "";
        break;
      case 17:
        rots =
            (normal.getY() < -0.99)
                ? "D-S"
                : ((normal.getX() > 0.99) ? "Ri-Si" : ""); // between U and D, as D
        break;

      case 18:
        rots =
            (normal.getZ() < -0.99)
                ? "Ui-L"
                : ((normal.getX() < -0.99) ? "Ui-Bi" : ((normal.getY() > 0.99) ? "Ui-L" : ""));
        break;
      case 19:
        rots =
            (normal.getZ() < -0.99)
                ? "B-M"
                : ((normal.getY() > 0.99) ? "U-M" : ""); // between L and R, as L
        break;
      case 20:
        rots =
            (normal.getZ() < -0.99)
                ? "Ui-Ri"
                : ((normal.getX() > 0.99) ? "Ui-B" : ((normal.getY() > 0.99) ? "Ui-Ri" : ""));
        break;
      case 21:
        rots =
            (normal.getZ() < -0.99)
                ? "E-Bi"
                : ((normal.getX() < -0.99) ? "E-L" : ""); // between U and D, as D
        break;
      case 22:
        rots = (normal.getZ() < -0.99) ? "Yi-Xi" : "";
        break;
      case 23:
        rots =
            (normal.getZ() < -0.99)
                ? "E-B"
                : ((normal.getX() > 0.99) ? "E-Ri" : ""); // between U and D, as D
        break;
      case 24:
        rots =
            (normal.getZ() < -0.99)
                ? "D-L"
                : ((normal.getX() < -0.99) ? "D-Bi" : ((normal.getY() < -0.99) ? "D-L" : ""));
        break;
      case 25:
        rots =
            (normal.getZ() < -0.99)
                ? "Bi-M"
                : ((normal.getY() < -0.99) ? "Bi-M" : ""); // between L and R, as L
        break;
      case 26:
        rots =
            (normal.getZ() < -0.99)
                ? "D-Ri"
                : ((normal.getX() > 0.99) ? "D-B" : ((normal.getY() < -0.99) ? "D-B" : ""));
        break;
    }
    return rots;
  }
Exemple #30
0
 /**
  * Provides the Arrow3D line length (in user coordinate space)
  *
  * @return length Double value of the Arrow length
  */
 public double length() {
   return Math.sqrt(
       (p1.getX() - p2.getX()) * (p1.getX() - p2.getX())
           + (p1.getY() - p2.getY()) * (p1.getY() - p2.getY())
           + (p1.getZ() - p2.getZ()) * (p1.getZ() - p2.getZ()));
 }