public int compare(Intersection losiA, Intersection losiB) { if (losiA.intersectionPoint == null || losiB.intersectionPoint == null) return 0; double dA = refPoint.distanceTo3(losiA.intersectionPoint); double dB = refPoint.distanceTo3(losiB.intersectionPoint); return dA < dB ? -1 : dA == dB ? 0 : 1; } });
public final Vec4 add3(double x, double y, double z) { return new Vec4(this.x + x, this.y + y, this.z + z, this.w); }
/** * Computes two vectors mutually perpendicular to this vector and each other. * * @return an array of two unit vectors mutually orthogonal to this vector. */ public Vec4[] perpendicularVectors() { // For the first vector, use the direction of the least component of this, which indicates the more // orthogonal axis to this. Vec4 v = this; Vec4 v1 = v.x <= v.y && v.x <= v.z ? Vec4.UNIT_X : v.y <= v.x && v.y <= v.z ? Vec4.UNIT_Y : Vec4.UNIT_Z; Vec4 va = v.cross3(v1).normalize3(); Vec4 vb = v.cross3(va).normalize3(); return new Vec4[] {va, vb}; }
public final Vec4 projectOnto3(Vec4 vec4) { if (vec4 == null) { throw new IllegalArgumentException("Vec4 Is Null"); } double dot = this.dot3(vec4); double length = vec4.getLength3(); // Normalize the dot product, if necessary. if (!(length == 0) && (length != 1.0)) dot /= (length * length); return vec4.multiply3(dot); }
Vec4 segmentBegin = new Vec4(begin.getLongitude().degrees, begin.getLatitude().degrees, 0); Vec4 segmentEnd = new Vec4(end.getLongitude().degrees, end.getLatitude().degrees, 0); Vec4 tmp = segmentEnd.subtract3(segmentBegin); Vec4 segmentCenter = segmentBegin.add3(segmentEnd).divide3(2); Vec4 segmentDirection = tmp.normalize3(); double segmentExtent = tmp.getLength3() / 2.0; Vec4 boxCenter = new Vec4(centroid.getLongitude().degrees, centroid.getLatitude().degrees, 0); double boxExtentX = this.getDeltaLonDegrees() / 2.0; double boxExtentY = this.getDeltaLatDegrees() / 2.0; Vec4 diff = segmentCenter.subtract3(boxCenter); Vec4 segmentPerp = new Vec4(segmentDirection.y, -segmentDirection.x, 0); return Math.abs(segmentPerp.dot3(diff)) <= (boxExtentX * Math.abs(segmentPerp.x) + boxExtentY * Math.abs(segmentPerp.y));
if (eye.distanceTo3(center) <= EPSILON) Vec4 forward = center.subtract3(eye); Vec4 f = forward.normalize3(); Vec4 s = f.cross3(up); s = s.normalize3(); if (s.getLength3() <= EPSILON) Vec4 u = s.cross3(f); u = u.normalize3();
Vec4 ru = new Vec4(1, 0, 0, 1); Vec4 su = new Vec4(0, 1, 0, 1); Vec4 tu = new Vec4(0, 0, 1, 1); double d = center.getLength3(); double dr = (center.x < 0) ? 0.5d : -0.5d; double ds = (center.y < 0) ? 0.5d : -0.5d; planes[5] = new Plane(+tu.x, +tu.y, +tu.z, d - dt); Vec4 rHalf = r.multiply3(0.5); Vec4 topCenter = center.add3(rHalf); Vec4 bottomCenter = center.subtract3(rHalf);
Vec4 midpoint = p0.add3(p1).multiply3(0.5); Vec4 midpointLength = midpoint.getAbs3(); Vec4 halfSegment = p1.subtract3(midpoint); Vec4 halfSegmentLength = halfSegment.getAbs3(); Vec4 halfSideLength = new Vec4(this.rLength, this.sLength, this.tLength); halfSideLength = halfSideLength.multiply3(0.5); halfSideLength = halfSideLength.add3(expansion); return false; // segment cannot intersect on z axis halfSegmentLength = halfSegmentLength.add3( PrecisionDouble.EPSILON, PrecisionDouble.EPSILON,
/** * Indicates whether three vectors are colinear. * * @param a the first vector. * @param b the second vector. * @param c the third vector. * * @return true if the vectors are colinear, otherwise false. * * @throws IllegalArgumentException if any argument is null. */ public static boolean areColinear(Vec4 a, Vec4 b, Vec4 c) { if (a == null || b == null || c == null) { throw new IllegalArgumentException("Vec4 Is Null"); } Vec4 ab = b.subtract3(a).normalize3(); Vec4 bc = c.subtract3(b).normalize3(); return Math.abs(ab.dot3(bc)) > 0.999; // ab and bc are considered colinear if their dot product is near +/-1 } }
/** * Returns the plane that passes through the specified three points. The plane's normal is the cross product of the * two vectors from <code>pb</code> to </code>pa</code> and <code>pc</code> to </code>pa</code>, respectively. The * returned plane is undefined if any of the specified points are colinear. * * @param pa the first point. * @param pb the second point. * @param pc the third point. * * @return a <code>Plane</code> passing through the specified points. * * @throws IllegalArgumentException if <code>pa</code>, <code>pb</code>, or <code>pc</code> is <code>null</code>. */ public static Plane fromPoints(Vec4 pa, Vec4 pb, Vec4 pc) { if (pa == null || pb == null || pc == null) { throw new IllegalArgumentException("Vec4 Is Null"); } Vec4 vab = pb.subtract3(pa); Vec4 vac = pc.subtract3(pa); Vec4 n = vab.cross3(vac); double d = -n.dot3(pa); return new Plane(n.x, n.y, n.z, d); }
Vec4 cellRAxis = this.getRAxis().divide3(rCells); Vec4 cellSAxis = this.getSAxis().divide3(sCells); Vec4 cellTAxis = this.getTAxis().divide3(tCells); rPlane.getDistance() - rPlane.getNormal().dot3(cellRAxis.multiply3(r)), rPlane.getDistance() - rPlane.getNormal().dot3(cellRAxis.multiply3(r + 1)), sPlane.getDistance() - sPlane.getNormal().dot3(cellSAxis.multiply3(s)), sPlane.getDistance() - sPlane.getNormal().dot3(cellSAxis.multiply3(s + 1)), tPlane.getDistance() - tPlane.getNormal().dot3(cellTAxis.multiply3(t)), tPlane.getDistance() - tPlane.getNormal().dot3(cellTAxis.multiply3(t + 1))); this.cells[r][s][t].parent = this; this.cells[r][s][t].neighborhood = this.neighborhood;
public final Vec4 normalize3() { double length = this.getLength3(); // Vector has zero length. if (length == 0) { return this; } else { return new Vec4( this.x / length, this.y / length, this.z / length); } }
if (pa.equals(pb)) return null; double ldotv = this.n.dot3(line.getDirection()); double ldots = this.n.dot4(line.getOrigin()); if (ldots == 0) return new Vec4[] {pa, pb}; // line is coincident with the plane double t = -this.n.dot4(line.getOrigin()) / ldotv; // ldots / ldotv if (t < 0 || t > 1) // segment does not intersect return null;
public final Angle angleBetween3(Vec4 vec4) { if (vec4 == null) { throw new IllegalArgumentException("Vec4 Is Null"); } double a_dot_b = this.dot3(vec4); // Compute the sum of magnitudes. double length = this.getLength3() * vec4.getLength3(); // Normalize the dot product, if necessary. if (!(length == 0) && (length != 1.0)) a_dot_b /= length; // The normalized dot product should be in the range [-1, 1]. Otherwise the result is an error from floating // point roundoff. So if a_dot_b is less than -1 or greater than +1, we treat it as -1 and +1 respectively. if (a_dot_b < -1.0) a_dot_b = -1.0; else if (a_dot_b > 1.0) a_dot_b = 1.0; // Angle is arc-cosine of normalized dot product. return Angle.fromRadians(Math.acos(a_dot_b)); }
/** * Determine if a point is behind the <code>Line</code>'s origin. * * @param point The point to test. * * @return true if <code>point</code> is behind this <code>Line</code>'s origin, false otherwise. */ public boolean isPointBehindLineOrigin(Vec4 point) { double dot = point.subtract3(this.getOrigin()).dot3(this.getDirection()); return dot < 0.0; }
public final double selfDot() { return this.origin.dot3(this.direction); }
Vec4 u1 = v1.normalize3(); Vec4 u0 = v2.normalize3(); Angle angle = Angle.fromRadians(Math.acos(u0.x * u1.x + u0.y * u1.y + u0.z * u1.z)); double C = (u0.x * u1.y) - (u0.y * u1.x); double L = Math.sqrt(A * A + B * B + C * C); result[0] = new Vec4(A / L, B / L, C / L);
public final Vec4 perpendicularTo3(Vec4 vec4) { if (vec4 == null) { throw new IllegalArgumentException("Vec4 Is Null"); } return this.subtract3(projectOnto3(vec4)); }