private static Point3D getMeshNormal(MeshView mesh) { TriangleMesh tm = (TriangleMesh) mesh.getMesh(); float[] fPoints = new float[tm.getPoints().size()]; tm.getPoints().toArray(fPoints); Point3D BA = new Point3D(fPoints[3] - fPoints[0], fPoints[4] - fPoints[1], fPoints[5] - fPoints[2]); Point3D CA = new Point3D(fPoints[6] - fPoints[0], fPoints[7] - fPoints[1], fPoints[8] - fPoints[2]); Point3D normal = BA.crossProduct(CA); Affine a = new Affine(mesh.getTransforms().get(0)); return a.transform(normal.normalize()); }
public static Affine getAffine(double dimCube, double d0, boolean bFaceArrow, String face) { Affine aff; double d = 2d * dimCube / 3d; if (!bFaceArrow) { aff = new Affine(new Scale(80, 80, 50)); aff.append(new Translate(-d0, -d0, d0)); } else { aff = new Affine(new Scale(3, 3, 3)); aff.append(new Translate(0, -d0, 0)); } switch (face) { case "F": case "Fi": aff.prepend(new Rotate(face.equals("F") ? 90 : -90, Rotate.X_AXIS)); aff.prepend(new Rotate(face.equals("F") ? 45 : -45, Rotate.Z_AXIS)); aff.prepend(new Translate(0, 0, dimCube / 2d)); break; case "B": case "Bi": aff.prepend(new Rotate(face.equals("Bi") ? 90 : -90, Rotate.X_AXIS)); aff.prepend(new Rotate(face.equals("Bi") ? 45 : -45, Rotate.Z_AXIS)); aff.prepend(new Translate(0, 0, -dimCube / 2d)); break; case "R": case "Ri": aff.prepend(new Rotate(face.equals("Ri") ? 90 : -90, Rotate.Z_AXIS)); aff.prepend(new Rotate(face.equals("Ri") ? 45 : -45, Rotate.X_AXIS)); aff.prepend(new Translate(dimCube / 2d, 0, 0)); break; case "L": case "Li": aff.prepend(new Rotate(face.equals("L") ? 90 : -90, Rotate.Z_AXIS)); aff.prepend(new Rotate(face.equals("L") ? 45 : -45, Rotate.X_AXIS)); aff.prepend(new Translate(-dimCube / 2d, 0, 0)); break; case "U": case "Ui": aff.prepend(new Rotate(face.equals("Ui") ? 180 : 0, Rotate.Z_AXIS)); aff.prepend(new Rotate(face.equals("Ui") ? 45 : -45, Rotate.Y_AXIS)); aff.prepend(new Translate(0, dimCube / 2d, 0)); break; case "D": case "Di": aff.prepend(new Rotate(face.equals("D") ? 180 : 0, Rotate.Z_AXIS)); aff.prepend(new Rotate(face.equals("D") ? 45 : -45, Rotate.Y_AXIS)); aff.prepend(new Translate(0, -dimCube / 2d, 0)); break; case "Z": case "Zi": aff.prepend(new Rotate(face.equals("Zi") ? 180 : 0, Rotate.Y_AXIS)); aff.prepend(new Rotate(face.equals("Zi") ? 45 : -45, Rotate.Z_AXIS)); aff.prepend(new Translate(0, 0, d)); break; case "X": case "Xi": aff.prepend(new Rotate(face.equals("X") ? 90 : -90, Rotate.Y_AXIS)); aff.prepend(new Rotate(face.equals("Xi") ? 45 : -45, Rotate.X_AXIS)); aff.prepend(new Translate(d, 0, 0)); break; case "Y": case "Yi": aff.prepend(new Rotate(face.equals("Yi") ? 90 : -90, Rotate.X_AXIS)); aff.prepend(new Rotate(face.equals("Yi") ? 45 : -45, Rotate.Y_AXIS)); aff.prepend(new Translate(0, d, 0)); break; } return aff; }
/** * Assigns the transformation values of the <i>src</i> {@link Affine} to the <i>dst</i> {@link * Affine}. * * @param dst The destination {@link Affine}. * @param src The source {@link Affine}. * @return The destination {@link Affine} for convenience. */ protected static Affine setAffine(Affine dst, Affine src) { dst.setMxx(src.getMxx()); dst.setMxy(src.getMxy()); dst.setMxz(src.getMxz()); dst.setMyx(src.getMyx()); dst.setMyy(src.getMyy()); dst.setMyz(src.getMyz()); dst.setMzx(src.getMzx()); dst.setMzy(src.getMzy()); dst.setMzz(src.getMzz()); dst.setTx(src.getTx()); dst.setTy(src.getTy()); dst.setTz(src.getTz()); return dst; }
/** * Returns <code>true</code> if the given {@link Affine}s are equal. Otherwise returns <code>false * </code>. * * @param a1 The first operand. * @param a2 The second operand. * @return <code>true</code> if the given {@link Affine}s are equal, otherwise <code>false</code>. */ protected static boolean equals(Affine a1, Affine a2) { // Affine does not properly implement equals, so we have to implement // that here return a1.getMxx() == a2.getMxx() && a1.getMxy() == a2.getMxy() && a1.getMxz() == a2.getMxz() && a1.getMyx() == a2.getMyx() && a1.getMyy() == a2.getMyy() && a1.getMyz() == a2.getMyz() && a1.getMzx() == a2.getMzx() && a1.getMzy() == a2.getMzy() && a1.getMzz() == a2.getMzz() && a1.getTx() == a2.getTx() && a1.getTy() == a2.getTy() && a1.getTz() == a2.getTz(); }