@Override public E sub(float b) { return vec.clone().sub(b); }
@Override public E sub(ImmutableVector<E> b) { return vec.clone().sub(b); }
public static <E extends Vector<E>> Line<E> fromPoints(ImmutableVector<E> a, ImmutableVector<E> b) { return new Line<>(a, a.clone().sub(b)); }
public double distanceQuad(ImmutableVector<E> v) { return clone().sub(v).lengthQuad(); }
public boolean contains(ImmutableVector<E> p) { return p.clone().sub(a).isParrallelTo(dir); }
public boolean isElement(ImmutableVector<E> point) { Vector<E> t = point.clone().sub(start); Vector<E> dir = end.clone().sub(start); if (t.isParrallelTo(dir)) { float[] dc = dir.getCoords(); for (int i = 0; i < dc.length; i++) { if (dc[i] != 0) { float mul = t.getCoords()[i] / dc[i]; return 0 <= mul && mul <= 1f; } } } return false; }
public E reflect(ImmutableVector<E> normal) { E n = normal.clone(); n.mul(dot(n) * 2); sub(n); return (E) this; }
public double distanceToSquared(ImmutableVector<E> p) { Vector<E> tmp = a.clone().sub(p); return tmp.lengthQuad() - dir.dot(tmp); }
public boolean isElement(ImmutableVector<E> point) { return point.clone().sub(getStartingPoint()).isParrallelTo(getDirection()); }
float[] c = g.a.clone().sub(a).getCoords();
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 fromPointAndLine( ImmutableVector<E> start, Line<E> g) { return new Plane(start, start.clone().sub(g.getStartingPoint()).toVector3().cross(g.getDirection().toVector3())); }
public boolean isSkewTo(Line<E> g) { ImmutableVector<Vector3> tmp = a.clone().sub(g.a).toVector3(); return !tmp.clone().cross(dir.toVector3()).isParrallelTo(tmp.clone().cross(g.dir.toVector3())); }
private <E extends Vector<E>> E[] generateExtrudedEndPoints( ImmutableVector<E> end, ImmutableVector<E> other, float extrude) { Vector<E> dir = other.clone().sub(end); ImmutableVector<E> ex = dir.clone().rotateCCW(2).normalize(); return toArray( ex.clone().mul(extrude).add(end), ex.clone().mul(-extrude).add(end)); }
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; } }