org.joml.Vector3d Java Examples
The following examples show how to use
org.joml.Vector3d.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RenderedMap.java From BlockMap with MIT License | 6 votes |
/** Returns the next Region to render */ protected synchronized RenderedRegion nextRegion() { try { // In region coordinates Vector3d cursorPos = new Vector3d(mouseWorldProperty.get(), 0).div(512).sub(.5, .5, 0); Comparator<RenderedRegion> comp = (a, b) -> Double.compare(new Vector3d(a.position.x(), a.position.y(), 0).sub(cursorPos).length(), new Vector3d(b.position.x(), b.position.y(), 0).sub(cursorPos).length()); RenderedRegion min = null; for (RenderedRegion r : notRendered) if (r.getImage() == null && (min == null || comp.compare(min, r) > 0)) min = r; notRendered.remove(min); return min; } catch (Throwable e) { e.printStackTrace(); throw new Error(e); } }
Example #2
Source File: VertexUtils.java From AnalyzeSkeleton with GNU General Public License v3.0 | 6 votes |
private static List<Double> getAngles(final Vertex junction) { final List<Double> angles = new ArrayList<>(); final Vector3d centroid = PointUtils.centroid(junction.getPoints()); final List<Edge> branches = junction.getBranches(); for (int i = 0; i < branches.size() - 1; i++) { for (int j = i + 1; j < branches.size(); j++) { final Vector3d endpoint = getOppositeCentroid(junction, centroid, branches.get(i)); final Vector3d endpoint2 = getOppositeCentroid(junction, centroid, branches.get(j)); final double angle = endpoint.angle(endpoint2); angles.add(angle); } } return angles; }
Example #3
Source File: EnergyCalculator.java From OSPREY3 with GNU General Public License v2.0 | 6 votes |
/** calculate the pair energy between position i1 and position i2 */ default double calcEnergyPair(AssignedCoords coords, int posi1, int posi2) { double energy = 0.0; // TODO: hopefully escape analysis will allocate this on the stack? Vector3d pos1 = new Vector3d(); Vector3d pos2 = new Vector3d(); int ffi = ffi(); ConfSpace.IndicesPair indices = coords.getIndices(ffi, posi1, posi2); for (int i=0; i<indices.size(); i++) { int confAtomi1 = indices.getConfAtom1Index(i); int confAtomi2 = indices.getConfAtom2Index(i); int paramsi = indices.getParamsIndex(i); coords.coords.get(coords.getConfIndex(posi1, confAtomi1), pos1); coords.coords.get(coords.getConfIndex(posi2, confAtomi2), pos2); double r2 = pos1.distanceSquared(pos2); double r = Math.sqrt(r2); energy += calcEnergy(r, r2, coords.getParams(ffi, paramsi)); } return energy; }
Example #4
Source File: EnergyCalculator.java From OSPREY3 with GNU General Public License v2.0 | 6 votes |
/** calculate the pair energy between position i and the static atoms */ default double calcEnergyStatic(AssignedCoords coords, int posi) { double energy = 0.0; // TODO: hopefully escape analysis will allocate this on the stack? Vector3d pos1 = new Vector3d(); Vector3d pos2 = new Vector3d(); int ffi = ffi(); ConfSpace.IndicesSingle indices = coords.getIndices(ffi, posi); for (int i=0; i<indices.sizeStatics(); i++) { int confAtomi = indices.getStaticConfAtomIndex(i); int staticAtomi = indices.getStaticStaticAtomIndex(i); int paramsi = indices.getStaticParamsIndex(i); coords.coords.get(coords.getConfIndex(posi, confAtomi), pos1); coords.coords.get(coords.getStaticIndex(staticAtomi), pos2); double r2 = pos1.distanceSquared(pos2); double r = Math.sqrt(r2); energy += calcEnergy(r, r2, coords.getParams(ffi, paramsi)); } return energy; }
Example #5
Source File: Quadric.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
/** * Creates a design matrix used for least squares fitting from a collection of * points. * * @see #solveVector(Collection) * @param points points in a 3D space. * @return a [points.size()][9] matrix of real values. */ private static PrimitiveMatrix createDesignMatrix( final Collection<Vector3d> points) { final BasicMatrix.Builder<PrimitiveMatrix> builder = PrimitiveMatrix.FACTORY .getBuilder(points.size(), MIN_DATA); final Iterator<Vector3d> iterator = points.iterator(); for (int i = 0; i < points.size(); i++) { final Vector3d p = iterator.next(); builder.set(i, 0, p.x * p.x); builder.set(i, 1, p.y * p.y); builder.set(i, 2, p.z * p.z); builder.set(i, 3, 2 * p.x * p.y); builder.set(i, 4, 2 * p.x * p.z); builder.set(i, 5, 2 * p.y * p.z); builder.set(i, 6, 2 * p.x); builder.set(i, 7, 2 * p.y); builder.set(i, 8, 2 * p.z); } return builder.build(); }
Example #6
Source File: Matrix4dTest.java From JOML with MIT License | 6 votes |
public static void testOrthoCrop() { Matrix4d lightView = new Matrix4d() .lookAt(0, 5, 0, 0, 0, 0, -1, 0, 0); Matrix4d crop = new Matrix4d(); Matrix4d fin = new Matrix4d(); new Matrix4d().ortho2D(-1, 1, -1, 1).invertAffine().orthoCrop(lightView, crop).mulOrthoAffine(lightView, fin); Vector3d p = new Vector3d(); fin.transformProject(p.set(1, -1, -1)); assertEquals(+1.0f, p.x, 1E-6f); assertEquals(-1.0f, p.y, 1E-6f); assertEquals(+1.0f, p.z, 1E-6f); fin.transformProject(p.set(-1, -1, -1)); assertEquals(+1.0f, p.x, 1E-6f); assertEquals(+1.0f, p.y, 1E-6f); assertEquals(+1.0f, p.z, 1E-6f); }
Example #7
Source File: Matrix4dTest.java From JOML with MIT License | 6 votes |
public static void testOrthoCropWithPerspective() { Matrix4d lightView = new Matrix4d() .lookAt(0, 5, 0, 0, 0, 0, 0, 0, -1); Matrix4d crop = new Matrix4d(); Matrix4d fin = new Matrix4d(); new Matrix4d().perspective((float) Math.toRadians(90), 1.0f, 5, 10).invertPerspective().orthoCrop(lightView, crop).mulOrthoAffine(lightView, fin); Vector3d p = new Vector3d(); fin.transformProject(p.set(0, 0, -5)); assertEquals(+0.0f, p.x, 1E-6f); assertEquals(-1.0f, p.y, 1E-6f); assertEquals(+0.0f, p.z, 1E-6f); fin.transformProject(p.set(0, 0, -10)); assertEquals(+0.0f, p.x, 1E-6f); assertEquals(+1.0f, p.y, 1E-6f); assertEquals(+0.0f, p.z, 1E-6f); fin.transformProject(p.set(-10, 10, -10)); assertEquals(-1.0f, p.x, 1E-6f); assertEquals(+1.0f, p.y, 1E-6f); assertEquals(-1.0f, p.z, 1E-6f); }
Example #8
Source File: Matrix4dTest.java From JOML with MIT License | 6 votes |
public static void testFrustumRay2() { Vector3d dir = new Vector3d(); Matrix4d m = new Matrix4d() .perspective((float) Math.toRadians(90), 1.0f, 0.1f, 100.0f) .rotateZ((float) Math.toRadians(45)); Vector3d expectedDir; m.frustumRayDir(0, 0, dir); expectedDir = new Vector3d(-(float)Math.sqrt(2), 0, -1).normalize(); TestUtil.assertVector3dEquals(expectedDir, dir, 1E-5f); m.frustumRayDir(1, 0, dir); expectedDir = new Vector3d(0, -(float)Math.sqrt(2), -1).normalize(); TestUtil.assertVector3dEquals(expectedDir, dir, 1E-5f); m.frustumRayDir(0, 1, dir); expectedDir = new Vector3d(0, (float)Math.sqrt(2), -1).normalize(); TestUtil.assertVector3dEquals(expectedDir, dir, 1E-5f); m.frustumRayDir(1, 1, dir); expectedDir = new Vector3d((float)Math.sqrt(2), 0, -1).normalize(); TestUtil.assertVector3dEquals(expectedDir, dir, 1E-5f); }
Example #9
Source File: Matrix4dTest.java From JOML with MIT License | 6 votes |
public static void testFrustumRay() { Vector3d dir = new Vector3d(); Matrix4d m = new Matrix4d() .perspective((float) Math.toRadians(90), 1.0f, 0.1f, 100.0f) .rotateY((float) Math.toRadians(90)); Vector3d expectedDir; m.frustumRayDir(0, 0, dir); expectedDir = new Vector3d(1, -1, -1).normalize(); TestUtil.assertVector3dEquals(expectedDir, dir, 1E-5f); m.frustumRayDir(1, 0, dir); expectedDir = new Vector3d(1, -1, 1).normalize(); TestUtil.assertVector3dEquals(expectedDir, dir, 1E-5f); m.frustumRayDir(0, 1, dir); expectedDir = new Vector3d(1, 1, -1).normalize(); TestUtil.assertVector3dEquals(expectedDir, dir, 1E-5f); m.frustumRayDir(1, 1, dir); expectedDir = new Vector3d(1, 1, 1).normalize(); TestUtil.assertVector3dEquals(expectedDir, dir, 1E-5f); }
Example #10
Source File: Matrix4dTest.java From JOML with MIT License | 6 votes |
/** * Test that project and unproject are each other's inverse operations. */ public static void testProjectUnproject() { /* Build some arbitrary viewport. */ int[] viewport = {0, 0, 800, 800}; Vector3d expected = new Vector3d(1.0f, 2.0f, -3.0f); Vector3d actual = new Vector3d(); /* Build a perspective projection and then project and unproject. */ Matrix4d m = new Matrix4d() .perspective((float) Math.toRadians(45.0f), 1.0f, 0.01f, 100.0f); m.project(expected, viewport, actual); m.unproject(actual, viewport, actual); /* Check for equality of the components */ assertEquals(expected.x, actual.x, TestUtil.MANY_OPS_AROUND_ZERO_PRECISION_FLOAT); assertEquals(expected.y, actual.y, TestUtil.MANY_OPS_AROUND_ZERO_PRECISION_FLOAT); assertEquals(expected.z, actual.z, TestUtil.MANY_OPS_AROUND_ZERO_PRECISION_FLOAT); }
Example #11
Source File: QuadricTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testEquation() { final Matrix4dc solution = (Matrix4dc) ops.run(Quadric.class, unitSpherePoints); final double a = solution.m00(); final double b = solution.m11(); final double c = solution.m22(); final double d = solution.m01(); final double e = solution.m02(); final double f = solution.m12(); final double g = solution.m03(); final double h = solution.m13(); final double i = solution.m23(); for (final Vector3d p : unitSpherePoints) { final double polynomial = a * p.x * p.x + b * p.y * p.y + c * p.z * p.z + 2 * d * p.x * p.y + 2 * e * p.x * p.z + 2 * f * p.y * p.z + 2 * g * p.x + 2 * h * p.y + 2 * i * p.z; assertEquals("The matrix does not solve the polynomial equation", 1.0, polynomial, 1e-12); } }
Example #12
Source File: IntersectiondTest.java From JOML with MIT License | 6 votes |
public static void testFindClosestPointOnRectangle() { final double EPSILON = 1E-4d; Vector3d a = new Vector3d(0, 0, 0); Vector3d b = new Vector3d(0, 1d, 0); Vector3d c = new Vector3d(1d, 0, 0); Vector3d p1 = new Vector3d(0.5d, 0.5d, 0); Vector3d v1 = Intersectiond.findClosestPointOnRectangle(a.x, a.y, a.z, b.x, b.y, b.z, c.x, c.y, c.z, p1.x, p1.y, p1.z, new Vector3d()); TestUtil.assertVector3dEquals(new Vector3d(0.5d, 0.5d, 0), v1, EPSILON); Vector3d p2 = new Vector3d(-1d, -0.5d, 0); Vector3d v2 = Intersectiond.findClosestPointOnRectangle(a.x, a.y, a.z, b.x, b.y, b.z, c.x, c.y, c.z, p2.x, p2.y, p2.z, new Vector3d()); TestUtil.assertVector3dEquals(new Vector3d(0, 0, 0), v2, EPSILON); Vector3d p3 = new Vector3d(-0.5d, 2d, 0); Vector3d v3 = Intersectiond.findClosestPointOnRectangle(a.x, a.y, a.z, b.x, b.y, b.z, c.x, c.y, c.z, p3.x, p3.y, p3.z, new Vector3d()); TestUtil.assertVector3dEquals(new Vector3d(0, 1d, 0), v3, EPSILON); Vector3d p4 = new Vector3d(-1d, 0.5d, 0); Vector3d v4 = Intersectiond.findClosestPointOnRectangle(a.x, a.y, a.z, b.x, b.y, b.z, c.x, c.y, c.z, p4.x, p4.y, p4.z, new Vector3d()); TestUtil.assertVector3dEquals(new Vector3d(0, 0.5d, 0), v4, EPSILON); Vector3d p5 = new Vector3d(0.5d, 1d, 0); Vector3d v5 = Intersectiond.findClosestPointOnRectangle(a.x, a.y, a.z, b.x, b.y, b.z, c.x, c.y, c.z, p5.x, p5.y, p5.z, new Vector3d()); TestUtil.assertVector3dEquals(new Vector3d(0.5d, 1d, 0), v5, EPSILON); }
Example #13
Source File: DihedralAngle.java From OSPREY3 with GNU General Public License v2.0 | 6 votes |
/** * Measures the dihedral angle in radians, using the usual a,b,c,d atom position convention. * * WARNING: this implementation overwrites the values of a, c, and d, * but it doesn't do any heap allocations. */ private static double measureAngleRadians(Vector3d a, Vector3d b, Vector3d c, Vector3d d) { // translate so b is at the origin a.sub(b); c.sub(b); d.sub(b); // rotate into a coordinate system where: // b->c is along the -z axis // b->a is in the yz plane Quaterniond q = new Quaterniond() .lookAlong(c, a); d.rotate(q); return Protractor.normalizeMinusPiToPi(Math.PI/2 - Math.atan2(d.y, d.x)); }
Example #14
Source File: TranslationRotation.java From OSPREY3 with GNU General Public License v2.0 | 6 votes |
private void apply() { Vector3d pos = new Vector3d(); Quaterniond qPsi = new Quaterniond().rotationX(dofPsi.value); Quaterniond qTheta = new Quaterniond().rotationY(dofTheta.value); Quaterniond qPhi = new Quaterniond().rotationZ(dofPhi.value); Vector3d t = new Vector3d(dofX.value, dofY.value, dofZ.value); // transform each atom for (int atomi : atomIndices) { originalCoords.get(atomi, pos); pos.sub(desc.centroid); pos.rotate(qPsi); pos.rotate(qTheta); pos.rotate(qPhi); pos.add(desc.centroid); pos.add(t); coords.coords.set(atomi, pos); } }
Example #15
Source File: VertexUtils.java From AnalyzeSkeleton with GNU General Public License v3.0 | 5 votes |
private static Vector3d getOppositeCentroid(final Vertex vertex, final Vector3d centroid, final Edge edge) { final List<Point> points = edge.getOppositeVertex(vertex).getPoints(); final Vector3d endPoint = PointUtils.centroid(points); return endPoint.sub(centroid); }
Example #16
Source File: PointUtilsTest.java From AnalyzeSkeleton with GNU General Public License v3.0 | 5 votes |
@Test public void testCentroidEmptyList() { final Vector3d expected = new Vector3d(Double.NaN, Double.NaN, Double.NaN); final List<Point> empty = new ArrayList<>(); final Vector3d result = PointUtils.centroid(empty); assertEquals(expected, result); }
Example #17
Source File: Rotate3d.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void compute(final Vector3d v, final Quaterniondc q, final Vector3d vDot) { vDot.set(v); vDot.rotate(q); }
Example #18
Source File: TranslationRotation.java From OSPREY3 with GNU General Public License v2.0 | 5 votes |
public Description( double maxDistance, double maxRotationRadians, Vector3d centroid ) { this.maxDistance = maxDistance; this.maxRotationRadians = maxRotationRadians; this.centroid = centroid; }
Example #19
Source File: QuadricTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Test(expected = IllegalArgumentException.class) public void testMatchingFailsIfTooFewPoints() { final int nPoints = Math.max(0, Quadric.MIN_DATA - 1); final List<Vector3d> points = Stream.generate(Vector3d::new).limit(nPoints) .collect(toList()); ops.run(Quadric.class, points); }
Example #20
Source File: PointUtilsTest.java From AnalyzeSkeleton with GNU General Public License v3.0 | 5 votes |
@Test public void testCentroid() { final Vector3d expected = new Vector3d(0.5, 0.5, 0.5); final List<Point> unitCube = asList(new Point(0, 0, 0), new Point(1, 0, 0), new Point(1, 1, 0), new Point(0, 1, 0), new Point(0, 0, 1), new Point(1, 0, 1), new Point(1, 1, 1), new Point(0, 1, 1)); final Vector3d result = PointUtils.centroid(unitCube); assertEquals(expected, result); }
Example #21
Source File: Rotate3dTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void testAxisAngle() { final Vector3d xAxis = new Vector3d(1, 0, 0); final Vector3d in = new Vector3d(xAxis); final AxisAngle4d axisAngle = new AxisAngle4d(Math.PI / 2.0, 0, 0, 1); final Vector3d expected = xAxis.rotate(new Quaterniond(axisAngle)); final Vector3d result = ops.linalg().rotate(in, axisAngle); assertEquals("Rotation is incorrect", expected, result); }
Example #22
Source File: Rotate3dTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void testCalculate() { final Vector3d xAxis = new Vector3d(1, 0, 0); final Vector3d in = new Vector3d(xAxis); final Vector3d result = ops.linalg().rotate(in, IDENTITY); assertNotSame("Op should create a new object for output", in, result); assertEquals("Rotation is incorrect", xAxis, result); }
Example #23
Source File: Rotate3dTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void testCompute() { final Vector3d origin = new Vector3d(); final Vector3d xAxis = new Vector3d(1, 0, 0); final Vector3d in = new Vector3d(xAxis); final Vector3d out = new Vector3d(origin); final Vector3d result = ops.linalg().rotate(out, in, IDENTITY); assertSame("Op should not create a new object for output", out, result); assertEquals("Rotation is incorrect", xAxis, out); }
Example #24
Source File: Rotate3dTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void testMutate() { final Vector3d xAxis = new Vector3d(1, 0, 0); final Vector3d in = new Vector3d(xAxis); final Quaterniond q = new Quaterniond(new AxisAngle4d(Math.PI / 2.0, 0, 0, 1)); final Vector3d expected = xAxis.rotate(q); final Vector3d result = ops.linalg().rotate1(in, q); assertSame("Mutate should operate on the input object", in, result); assertEquals("Rotation is incorrect", expected, result); }
Example #25
Source File: LinAlgNamespace.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@OpMethod(op = net.imagej.ops.linalg.rotate.Rotate3d.class) public Vector3d rotate(final Vector3d out, final Vector3d v, final AxisAngle4d axisAngle) { final Quaterniondc q = new Quaterniond(axisAngle); return (Vector3d) ops().run(Rotate3d.class, out, v, q); }
Example #26
Source File: GraphPruning.java From AnalyzeSkeleton with GNU General Public License v3.0 | 5 votes |
/** * Sets the length of the {@link Edge} to the calibrated euclidean distance * between its endpoints. * * @param e an edge of a graph. * @param voxelSize [x, y, z] voxel size in the skeleton image from which the * graph was created. */ private static void euclideanDistance(final Edge e, final double[] voxelSize) { final Vector3d centre = PointUtils.centroid(e.getV1().getPoints()); final Vector3d centre2 = PointUtils.centroid(e.getV2().getPoints()); centre.sub(centre2); final double l = length(centre, voxelSize); e.setLength(l); }
Example #27
Source File: EnergyCalculator.java From OSPREY3 with GNU General Public License v2.0 | 5 votes |
/** calculate the single energy of position i */ default double calcEnergySingle(AssignedCoords coords, int posi) { int ffi = ffi(); // start with the internal energy double energy = coords.getInternalEnergy(ffi, posi); // TODO: hopefully escape analysis will allocate this on the stack? Vector3d pos1 = new Vector3d(); Vector3d pos2 = new Vector3d(); // add the internal interactions ConfSpace.IndicesSingle indices = coords.getIndices(ffi, posi); for (int i=0; i<indices.sizeInternals(); i++) { int confAtom1i = indices.getInternalConfAtom1Index(i); int confAtom2i = indices.getInternalConfAtom2Index(i); int paramsi = indices.getInternalParamsIndex(i); coords.coords.get(coords.getConfIndex(posi, confAtom1i), pos1); coords.coords.get(coords.getConfIndex(posi, confAtom2i), pos2); double r2 = pos1.distanceSquared(pos2); double r = Math.sqrt(r2); energy += calcEnergy(r, r2, coords.getParams(ffi, paramsi)); } return energy; }
Example #28
Source File: EnergyCalculator.java From OSPREY3 with GNU General Public License v2.0 | 5 votes |
/** get the internal energy of the static atoms */ default double calcEnergyStatic(AssignedCoords coords) { int ffi = ffi(); // start with the static energy double energy = coords.getStaticEnergy(ffi); // TODO: hopefully escape analysis will allocate this on the stack? Vector3d pos1 = new Vector3d(); Vector3d pos2 = new Vector3d(); // add the internal interactions ConfSpace.IndicesStatic indices = coords.getIndices(ffi); for (int i=0; i<indices.size(); i++) { int atomi1 = indices.getStaticAtom1Index(i); int atomi2 = indices.getStaticAtom2Index(i); int paramsi = indices.getParamsIndex(i); coords.coords.get(coords.getStaticIndex(atomi1), pos1); coords.coords.get(coords.getStaticIndex(atomi2), pos2); double r2 = pos1.distanceSquared(pos2); double r = Math.sqrt(r2); energy += calcEnergy(r, r2, coords.getParams(ffi, paramsi)); } return energy; }
Example #29
Source File: ForcefieldDebugger.java From OSPREY3 with GNU General Public License v2.0 | 5 votes |
public AtomPair( String idA, String idB, double x1, double y1, double z1, double x2, double y2, double z2, double r ) { this(idA, idB, new Vector3d(x1, y1, z1), new Vector3d(x2, y2, z2), r); }
Example #30
Source File: Matrix4x3dTest.java From JOML with MIT License | 5 votes |
public static void testPositiveXRotateY() { Vector3d dir = new Vector3d(); Matrix4x3dc m = new Matrix4x3d() .rotateY((float) Math.toRadians(90)); m.positiveX(dir); TestUtil.assertVector3dEquals(new Vector3d(0, 0, 1), dir, 1E-7f); }