matrix.setToCovarianceOfPoints(array, count, stride); matrix.extractEigenvectors(this.r, this.s, this.t); this.r.normalize(); this.s.normalize(); this.t.normalize(); Vec3 p = new Vec3(); for (int idx = 0; idx < count; idx += stride) { p.set(array[idx], array[idx + 1], array[idx + 2]); double pdr = p.dot(this.r); if (rMin > pdr) { rMin = pdr; double pds = p.dot(this.s); if (sMin > pds) { sMin = pds; double pdt = p.dot(this.t); if (tMin > pdt) { tMin = pdt; this.center.set(cx, cy, cz); this.topCenter.set(cx + rx_2, cy + ry_2, cz + rz_2); this.bottomCenter.set(cx - rx_2, cy - ry_2, cz - rz_2); this.r.multiply(rLen); this.s.multiply(sLen); this.t.multiply(tLen);
public void loadEyePoint(Vec3 eyePoint) { eyePoint.toArray(this.array, 0); GLES20.glUniform3fv(this.eyePointId, 1, this.array, 0); GLES20.glUniform1f(this.eyeMagnitudeId, (float) eyePoint.magnitude()); GLES20.glUniform1f(this.eyeMagnitude2Id, (float) eyePoint.magnitudeSquared()); }
Vec3 texCoord2d = this.texCoord2d.set(point).multiplyByMatrix(this.modelToTexCoord); this.prevPoint.set(point); } else { this.texCoord1d += point.distanceTo(this.prevPoint); this.prevPoint.set(point);
private double intersectsAt(Plane plane) { Vec3 n = plane.normal; double effectiveRadius = 0.5 * (Math.abs(this.s.dot(n)) + Math.abs(this.t.dot(n))); double z = (this.endPoint2.z - this.endPoint1.z) * t + this.endPoint1.z; if (bq1) { this.endPoint1.set(x, y, z); } else { this.endPoint2.set(x, y, z);
@Test public void testConstructor_NotNormalizedValues() { Vec3 n = new Vec3(3, 4, 5); Vec3 nExpected = new Vec3(n).normalize(); double distance = 6; double distanceExpected = distance / n.magnitude(); Plane plane = new Plane(n.x, n.y, n.z, distance); assertEquals("normal x", plane.normal.x, nExpected.x, 0); assertEquals("normal y", plane.normal.y, nExpected.y, 0); assertEquals("normal z", plane.normal.z, nExpected.z, 0); assertEquals("distance", plane.distance, distanceExpected, 0); }
@SuppressWarnings("SuspiciousNameCombination") private static Vec3 worldWindEcef(Vec3 officialEcef) { double x = officialEcef.y; double y = officialEcef.z; double z = officialEcef.x; return new Vec3(x, y, z); }
/** * Sets this bounding box to a unit box centered at the Cartesian origin (0, 0, 0). * * @return This bounding box set to a unit box */ public BoundingBox setToUnitBox() { this.center.set(0, 0, 0); this.bottomCenter.set(-0.5, 0, 0); this.topCenter.set(0.5, 0, 0); this.r.set(1, 0, 0); this.s.set(0, 1, 0); this.t.set(0, 0, 1); this.radius = Math.sqrt(3); return this; }
@Test public void testToString() throws Exception { Vec3 n = new Vec3(3, 4, 5).normalize(); double distance = 6; Plane plane = new Plane(n.x, n.y, n.z, distance); String string = plane.toString(); assertTrue("normal x", string.contains(Double.toString(plane.normal.x))); assertTrue("normal y", string.contains(Double.toString(plane.normal.y))); assertTrue("normal z", string.contains(Double.toString(plane.normal.z))); assertTrue("distance", string.contains(Double.toString(plane.distance))); }
mvpInv.unProject(left, bottom, viewport, bln = new Vec3(), blf = new Vec3()); mvpInv.unProject(right, bottom, viewport, brn = new Vec3(), brf = new Vec3()); mvpInv.unProject(left, top, viewport, tln = new Vec3(), tlf = new Vec3()); mvpInv.unProject(right, top, viewport, trn = new Vec3(), trf = new Vec3()); Vec3 va = new Vec3(tlf.x - bln.x, tlf.y - bln.y, tlf.z - bln.z); Vec3 vb = new Vec3(tln.x - blf.x, tln.y - blf.y, tln.z - blf.z); Vec3 nl = va.cross(vb); this.left.set(nl.x, nl.y, nl.z, -nl.dot(bln)); va.set(trn.x - brf.x, trn.y - brf.y, trn.z - brf.z); vb.set(trf.x - brn.x, trf.y - brn.y, trf.z - brn.z); Vec3 nr = va.cross(vb); this.right.set(nr.x, nr.y, nr.z, -nr.dot(brn)); va.set(brf.x - bln.x, brf.y - bln.y, brf.z - bln.z); vb.set(blf.x - brn.x, blf.y - brn.y, blf.z - brn.z); Vec3 nb = va.cross(vb); this.bottom.set(nb.x, nb.y, nb.z, -nb.dot(brn)); va.set(tlf.x - trn.x, tlf.y - trn.y, tlf.z - trn.z); vb.set(trf.x - tln.x, trf.y - tln.y, trf.z - tln.z); Vec3 nt = va.cross(vb); this.top.set(nt.x, nt.y, nt.z, -nt.dot(tln)); va.set(tln.x - brn.x, tln.y - brn.y, tln.z - brn.z); vb.set(trn.x - bln.x, trn.y - bln.y, trn.z - bln.z); Vec3 nn = va.cross(vb); this.near.set(nn.x, nn.y, nn.z, -nn.dot(bln));
@Override public boolean intersect(Line line, Vec3 result) { if (line == null) { throw new IllegalArgumentException( Logger.logMessage(Logger.ERROR, "BasicTerrain", "intersect", "missingLine")); } if (result == null) { throw new IllegalArgumentException( Logger.logMessage(Logger.ERROR, "BasicTerrain", "intersect", "missingResult")); } double minDist2 = Double.POSITIVE_INFINITY; for (int idx = 0, len = this.tiles.size(); idx < len; idx++) { // Translate the line to the terrain tile's local coordinate system. TerrainTile tile = this.tiles.get(idx); line.origin.subtract(tile.origin); // Compute the first intersection of the terrain tile with the line. The line is interpreted as a ray; // intersection points behind the line's origin are ignored. Store the nearest intersection found so far // in the result argument. if (line.triStripIntersection(tile.points, 3, this.triStripElements, this.triStripElements.length, this.intersectPoint)) { double dist2 = line.origin.distanceToSquared(this.intersectPoint); if (minDist2 > dist2) { minDist2 = dist2; result.set(this.intersectPoint).add(tile.origin); } } // Restore the line's origin to it's previous coordinate system. line.origin.add(tile.origin); } return minDist2 != Double.POSITIVE_INFINITY; }
/** * Tests the distance (or displacement) between two opposing position-vectors. * * @throws Exception */ @Test public void testDistanceTo() throws Exception { final double x1 = 3.1; final double y1 = 4.2; final double z1 = -5.3; final double x2 = -x1; final double y2 = -y1; final double z2 = -z1; Vec3 u = new Vec3(x1, y1, z1); Vec3 v = new Vec3(x2, y2, z2); double magnitude = u.magnitude(); double distanceTo = u.distanceTo(v); assertEquals("distance", magnitude * 2, distanceTo, Double.MIN_VALUE); }
/** * Tests the squared distance (or displacement) between two opposing position-vectors. * * @throws Exception */ @Test public void testDistanceToSquared() throws Exception { final double x1 = 3.1; final double y1 = 4.2; final double z1 = -5.3; final double x2 = -x1; final double y2 = -y1; final double z2 = -z1; Vec3 u = new Vec3(x1, y1, z1); Vec3 v = new Vec3(x2, y2, z2); double magnitude = u.magnitude(); double distanceToSquared = u.distanceToSquared(v); assertEquals("distance squared", Math.pow(magnitude * 2, 2), distanceToSquared, Double.MIN_VALUE); }
double m[] = matrix.m; this.r.set(m[0], m[4], m[8]); this.s.set(m[1], m[5], m[9]); this.t.set(m[2], m[6], m[10]); double sExtremes[] = {Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY}; double tExtremes[] = {Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY}; Vec3 p = new Vec3(); for (int idx = 0, len = points.length; idx < len; idx += 3) { p.set(points[idx], points[idx + 1], points[idx + 2]); adjustExtremes(this.r, rExtremes, this.s, sExtremes, this.t, tExtremes, p); double rz_2 = 0.5 * this.r.z * rLen; this.center.set(cx, cy, cz); this.topCenter.set(cx + rx_2, cy + ry_2, cz + rz_2); this.bottomCenter.set(cx - rx_2, cy - ry_2, cz - rz_2); this.r.multiply(rLen); this.s.multiply(sLen); this.t.multiply(tLen);
@Test public void testDistanceToPoint() throws Exception { Vec3 normal = new Vec3(3, 4, 5).normalize();// arbitrary orientation double distance = 10; // arbitrary distance Plane plane = new Plane(normal.x, normal.y, normal.z, distance); // The plane's normal points towards the origin, so use the normal's // reversed direction to create a point on the plane Vec3 point = new Vec3(normal).negate().multiply(distance); Vec3 origin = new Vec3(0, 0, 0); double distanceToOrigin = plane.distanceToPoint(origin); double distanceToPoint = plane.distanceToPoint(point); assertEquals("distance to origin", distance, distanceToOrigin, 0); assertEquals("distance to point on plane", 0, distanceToPoint, 0); }
@Test public void testPointAt() throws Exception { Vec3 origin = new Vec3(1, 2, 3); Vec3 direction = new Vec3(4, 5, 6); Line line = new Line(origin, direction); double distance = -2.0; Vec3 expected = new Vec3(origin).add(new Vec3(direction).multiply(distance)); Vec3 point = line.pointAt(distance, new Vec3()); assertEquals("point at", expected, point); }
@Test public void testDot() throws Exception { double distance = 6; Vec3 n = new Vec3(3, 4, 5).normalize(); Vec3 u = new Vec3(7, 8, 9); Plane plane = new Plane(n.x, n.y, n.z, distance); double expected = n.dot(u) + distance; double result = plane.dot(u); assertEquals("plane dot product", expected, result, 0); }
/** * Ensures cross with null argument is handled correctly. * * @throws Exception */ @Test(expected = IllegalArgumentException.class) public void testCross_WithNull() throws Exception { PowerMockito.mockStatic(Logger.class); Vec3 u = new Vec3(3, 4, 5); u.cross(null); fail("Expected an IllegalArgumentException to be thrown."); }
/** * Ensures add with null argument is handled correctly. * * @throws Exception */ @Test(expected = IllegalArgumentException.class) public void testAdd_WithNull() throws Exception { PowerMockito.mockStatic(Logger.class); Vec3 u = new Vec3(3, 4, 5); u.add(null); fail("Expected an IllegalArgumentException to be thrown."); }