public Optional<EnumFacing> classify(Vector3f normalVec) { for (Pair<Vector3f, EnumFacing> e : sideOrder) { final Vector3f base = e.getKey(); if (normalVec.equals(base)) return Optional.of(e.getValue()); // cos > 0 only in 0..90 deg final double angleCos = base.dot(normalVec); if (angleCos > 0) return Optional.of(e.getValue()); } return Optional.empty(); } }
/** * Returns the angle in radians between this vector and the vector * parameter; the return value is constrained to the range [0,PI]. * @param v1 the other vector * @return the angle in radians in the range [0,PI] */ public final float angle(Vector3f v1) { double vDot = this.dot(v1) / ( this.length()*v1.length() ); if( vDot < -1.0) vDot = -1.0; if( vDot > 1.0) vDot = 1.0; return((float) (Math.acos( vDot ))); }