public static <E extends Vector<E>> Plane fromPointAndDirection( ImmutableVector start, ImmutableVector<E> dir1, ImmutableVector<E> dir2) { return new Plane(start, dir1.toVector3().cross(dir2.toVector3())); }
/** * initializes a Quaternion which maps a Vector on another. * <p/> * @param old Source Vector which gets mapped. * @param map2 Destination Vector which the source Vector gets mapped to. */ public void mapVector(ImmutableVector<Vector3> old, ImmutableVector<Vector3> map2) { Vector3 o = old.clone().normalize(); Vector3 m = map2.clone().normalize(); float p = (float) acos(o.dot(m)); ini(o.cross(m), p); }
public static <E extends Vector<E>> Plane fromLineAndDirection( Line<E> g, ImmutableVector<E> dir) { return new Plane(g.getStartingPoint(), dir.toVector3().cross(g.getDirection().toVector3())); }
public double distanceTo(Line<E> g) { if (isParallelTo(g)) { return distanceTo(g.a); } else { //TODO Vector3 n = dir.toVector3().cross(g.dir.toVector3()).normalize(); return Math.abs(a.clone().sub(g.a).toVector3().dot(n)); } }
public static <E extends Vector<E>> Plane fromPoints(ImmutableVector<E> p1, ImmutableVector<E> p2, ImmutableVector<E> p3) { Vector<E> tmp = p2.clone().sub(p1); return new Plane(p1, tmp.toVector3().cross(p3.clone().sub(p1).toVector3())); }
public static <E extends Vector<E>> Plane fromPointAndLine( ImmutableVector<E> start, Line<E> g) { return new Plane(start, start.clone().sub(g.getStartingPoint()).toVector3().cross(g.getDirection().toVector3())); }
public Line<Vector3> getSchnittKante(Plane e) { Vector3 dir = normal.toVector3().cross(e.normal); float dot = normal.dot(e.normal); float tmp = 1 / (1 - dot * dot); float c1 = (e.nDot * dot - nDot) * tmp; float c2 = (nDot * dot - e.nDot) * tmp; Vector3 a = normal.clone().mul(c1); a.add(e.normal.clone().mul(c2)); return new Line(a, dir); }
private Float[] calculateTangent(Vertex v0, Vertex v1, Vertex v2) { Vector3 pos1 = getPosition(v0); Vector3 pos2 = getPosition(v1); Vector3 pos3 = getPosition(v2); Vector2 uv1 = getTexCoord(v0); Vector2 uv2 = getTexCoord(v1); Vector2 uv3 = getTexCoord(v2); Vector3 v2v1 = pos2.clone().sub(pos1); Vector3 v3v1 = pos3.clone().sub(pos1); float c2c1b = uv2.getY() - uv1.getY(); float c3c1b = uv3.getY() - uv1.getY(); Vector3 n = getNormal(v0); Vector3 t = new Vector3(c3c1b * v2v1.getX() - c2c1b * v3v1.getX(), c3c1b * v2v1.getY() - c2c1b * v3v1.getY(), c3c1b * v2v1.getZ() - c2c1b * v3v1.getZ()); Vector3 b = n.cross(t); Vector3 smoothTangent = b.cross(n).normalize(); return float2Float(smoothTangent.getCoords()); }
/** * Builds a orthogonal Coordinate System, where the given Vector represents * the given Axis. Both other Axis are generated in a way that no gurantee * can be given how their orientation are. * <p/> * @param dir direction Vector of the given Axis * @param a Axis of the given Vektor */ public static Matrix4 createCoordinateSystem(ImmutableVector<Vector3> dir, Axis a) { Matrix4 res = new Matrix4(); res.loadIdentity(); Vector3 di = dir.clone().normalize(); res.setAxis(di, a); Vector3 dir2 = new Vector3(di.getY(), di.getZ(), -di.getX()); Vector3 dir3 = dir.clone().cross(dir2); Axis[] vals = Axis.values(); int a2 = a.ordinal(); a2 = (1 << a2) & 3; //(ordinal+1)%3 int a3 = (1 << a2) & 3;//(ordinal+2)%3 res.setAxis(dir2, vals[a2]); res.setAxis(dir3, vals[a3]); return res; }