@Override public Vector2 sub(ImmutableVector<Vector2> b) { Vector2 sum = b.clone(); x -= sum.x; y -= sum.y; return this; }
@Override public float[] getCoords() { return vec.getCoords(); }
public boolean isParallelTo(Line<E> g) { return g.dir.isParrallelTo(dir); }
public Line(ImmutableVector<E> a, ImmutableVector<E> dir) { if (dir.lengthQuad() == 0.) { throw new IllegalArgumentException("The direction vector must not have a length of zero!"); } this.a = a.clone(); this.dir = dir.clone().normalize(); }
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 <E extends Vector<E>> E[] generateExtrudedPoints( ImmutableVector<E> first, ImmutableVector<E> mid, ImmutableVector<E> last, float extrude) { ImmutableVector<E> dir1 = mid.clone().sub(first); ImmutableVector<E> dir2 = last.clone().sub(mid); ImmutableVector<E> left = dir1.clone().rotateCCW(2).normalize().mul(extrude); ImmutableVector<E> right = left.clone().mul(-1); if (dir1.isParrallelTo(dir2)) { return toArray(mid.clone().add(left), mid.clone().add(right)); } Line<E> firstLeft = Line.fromPoints(first.clone().add(left), mid.clone().add(left)); Line<E> firstRight = Line.fromPoints(first.clone().add(right), mid.clone().add(right)); left = dir2.clone().rotateCCW(2).normalize().mul(extrude); right = left.clone().mul(-1); Line<E> secondLeft = Line.fromPoints(last.clone().add(left), mid.clone().add(left)); Line<E> secondRight = Line.fromPoints(last.clone().add(right), mid.clone().add(right)); try { E leftResult = firstLeft.getIntersection(secondLeft); E rightResult = firstRight.getIntersection(secondRight); return toArray(leftResult, rightResult); } catch (Throwable t) { System.out.println(t); dir1.isParrallelTo(dir2); throw t; } }
@Override public float dot(ImmutableVector<E> b) { return vec.dot(b); }
@Override public Vector3 toVector3() { return vec.toVector3(); }
public double distance(ImmutableVector<E> v) { return sqrt(distanceQuad(v)); }
public boolean hasSameDirectionAs(ImmutableVector<E> b) { return almostEqual(getAngle(b), 0., 2); }
public boolean isZero() { return lengthQuad() == 0.; }
public Vector3 getIntersection(Line<Vector3> g) { float NdotD = g.getDirection().dot(normal); if (NdotD == 0) { throw new IllegalArgumentException("There is no intersecting point when a line is parallel to a plane"); } float delta = (-nDot - g.getStartingPoint().dot(normal)) / NdotD; return g.getStartingPoint().clone().add(g.getDirection().clone().mul(delta)); }
public float magnituteSqr() { return vec.dot(vec) + w * w;//normaly conjungate . quaternion, but shortened version }