Java Code Examples for org.apache.commons.math3.geometry.euclidean.threed.Vector3D#getZ()

The following examples show how to use org.apache.commons.math3.geometry.euclidean.threed.Vector3D#getZ() . 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: SphericalPolygonsSetTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testPositiveOctantByVertices() {
    double tol = 0.01;
    double sinTol = FastMath.sin(tol);
    SphericalPolygonsSet octant = new SphericalPolygonsSet(tol, S2Point.PLUS_I, S2Point.PLUS_J, S2Point.PLUS_K);
    UnitSphereRandomVectorGenerator random =
            new UnitSphereRandomVectorGenerator(3, new Well1024a(0xb8fc5acc91044308l));
    for (int i = 0; i < 1000; ++i) {
        Vector3D v = new Vector3D(random.nextVector());
        if ((v.getX() > sinTol) && (v.getY() > sinTol) && (v.getZ() > sinTol)) {
            Assert.assertEquals(Location.INSIDE, octant.checkPoint(new S2Point(v)));
        } else if ((v.getX() < -sinTol) || (v.getY() < -sinTol) || (v.getZ() < -sinTol)) {
            Assert.assertEquals(Location.OUTSIDE, octant.checkPoint(new S2Point(v)));
        } else {
            Assert.assertEquals(Location.BOUNDARY, octant.checkPoint(new S2Point(v)));
        }
    }
}
 
Example 2
Source File: ClientProxy.java    From NOVA-Core with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public Entity spawnParticle(net.minecraft.world.World world, Entity entity) {
	//Backward entity particle unwrapper
	if (entity instanceof BWEntityFX) {
		EntityFX entityFX = ((BWEntityFX) entity).createEntityFX(world);
		Vector3D position = entity.position();
		entityFX.posX = position.getX();
		entityFX.posY = position.getY();
		entityFX.posZ = position.getZ();
		FMLClientHandler.instance().getClient().effectRenderer.addEffect(entityFX);
		return EntityConverter.instance().toNova(entityFX);
	} else {
		FWEntityFX bwEntityFX = new FWEntityFX(world, entity);
		FMLClientHandler.instance().getClient().effectRenderer.addEffect(bwEntityFX);
		return bwEntityFX.wrapped;
	}
}
 
Example 3
Source File: SphericalPolygonsSetTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testPositiveOctantByVertices() {
    double tol = 0.01;
    double sinTol = FastMath.sin(tol);
    SphericalPolygonsSet octant = new SphericalPolygonsSet(tol, S2Point.PLUS_I, S2Point.PLUS_J, S2Point.PLUS_K);
    UnitSphereRandomVectorGenerator random =
            new UnitSphereRandomVectorGenerator(3, new Well1024a(0xb8fc5acc91044308l));
    for (int i = 0; i < 1000; ++i) {
        Vector3D v = new Vector3D(random.nextVector());
        if ((v.getX() > sinTol) && (v.getY() > sinTol) && (v.getZ() > sinTol)) {
            Assert.assertEquals(Location.INSIDE, octant.checkPoint(new S2Point(v)));
        } else if ((v.getX() < -sinTol) || (v.getY() < -sinTol) || (v.getZ() < -sinTol)) {
            Assert.assertEquals(Location.OUTSIDE, octant.checkPoint(new S2Point(v)));
        } else {
            Assert.assertEquals(Location.BOUNDARY, octant.checkPoint(new S2Point(v)));
        }
    }
}
 
Example 4
Source File: FWSmartModel.java    From NOVA-Core with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static int[] vertexToInts(Vertex vertex, TextureAtlasSprite texture, Vector3D normal) {
		// TODO: Possibly support arbitrary `VertexFormat`
//		if (vertex.normal.isPresent())
//			normal = vertex.normal.get();
		return new int[] {
			Float.floatToRawIntBits((float) vertex.vec.getX()),
			Float.floatToRawIntBits((float) vertex.vec.getY()),
			Float.floatToRawIntBits((float) vertex.vec.getZ()),
			vertex.color.rgba(),
			Float.floatToRawIntBits(texture.getInterpolatedU(16 * vertex.uv.getX())),
			Float.floatToRawIntBits(texture.getInterpolatedV(16 * vertex.uv.getY())),
			((((byte)(normal.getX() * 127)) & 0xFF) |
			((((byte)(normal.getY() * 127)) & 0xFF) << 8) |
			((((byte)(normal.getZ() * 127)) & 0xFF) << 16))
		};
	}
 
Example 5
Source File: TransformUtil.java    From NOVA-Core with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Transform vector by this matrix.
 *
 * @param vector to be transformed.
 * @param m The 4x4 matrix to transform the vector by
 * @return transformed vector.
 */
public static Vector3D transformDirectionless(Vector3D vector, RealMatrix m) {
	double x, y, z;
	x = m.getEntry(0, 0) * vector.getX() + m.getEntry(1, 0) * vector.getY() + m.getEntry(2, 0) * vector.getZ();
	y = m.getEntry(0, 1) * vector.getX() + m.getEntry(1, 1) * vector.getY() + m.getEntry(2, 1) * vector.getZ();
	z = m.getEntry(0, 2) * vector.getX() + m.getEntry(1, 2) * vector.getY() + m.getEntry(2, 2) * vector.getZ();
	return new Vector3D(x, y, z);
}
 
Example 6
Source File: TransformUtil.java    From NOVA-Core with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Transform vector by this matrix.
 *
 * @param vector to be transformed.
 * @param m The 4x4 matrix to transform the vector by
 * @return transformed vector.
 */
public static Vector3D transform(Vector3D vector, RealMatrix m) {
	double x, y, z, w;
	x = m.getEntry(0, 0) * vector.getX() + m.getEntry(1, 0) * vector.getY() + m.getEntry(2, 0) * vector.getZ() + m.getEntry(3, 0);
	y = m.getEntry(0, 1) * vector.getX() + m.getEntry(1, 1) * vector.getY() + m.getEntry(2, 1) * vector.getZ() + m.getEntry(3, 1);
	z = m.getEntry(0, 2) * vector.getX() + m.getEntry(1, 2) * vector.getY() + m.getEntry(2, 2) * vector.getZ() + m.getEntry(3, 2);
	w = m.getEntry(0, 3) * vector.getX() + m.getEntry(1, 3) * vector.getY() + m.getEntry(2, 3) * vector.getZ() + m.getEntry(3, 3);
	return new Vector3D(x / w, y / w, z / w);
}
 
Example 7
Source File: Vector3DUtil.java    From NOVA-Core with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static Vector3D perpendicular(Vector3D vec) {
	// Special case. Z == 0 would cause a error.
	//noinspection FloatingPointEquality
	if (vec.getZ() == 0) {
		return zCross(vec);
	}

	return xCross(vec);
}
 
Example 8
Source File: DefaultConvexHull3D.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public Mesh calculate(final Mesh input) {
	Mesh output = new NaiveDoubleMesh();
	Set<Vertex> vertices = new LinkedHashSet<>();
	for (final net.imagej.mesh.Vertex v : input.vertices()) {
		final Vertex vertex = new Vertex(v.x(), v.y(), v.z());
		vertices.add(vertex);
	}
	List<TriangularFacet> facets = new ArrayList<>();
	List<TriangularFacet> facetsWithPointInFront = new ArrayList<>();
	epsilon = computeHull(vertices, facets, facetsWithPointInFront);

	final Map<Vertex, Long> vertexIndices = new HashMap<>();
	for (final TriangularFacet f : facets) {
		final Vertex v0 = f.getP0();
		final Vertex v1 = f.getP1();
		final Vertex v2 = f.getP2();
		final long vIndex0 = vertexIndices.computeIfAbsent(v0, //
			v -> output.vertices().add(v0.getX(), v0.getY(), v0.getZ()));
		final long vIndex1 = vertexIndices.computeIfAbsent(v1, //
			v -> output.vertices().add(v1.getX(), v1.getY(), v1.getZ()));
		final long vIndex2 = vertexIndices.computeIfAbsent(v2, //
			v -> output.vertices().add(v2.getX(), v2.getY(), v2.getZ()));
		final Vector3D normal = f.getNormal();
		final double nx = normal.getX();
		final double ny = normal.getY();
		final double nz = normal.getZ();
		output.triangles().add(vIndex0, vIndex1, vIndex2, nx, ny, nz);
	}
	return output;
}
 
Example 9
Source File: VectorConverter.java    From NOVA-Core with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public BlockPos toNative(Vector3D vec) {
	return new BlockPos(vec.getX(), vec.getY(), vec.getZ());
}
 
Example 10
Source File: SphericalPolygonsSetTest.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void testNonConvex() {
    double tol = 0.01;
    double sinTol = FastMath.sin(tol);
    RegionFactory<Sphere2D> factory = new RegionFactory<Sphere2D>();
    SphericalPolygonsSet plusX = new SphericalPolygonsSet(Vector3D.PLUS_I, tol);
    SphericalPolygonsSet plusY = new SphericalPolygonsSet(Vector3D.PLUS_J, tol);
    SphericalPolygonsSet plusZ = new SphericalPolygonsSet(Vector3D.PLUS_K, tol);
    SphericalPolygonsSet threeOctants =
            (SphericalPolygonsSet) factory.difference(plusZ, factory.intersection(plusX, plusY));

    UnitSphereRandomVectorGenerator random =
            new UnitSphereRandomVectorGenerator(3, new Well1024a(0x9c9802fde3cbcf25l));
    for (int i = 0; i < 1000; ++i) {
        Vector3D v = new Vector3D(random.nextVector());
        if (((v.getX() < -sinTol) || (v.getY() < -sinTol)) && (v.getZ() > sinTol)) {
            Assert.assertEquals(Location.INSIDE, threeOctants.checkPoint(new S2Point(v)));
        } else if (((v.getX() > sinTol) && (v.getY() > sinTol)) || (v.getZ() < -sinTol)) {
            Assert.assertEquals(Location.OUTSIDE, threeOctants.checkPoint(new S2Point(v)));
        } else {
            Assert.assertEquals(Location.BOUNDARY, threeOctants.checkPoint(new S2Point(v)));
        }
    }

    List<Vertex> loops = threeOctants.getBoundaryLoops();
    Assert.assertEquals(1, loops.size());
    boolean xPFound = false;
    boolean yPFound = false;
    boolean zPFound = false;
    boolean xVFound = false;
    boolean yVFound = false;
    boolean zVFound = false;
    Vertex first = loops.get(0);
    int count = 0;
    for (Vertex v = first; count == 0 || v != first; v = v.getOutgoing().getEnd()) {
        ++count;
        Edge e = v.getIncoming();
        Assert.assertTrue(v == e.getStart().getOutgoing().getEnd());
        xPFound = xPFound || e.getCircle().getPole().distance(Vector3D.MINUS_I) < 1.0e-10;
        yPFound = yPFound || e.getCircle().getPole().distance(Vector3D.MINUS_J) < 1.0e-10;
        zPFound = zPFound || e.getCircle().getPole().distance(Vector3D.PLUS_K)  < 1.0e-10;
        if (Vector3D.PLUS_K.distance(e.getCircle().getPole()) < 1.0e-10) {
            Assert.assertEquals(1.5 * FastMath.PI, e.getLength(), 1.0e-10);
        } else {
            Assert.assertEquals(0.5 * FastMath.PI, e.getLength(), 1.0e-10);
        }
        xVFound = xVFound || v.getLocation().getVector().distance(Vector3D.PLUS_I) < 1.0e-10;
        yVFound = yVFound || v.getLocation().getVector().distance(Vector3D.PLUS_J) < 1.0e-10;
        zVFound = zVFound || v.getLocation().getVector().distance(Vector3D.PLUS_K) < 1.0e-10;
    }
    Assert.assertTrue(xPFound);
    Assert.assertTrue(yPFound);
    Assert.assertTrue(zPFound);
    Assert.assertTrue(xVFound);
    Assert.assertTrue(yVFound);
    Assert.assertTrue(zVFound);
    Assert.assertEquals(3, count);

    Assert.assertEquals(1.5 * FastMath.PI, threeOctants.getSize(), 1.0e-10);

}
 
Example 11
Source File: SphericalPolygonsSetTest.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void testSeveralParts() {
    double tol = 0.01;
    double sinTol = FastMath.sin(tol);
    List<SubHyperplane<Sphere2D>> boundary = new ArrayList<SubHyperplane<Sphere2D>>();

    // first part: +X, +Y, +Z octant
    boundary.add(create(Vector3D.PLUS_J,  Vector3D.PLUS_K,  Vector3D.PLUS_I,  tol, 0.0, 0.5 * FastMath.PI));
    boundary.add(create(Vector3D.PLUS_K,  Vector3D.PLUS_I,  Vector3D.PLUS_J,  tol, 0.0, 0.5 * FastMath.PI));
    boundary.add(create(Vector3D.PLUS_I,  Vector3D.PLUS_J,  Vector3D.PLUS_K,  tol, 0.0, 0.5 * FastMath.PI));

    // first part: -X, -Y, -Z octant
    boundary.add(create(Vector3D.MINUS_J, Vector3D.MINUS_I, Vector3D.MINUS_K, tol, 0.0, 0.5 * FastMath.PI));
    boundary.add(create(Vector3D.MINUS_I, Vector3D.MINUS_K, Vector3D.MINUS_J, tol, 0.0, 0.5 * FastMath.PI));
    boundary.add(create(Vector3D.MINUS_K, Vector3D.MINUS_J, Vector3D.MINUS_I,  tol, 0.0, 0.5 * FastMath.PI));

    SphericalPolygonsSet polygon = new SphericalPolygonsSet(boundary, tol);

    UnitSphereRandomVectorGenerator random =
            new UnitSphereRandomVectorGenerator(3, new Well1024a(0xcc5ce49949e0d3ecl));
    for (int i = 0; i < 1000; ++i) {
        Vector3D v = new Vector3D(random.nextVector());
        if ((v.getX() < -sinTol) && (v.getY() < -sinTol) && (v.getZ() < -sinTol)) {
            Assert.assertEquals(Location.INSIDE, polygon.checkPoint(new S2Point(v)));
        } else if ((v.getX() < sinTol) && (v.getY() < sinTol) && (v.getZ() < sinTol)) {
            Assert.assertEquals(Location.BOUNDARY, polygon.checkPoint(new S2Point(v)));
        } else if ((v.getX() > sinTol) && (v.getY() > sinTol) && (v.getZ() > sinTol)) {
            Assert.assertEquals(Location.INSIDE, polygon.checkPoint(new S2Point(v)));
        } else if ((v.getX() > -sinTol) && (v.getY() > -sinTol) && (v.getZ() > -sinTol)) {
            Assert.assertEquals(Location.BOUNDARY, polygon.checkPoint(new S2Point(v)));
        } else {
            Assert.assertEquals(Location.OUTSIDE, polygon.checkPoint(new S2Point(v)));
        }
    }

    Assert.assertEquals(FastMath.PI, polygon.getSize(), 1.0e-10);
    Assert.assertEquals(3 * FastMath.PI, polygon.getBoundarySize(), 1.0e-10);

    // there should be two separate boundary loops
    Assert.assertEquals(2, polygon.getBoundaryLoops().size());

}
 
Example 12
Source File: VectorConverter.java    From NOVA-Core with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public BlockPos toNative(Vector3D vec) {
	return new BlockPos(vec.getX(), vec.getY(), vec.getZ());
}
 
Example 13
Source File: BWWorld.java    From NOVA-Core with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void markStaticRender(Vector3D position) {
	BlockPos pos = new BlockPos((int) position.getX(), (int) position.getY(), (int) position.getZ());
	world().markBlockRangeForRenderUpdate(pos, pos);
}
 
Example 14
Source File: MCParticleTransform.java    From NOVA-Core with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void setScale(Vector3D scale) {
	// MC Particles only have one scale.
	wrapper.particleScale = (float) ((scale.getX() + scale.getY() + scale.getZ()) / 3);
}
 
Example 15
Source File: BWWorld.java    From NOVA-Core with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public Entity addEntity(Vector3D position, Item item) {
	EntityItem entityItem = new EntityItem(world(), position.getX(), position.getY(), position.getZ(), ItemConverter.instance().toNative(item));
	world().spawnEntityInWorld(entityItem);
	return new BWEntity(entityItem);
}
 
Example 16
Source File: SphericalPolygonsSetTest.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void testPositiveOctantByIntersection() {
    double tol = 0.01;
    double sinTol = FastMath.sin(tol);
    RegionFactory<Sphere2D> factory = new RegionFactory<Sphere2D>();
    SphericalPolygonsSet plusX = new SphericalPolygonsSet(Vector3D.PLUS_I, tol);
    SphericalPolygonsSet plusY = new SphericalPolygonsSet(Vector3D.PLUS_J, tol);
    SphericalPolygonsSet plusZ = new SphericalPolygonsSet(Vector3D.PLUS_K, tol);
    SphericalPolygonsSet octant =
            (SphericalPolygonsSet) factory.intersection(factory.intersection(plusX, plusY), plusZ);
    UnitSphereRandomVectorGenerator random =
            new UnitSphereRandomVectorGenerator(3, new Well1024a(0x9c9802fde3cbcf25l));
    for (int i = 0; i < 1000; ++i) {
        Vector3D v = new Vector3D(random.nextVector());
        if ((v.getX() > sinTol) && (v.getY() > sinTol) && (v.getZ() > sinTol)) {
            Assert.assertEquals(Location.INSIDE, octant.checkPoint(new S2Point(v)));
        } else if ((v.getX() < -sinTol) || (v.getY() < -sinTol) || (v.getZ() < -sinTol)) {
            Assert.assertEquals(Location.OUTSIDE, octant.checkPoint(new S2Point(v)));
        } else {
            Assert.assertEquals(Location.BOUNDARY, octant.checkPoint(new S2Point(v)));
        }
    }

    List<Vertex> loops = octant.getBoundaryLoops();
    Assert.assertEquals(1, loops.size());
    boolean xPFound = false;
    boolean yPFound = false;
    boolean zPFound = false;
    boolean xVFound = false;
    boolean yVFound = false;
    boolean zVFound = false;
    Vertex first = loops.get(0);
    int count = 0;
    for (Vertex v = first; count == 0 || v != first; v = v.getOutgoing().getEnd()) {
        ++count;
        Edge e = v.getIncoming();
        Assert.assertTrue(v == e.getStart().getOutgoing().getEnd());
        xPFound = xPFound || e.getCircle().getPole().distance(Vector3D.PLUS_I) < 1.0e-10;
        yPFound = yPFound || e.getCircle().getPole().distance(Vector3D.PLUS_J) < 1.0e-10;
        zPFound = zPFound || e.getCircle().getPole().distance(Vector3D.PLUS_K) < 1.0e-10;
        Assert.assertEquals(0.5 * FastMath.PI, e.getLength(), 1.0e-10);
        xVFound = xVFound || v.getLocation().getVector().distance(Vector3D.PLUS_I) < 1.0e-10;
        yVFound = yVFound || v.getLocation().getVector().distance(Vector3D.PLUS_J) < 1.0e-10;
        zVFound = zVFound || v.getLocation().getVector().distance(Vector3D.PLUS_K) < 1.0e-10;
    }
    Assert.assertTrue(xPFound);
    Assert.assertTrue(yPFound);
    Assert.assertTrue(zPFound);
    Assert.assertTrue(xVFound);
    Assert.assertTrue(yVFound);
    Assert.assertTrue(zVFound);
    Assert.assertEquals(3, count);

    Assert.assertEquals(0.0,
                        ((S2Point) octant.getBarycenter()).distance(new S2Point(new Vector3D(1, 1, 1))),
                        1.0e-10);
    Assert.assertEquals(0.5 * FastMath.PI, octant.getSize(), 1.0e-10);

    EnclosingBall<Sphere2D, S2Point> cap = octant.getEnclosingCap();
    Assert.assertEquals(0.0, octant.getBarycenter().distance(cap.getCenter()), 1.0e-10);
    Assert.assertEquals(FastMath.acos(1.0 / FastMath.sqrt(3)), cap.getRadius(), 1.0e-10);

    EnclosingBall<Sphere2D, S2Point> reversedCap =
            ((SphericalPolygonsSet) factory.getComplement(octant)).getEnclosingCap();
    Assert.assertEquals(0, reversedCap.getCenter().distance(new S2Point(new Vector3D(-1, -1, -1))), 1.0e-10);
    Assert.assertEquals(FastMath.PI - FastMath.asin(1.0 / FastMath.sqrt(3)), reversedCap.getRadius(), 1.0e-10);

}
 
Example 17
Source File: SphericalPolygonsSetTest.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void testSeveralParts() {
    double tol = 0.01;
    double sinTol = FastMath.sin(tol);
    List<SubHyperplane<Sphere2D>> boundary = new ArrayList<SubHyperplane<Sphere2D>>();

    // first part: +X, +Y, +Z octant
    boundary.add(create(Vector3D.PLUS_J,  Vector3D.PLUS_K,  Vector3D.PLUS_I,  tol, 0.0, 0.5 * FastMath.PI));
    boundary.add(create(Vector3D.PLUS_K,  Vector3D.PLUS_I,  Vector3D.PLUS_J,  tol, 0.0, 0.5 * FastMath.PI));
    boundary.add(create(Vector3D.PLUS_I,  Vector3D.PLUS_J,  Vector3D.PLUS_K,  tol, 0.0, 0.5 * FastMath.PI));

    // first part: -X, -Y, -Z octant
    boundary.add(create(Vector3D.MINUS_J, Vector3D.MINUS_I, Vector3D.MINUS_K, tol, 0.0, 0.5 * FastMath.PI));
    boundary.add(create(Vector3D.MINUS_I, Vector3D.MINUS_K, Vector3D.MINUS_J, tol, 0.0, 0.5 * FastMath.PI));
    boundary.add(create(Vector3D.MINUS_K, Vector3D.MINUS_J, Vector3D.MINUS_I,  tol, 0.0, 0.5 * FastMath.PI));

    SphericalPolygonsSet polygon = new SphericalPolygonsSet(boundary, tol);

    UnitSphereRandomVectorGenerator random =
            new UnitSphereRandomVectorGenerator(3, new Well1024a(0xcc5ce49949e0d3ecl));
    for (int i = 0; i < 1000; ++i) {
        Vector3D v = new Vector3D(random.nextVector());
        if ((v.getX() < -sinTol) && (v.getY() < -sinTol) && (v.getZ() < -sinTol)) {
            Assert.assertEquals(Location.INSIDE, polygon.checkPoint(new S2Point(v)));
        } else if ((v.getX() < sinTol) && (v.getY() < sinTol) && (v.getZ() < sinTol)) {
            Assert.assertEquals(Location.BOUNDARY, polygon.checkPoint(new S2Point(v)));
        } else if ((v.getX() > sinTol) && (v.getY() > sinTol) && (v.getZ() > sinTol)) {
            Assert.assertEquals(Location.INSIDE, polygon.checkPoint(new S2Point(v)));
        } else if ((v.getX() > -sinTol) && (v.getY() > -sinTol) && (v.getZ() > -sinTol)) {
            Assert.assertEquals(Location.BOUNDARY, polygon.checkPoint(new S2Point(v)));
        } else {
            Assert.assertEquals(Location.OUTSIDE, polygon.checkPoint(new S2Point(v)));
        }
    }

    Assert.assertEquals(FastMath.PI, polygon.getSize(), 1.0e-10);
    Assert.assertEquals(3 * FastMath.PI, polygon.getBoundarySize(), 1.0e-10);

    // there should be two separate boundary loops
    Assert.assertEquals(2, polygon.getBoundaryLoops().size());

}
 
Example 18
Source File: SphericalPolygonsSetTest.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void testPositiveOctantByIntersection() {
    double tol = 0.01;
    double sinTol = FastMath.sin(tol);
    RegionFactory<Sphere2D> factory = new RegionFactory<Sphere2D>();
    SphericalPolygonsSet plusX = new SphericalPolygonsSet(Vector3D.PLUS_I, tol);
    SphericalPolygonsSet plusY = new SphericalPolygonsSet(Vector3D.PLUS_J, tol);
    SphericalPolygonsSet plusZ = new SphericalPolygonsSet(Vector3D.PLUS_K, tol);
    SphericalPolygonsSet octant =
            (SphericalPolygonsSet) factory.intersection(factory.intersection(plusX, plusY), plusZ);
    UnitSphereRandomVectorGenerator random =
            new UnitSphereRandomVectorGenerator(3, new Well1024a(0x9c9802fde3cbcf25l));
    for (int i = 0; i < 1000; ++i) {
        Vector3D v = new Vector3D(random.nextVector());
        if ((v.getX() > sinTol) && (v.getY() > sinTol) && (v.getZ() > sinTol)) {
            Assert.assertEquals(Location.INSIDE, octant.checkPoint(new S2Point(v)));
        } else if ((v.getX() < -sinTol) || (v.getY() < -sinTol) || (v.getZ() < -sinTol)) {
            Assert.assertEquals(Location.OUTSIDE, octant.checkPoint(new S2Point(v)));
        } else {
            Assert.assertEquals(Location.BOUNDARY, octant.checkPoint(new S2Point(v)));
        }
    }

    List<Vertex> loops = octant.getBoundaryLoops();
    Assert.assertEquals(1, loops.size());
    boolean xPFound = false;
    boolean yPFound = false;
    boolean zPFound = false;
    boolean xVFound = false;
    boolean yVFound = false;
    boolean zVFound = false;
    Vertex first = loops.get(0);
    int count = 0;
    for (Vertex v = first; count == 0 || v != first; v = v.getOutgoing().getEnd()) {
        ++count;
        Edge e = v.getIncoming();
        Assert.assertTrue(v == e.getStart().getOutgoing().getEnd());
        xPFound = xPFound || e.getCircle().getPole().distance(Vector3D.PLUS_I) < 1.0e-10;
        yPFound = yPFound || e.getCircle().getPole().distance(Vector3D.PLUS_J) < 1.0e-10;
        zPFound = zPFound || e.getCircle().getPole().distance(Vector3D.PLUS_K) < 1.0e-10;
        Assert.assertEquals(0.5 * FastMath.PI, e.getLength(), 1.0e-10);
        xVFound = xVFound || v.getLocation().getVector().distance(Vector3D.PLUS_I) < 1.0e-10;
        yVFound = yVFound || v.getLocation().getVector().distance(Vector3D.PLUS_J) < 1.0e-10;
        zVFound = zVFound || v.getLocation().getVector().distance(Vector3D.PLUS_K) < 1.0e-10;
    }
    Assert.assertTrue(xPFound);
    Assert.assertTrue(yPFound);
    Assert.assertTrue(zPFound);
    Assert.assertTrue(xVFound);
    Assert.assertTrue(yVFound);
    Assert.assertTrue(zVFound);
    Assert.assertEquals(3, count);

    Assert.assertEquals(0.0,
                        ((S2Point) octant.getBarycenter()).distance(new S2Point(new Vector3D(1, 1, 1))),
                        1.0e-10);
    Assert.assertEquals(0.5 * FastMath.PI, octant.getSize(), 1.0e-10);

    EnclosingBall<Sphere2D, S2Point> cap = octant.getEnclosingCap();
    Assert.assertEquals(0.0, octant.getBarycenter().distance(cap.getCenter()), 1.0e-10);
    Assert.assertEquals(FastMath.acos(1.0 / FastMath.sqrt(3)), cap.getRadius(), 1.0e-10);

    EnclosingBall<Sphere2D, S2Point> reversedCap =
            ((SphericalPolygonsSet) factory.getComplement(octant)).getEnclosingCap();
    Assert.assertEquals(0, reversedCap.getCenter().distance(new S2Point(new Vector3D(-1, -1, -1))), 1.0e-10);
    Assert.assertEquals(FastMath.PI - FastMath.asin(1.0 / FastMath.sqrt(3)), reversedCap.getRadius(), 1.0e-10);

}
 
Example 19
Source File: Vector3DUtil.java    From NOVA-Core with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static Vector3D cartesianProduct(Vector3D a, Vector3D b) {
	return new Vector3D(a.getX() * b.getX(), a.getY() * b.getY(), a.getZ() * b.getZ());
}
 
Example 20
Source File: Cuboid.java    From NOVA-Core with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Checks if a vector is within this cuboid.
 *
 * @param other Vector to check
 * @return Result of the check
 */
public boolean intersects(Vector3D other) {
	return other.getX() >= this.min.getX() && other.getX() < this.max.getX() ?
		(other.getY() >= this.min.getY() && other.getY() < this.max.getY() ? other.getZ() >= this.min.getZ() && other.getZ() < this.max.getZ() : false) : false;
}