org.apache.commons.math3.geometry.euclidean.threed.Vector3D Java Examples

The following examples show how to use org.apache.commons.math3.geometry.euclidean.threed.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: CircleTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testReverse() {
    Circle circle = new Circle(new S2Point(1.2, 2.5), new S2Point(-4.3, 0), 1.0e-10);
    Circle reversed = circle.getReverse();
    Assert.assertEquals(0.0, reversed.getPointAt(0).distance(reversed.getXAxis()), 1.0e-10);
    Assert.assertEquals(0.0, reversed.getPointAt(0.5 * FastMath.PI).distance(reversed.getYAxis()), 1.0e-10);
    Assert.assertEquals(0.5 * FastMath.PI, Vector3D.angle(reversed.getXAxis(), reversed.getYAxis()), 1.0e-10);
    Assert.assertEquals(0.5 * FastMath.PI, Vector3D.angle(reversed.getXAxis(), reversed.getPole()), 1.0e-10);
    Assert.assertEquals(0.5 * FastMath.PI, Vector3D.angle(reversed.getPole(), reversed.getYAxis()), 1.0e-10);
    Assert.assertEquals(0.0,
                        reversed.getPole().distance(Vector3D.crossProduct(reversed.getXAxis(), reversed.getYAxis())),
                        1.0e-10);

    Assert.assertEquals(0, Vector3D.angle(circle.getXAxis(), reversed.getXAxis()), 1.0e-10);
    Assert.assertEquals(FastMath.PI, Vector3D.angle(circle.getYAxis(), reversed.getYAxis()), 1.0e-10);
    Assert.assertEquals(FastMath.PI, Vector3D.angle(circle.getPole(), reversed.getPole()), 1.0e-10);

    Assert.assertTrue(circle.sameOrientationAs(circle));
    Assert.assertFalse(circle.sameOrientationAs(reversed));

}
 
Example #2
Source File: S2Point.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** Build the normalized vector corresponding to spherical coordinates.
 * @param theta azimuthal angle \( \theta \) in the x-y plane
 * @param phi polar angle \( \varphi \)
 * @return normalized vector
 * @exception OutOfRangeException if \( \varphi \) is not in the [\( 0; \pi \)] range
 */
private static Vector3D vector(final double theta, final double phi)
   throws OutOfRangeException {

    if (phi < 0 || phi > FastMath.PI) {
        throw new OutOfRangeException(phi, 0, FastMath.PI);
    }

    final double cosTheta = FastMath.cos(theta);
    final double sinTheta = FastMath.sin(theta);
    final double cosPhi   = FastMath.cos(phi);
    final double sinPhi   = FastMath.sin(phi);

    return new Vector3D(cosTheta * sinPhi, sinTheta * sinPhi, cosPhi);

}
 
Example #3
Source File: LineTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testIntersection() throws MathIllegalArgumentException {
    Line l = new Line(new Vector3D(0, 1, 1), new Vector3D(0, 2, 2), 1.0e-10);
    Assert.assertNull(l.intersection(new Line(new Vector3D(1, 0, 1), new Vector3D(1, 0, 2), 1.0e-10)));
    Assert.assertNull(l.intersection(new Line(new Vector3D(-0.5, 0, 0), new Vector3D(-0.5, -1, -1), 1.0e-10)));
    Assert.assertEquals(0.0,
                        l.intersection(l).distance(new Vector3D(0, 0, 0)),
                        1.0e-10);
    Assert.assertEquals(0.0,
                        l.intersection(new Line(new Vector3D(0, -4, -4), new Vector3D(0, -5, -5), 1.0e-10)).distance(new Vector3D(0, 0, 0)),
                        1.0e-10);
    Assert.assertEquals(0.0,
                        l.intersection(new Line(new Vector3D(0, -4, -4), new Vector3D(0, -3, -4), 1.0e-10)).distance(new Vector3D(0, -4, -4)),
                        1.0e-10);
    Assert.assertEquals(0.0,
                        l.intersection(new Line(new Vector3D(0, -4, -4), new Vector3D(1, -4, -4), 1.0e-10)).distance(new Vector3D(0, -4, -4)),
                        1.0e-10);
    Assert.assertNull(l.intersection(new Line(new Vector3D(0, -4, 0), new Vector3D(1, -4, 0), 1.0e-10)));
}
 
Example #4
Source File: LineTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testLineDistance() throws MathIllegalArgumentException {
    Line l = new Line(new Vector3D(0, 1, 1), new Vector3D(0, 2, 2));
    Assert.assertEquals(1.0,
                        l.distance(new Line(new Vector3D(1, 0, 1), new Vector3D(1, 0, 2))),
                        1.0e-10);
    Assert.assertEquals(0.5,
                        l.distance(new Line(new Vector3D(-0.5, 0, 0), new Vector3D(-0.5, -1, -1))),
                        1.0e-10);
    Assert.assertEquals(0.0,
                        l.distance(l),
                        1.0e-10);
    Assert.assertEquals(0.0,
                        l.distance(new Line(new Vector3D(0, -4, -4), new Vector3D(0, -5, -5))),
                        1.0e-10);
    Assert.assertEquals(0.0,
                        l.distance(new Line(new Vector3D(0, -4, -4), new Vector3D(0, -3, -4))),
                        1.0e-10);
    Assert.assertEquals(0.0,
                        l.distance(new Line(new Vector3D(0, -4, -4), new Vector3D(1, -4, -4))),
                        1.0e-10);
    Assert.assertEquals(FastMath.sqrt(8),
                        l.distance(new Line(new Vector3D(0, -4, 0), new Vector3D(1, -4, 0))),
                        1.0e-10);
}
 
Example #5
Source File: BWBlockTransform.java    From NOVA-Core with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void setPosition(Vector3D position) {
	BlockPos oldPos = blockPos();
	BlockPos newPos = VectorConverter.instance().toNative(position);
	net.minecraft.world.World world = (net.minecraft.world.World) WorldConverter.instance().toNative(this.world);
	Optional<TileEntity> tileEntity = Optional.ofNullable(blockAccess().getTileEntity(oldPos));
	Optional<NBTTagCompound> nbt = Optional.empty();
	if (tileEntity.isPresent()) {
		NBTTagCompound compound = new NBTTagCompound();
		tileEntity.get().writeToNBT(compound);
           compound.setInteger("x", newPos.getX());
           compound.setInteger("y", newPos.getY());
           compound.setInteger("z", newPos.getZ());
		nbt = Optional.of(compound);
	}
	world.setBlockState(newPos, block.blockState());
	world.removeTileEntity(oldPos);
	world.setBlockToAir(oldPos);
	Optional<TileEntity> newTileEntity = Optional.ofNullable(blockAccess().getTileEntity(newPos));
	if (newTileEntity.isPresent() && nbt.isPresent()) {
		newTileEntity.get().readFromNBT(nbt.get());
	}
	this.position = position;
}
 
Example #6
Source File: LineTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testLineDistance() throws MathIllegalArgumentException {
    Line l = new Line(new Vector3D(0, 1, 1), new Vector3D(0, 2, 2));
    Assert.assertEquals(1.0,
                        l.distance(new Line(new Vector3D(1, 0, 1), new Vector3D(1, 0, 2))),
                        1.0e-10);
    Assert.assertEquals(0.5,
                        l.distance(new Line(new Vector3D(-0.5, 0, 0), new Vector3D(-0.5, -1, -1))),
                        1.0e-10);
    Assert.assertEquals(0.0,
                        l.distance(l),
                        1.0e-10);
    Assert.assertEquals(0.0,
                        l.distance(new Line(new Vector3D(0, -4, -4), new Vector3D(0, -5, -5))),
                        1.0e-10);
    Assert.assertEquals(0.0,
                        l.distance(new Line(new Vector3D(0, -4, -4), new Vector3D(0, -3, -4))),
                        1.0e-10);
    Assert.assertEquals(0.0,
                        l.distance(new Line(new Vector3D(0, -4, -4), new Vector3D(1, -4, -4))),
                        1.0e-10);
    Assert.assertEquals(FastMath.sqrt(8),
                        l.distance(new Line(new Vector3D(0, -4, 0), new Vector3D(1, -4, 0))),
                        1.0e-10);
}
 
Example #7
Source File: WelzlEncloser3DTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testReducingBall() {
    List<Vector3D> list =
            Arrays.asList(new Vector3D(-7.140397329568118, -16.571661242582177,  11.714458961735405),
                          new Vector3D(-7.137986707455888, -16.570767323375720,  11.708602108715928),
                          new Vector3D(-7.139185068549035, -16.570891204702250,  11.715554057357394),
                          new Vector3D(-7.142682716997507, -16.571609818234290,  11.710787934580328),
                          new Vector3D(-7.139018392423351, -16.574405614157020,  11.710518716711425),
                          new Vector3D(-7.140870659936730, -16.567993074240455,  11.710914678204503),
                          new Vector3D(-7.136350173659562, -16.570498228820930,  11.713965225900928),
                          new Vector3D(-7.141675762759172, -16.572852471407028,  11.714033471449508),
                          new Vector3D(-7.140453077221105, -16.570212820780647,  11.708624578004980),
                          new Vector3D(-7.140322188726825, -16.574152894557717,  11.710305611121410),
                          new Vector3D(-7.141116131477088, -16.574061164624560,  11.712938509321699));
    WelzlEncloser<Euclidean3D, Vector3D> encloser =
            new WelzlEncloser<Euclidean3D, Vector3D>(1.0e-10, new SphereGenerator());
    EnclosingBall<Euclidean3D, Vector3D> ball = encloser.enclose(list);
    Assert.assertTrue(ball.getRadius() > 0);
}
 
Example #8
Source File: LineTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testLineDistance() throws MathIllegalArgumentException {
    Line l = new Line(new Vector3D(0, 1, 1), new Vector3D(0, 2, 2), 1.0e-10);
    Assert.assertEquals(1.0,
                        l.distance(new Line(new Vector3D(1, 0, 1), new Vector3D(1, 0, 2), 1.0e-10)),
                        1.0e-10);
    Assert.assertEquals(0.5,
                        l.distance(new Line(new Vector3D(-0.5, 0, 0), new Vector3D(-0.5, -1, -1), 1.0e-10)),
                        1.0e-10);
    Assert.assertEquals(0.0,
                        l.distance(l),
                        1.0e-10);
    Assert.assertEquals(0.0,
                        l.distance(new Line(new Vector3D(0, -4, -4), new Vector3D(0, -5, -5), 1.0e-10)),
                        1.0e-10);
    Assert.assertEquals(0.0,
                        l.distance(new Line(new Vector3D(0, -4, -4), new Vector3D(0, -3, -4), 1.0e-10)),
                        1.0e-10);
    Assert.assertEquals(0.0,
                        l.distance(new Line(new Vector3D(0, -4, -4), new Vector3D(1, -4, -4), 1.0e-10)),
                        1.0e-10);
    Assert.assertEquals(FastMath.sqrt(8),
                        l.distance(new Line(new Vector3D(0, -4, 0), new Vector3D(1, -4, 0), 1.0e-10)),
                        1.0e-10);
}
 
Example #9
Source File: Vector3DFormatAbstractTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testDefaultFormatVector3D() {
    Locale defaultLocal = Locale.getDefault();
    Locale.setDefault(getLocale());

    Vector3D c = new Vector3D(232.222, -342.33, 432.444);
    String expected =
        "{232"    + getDecimalCharacter() +
        "22; -342" + getDecimalCharacter() +
        "33; 432" + getDecimalCharacter() +
        "44}";
    String actual = (new Vector3DFormat()).format(c);
    Assert.assertEquals(expected, actual);

    Locale.setDefault(defaultLocal);
}
 
Example #10
Source File: SubCircle.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public Side side(final Hyperplane<Sphere2D> hyperplane) {

    final Circle thisCircle  = (Circle) getHyperplane();
    final Circle otherCircle = (Circle) hyperplane;
    final double angle = Vector3D.angle(thisCircle.getPole(), otherCircle.getPole());

    if (angle < thisCircle.getTolerance() || angle > FastMath.PI - thisCircle.getTolerance()) {
        // the two circles are aligned or opposite
        return Side.HYPER;
    } else {
        // the two circles intersect each other
        return ((ArcsSet) getRemainingRegion()).side(thisCircle.getInsideArc(otherCircle));
    }

}
 
Example #11
Source File: LineTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testIntersection() throws MathIllegalArgumentException {
    Line l = new Line(new Vector3D(0, 1, 1), new Vector3D(0, 2, 2));
    Assert.assertNull(l.intersection(new Line(new Vector3D(1, 0, 1), new Vector3D(1, 0, 2))));
    Assert.assertNull(l.intersection(new Line(new Vector3D(-0.5, 0, 0), new Vector3D(-0.5, -1, -1))));
    Assert.assertEquals(0.0,
                        l.intersection(l).distance(new Vector3D(0, 0, 0)),
                        1.0e-10);
    Assert.assertEquals(0.0,
                        l.intersection(new Line(new Vector3D(0, -4, -4), new Vector3D(0, -5, -5))).distance(new Vector3D(0, 0, 0)),
                        1.0e-10);
    Assert.assertEquals(0.0,
                        l.intersection(new Line(new Vector3D(0, -4, -4), new Vector3D(0, -3, -4))).distance(new Vector3D(0, -4, -4)),
                        1.0e-10);
    Assert.assertEquals(0.0,
                        l.intersection(new Line(new Vector3D(0, -4, -4), new Vector3D(1, -4, -4))).distance(new Vector3D(0, -4, -4)),
                        1.0e-10);
    Assert.assertNull(l.intersection(new Line(new Vector3D(0, -4, 0), new Vector3D(1, -4, 0))));
}
 
Example #12
Source File: BWRigidBody.java    From NOVA-Core with GNU Lesser General Public License v3.0 6 votes vote down vote up
void updateTranslation(double deltaTime) {
	//Integrate velocity to displacement
	Vector3D displacement = velocity().scalarMultiply(deltaTime);
	mcEntity().moveEntity(displacement.getX(), displacement.getY(), displacement.getZ());

	//Integrate netForce to velocity
	setVelocity(velocity().add(netForce.scalarMultiply(1 / mass()).scalarMultiply(deltaTime)));

	//Clear net force
	netForce = Vector3D.ZERO;

	//Apply drag
	addForce(velocity().negate().scalarMultiply(drag()));
	if (!mcEntity().onGround) {
		//Apply gravity
		addForce(gravity().scalarMultiply(mass()));
	}
}
 
Example #13
Source File: Vector3DFormatAbstractTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testNegativeY() {
    Vector3D c = new Vector3D(1.23, -1.434343434343, 1.63);
    String expected =
        "{1"    + getDecimalCharacter() +
        "23; -1" + getDecimalCharacter() +
        "4343434343; 1" + getDecimalCharacter() +
        "63}";
    String actual = vector3DFormat.format(c);
    Assert.assertEquals(expected, actual);
}
 
Example #14
Source File: Vector3DFormatAbstractTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testNegativeX() {
    Vector3D c = new Vector3D(-1.232323232323, 1.43, 1.63);
    String expected =
        "{-1"    + getDecimalCharacter() +
        "2323232323; 1" + getDecimalCharacter() +
        "43; 1" + getDecimalCharacter() +
        "63}";
    String actual = vector3DFormat.format(c);
    Assert.assertEquals(expected, actual);
}
 
Example #15
Source File: Vector3DFormatAbstractTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testParseIgnoredWhitespace() {
    Vector3D expected = new Vector3D(1, 1, 1);
    ParsePosition pos1 = new ParsePosition(0);
    String source1 = "{1;1;1}";
    Assert.assertEquals(expected, vector3DFormat.parse(source1, pos1));
    Assert.assertEquals(source1.length(), pos1.getIndex());
    ParsePosition pos2 = new ParsePosition(0);
    String source2 = " { 1 ; 1 ; 1 } ";
    Assert.assertEquals(expected, vector3DFormat.parse(source2, pos2));
    Assert.assertEquals(source2.length() - 1, pos2.getIndex());
}
 
Example #16
Source File: MatrixStackTest.java    From NOVA-Core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testTransforms() {
	ms.translate(Vector3DUtil.ONE);
	ms.scale(Vector3DUtil.ONE.scalarMultiply(2));
	ms.pushMatrix();
	ms.rotate(Vector3D.PLUS_J, Math.PI / 2);
	assertThat(ms.apply(Vector3D.PLUS_K)).isAlmostEqualTo(new Vector3D(-1, 1, 1));

	ms.popMatrix();
	ms.transform(MatrixUtils.createRealMatrix(new Rotation(Vector3D.PLUS_J, Math.PI / 2).getMatrix()));
	assertThat(ms.apply(Vector3D.PLUS_K)).isAlmostEqualTo(new Vector3D(-1, 1, 1));

	assertThat(ms.apply(Vector3DUtil.ONE)).isAlmostEqualTo(ms.apply(Vector3DUtil.ONE));

}
 
Example #17
Source File: FWBlock.java    From NOVA-Core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void setBlockBoundsBasedOnState(IBlockAccess access, int x, int y, int z) {
	Block blockInstance = getBlockInstance(access, new Vector3D(x, y, z));
	if (blockInstance.components.has(Collider.class)) {
		Cuboid cuboid = blockInstance.components.get(Collider.class).boundingBox.get();
		setBlockBounds((float) cuboid.min.getX(), (float) cuboid.min.getY(), (float) cuboid.min.getZ(), (float) cuboid.max.getX(), (float) cuboid.max.getY(), (float) cuboid.max.getZ());
	}
}
 
Example #18
Source File: Vector3DFormatAbstractTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testParseNegativeZ() throws MathParseException {
    String source =
        "{1" + getDecimalCharacter() +
        "2323; 1" + getDecimalCharacter() +
        "4343; -1" + getDecimalCharacter() +
        "6333}";
    Vector3D expected = new Vector3D(1.2323, 1.4343, -1.6333);
    Vector3D actual = vector3DFormat.parse(source);
    Assert.assertEquals(expected, actual);
}
 
Example #19
Source File: PlaneTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testOffset() throws MathArithmeticException {
    Vector3D p1 = new Vector3D(1, 1, 1);
    Plane p = new Plane(p1, new Vector3D(0.2, 0, 0), 1.0e-10);
    Assert.assertEquals(-5.0, p.getOffset(new Vector3D(-4, 0, 0)), 1.0e-10);
    Assert.assertEquals(+5.0, p.getOffset(new Vector3D(6, 10, -12)), 1.0e-10);
    Assert.assertEquals(0.3,
                        p.getOffset(new Vector3D(1.0, p1, 0.3, p.getNormal())),
                        1.0e-10);
    Assert.assertEquals(-0.3,
                        p.getOffset(new Vector3D(1.0, p1, -0.3, p.getNormal())),
                        1.0e-10);
}
 
Example #20
Source File: Vector3DFormatAbstractTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testParseSimpleWithDecimalsTrunc() throws MathParseException {
    String source =
        "{1" + getDecimalCharacter() +
        "2323; 1" + getDecimalCharacter() +
        "4343; 1" + getDecimalCharacter() +
        "6333}";
    Vector3D expected = new Vector3D(1.2323, 1.4343, 1.6333);
    Vector3D actual = vector3DFormat.parse(source);
    Assert.assertEquals(expected, actual);
}
 
Example #21
Source File: FWBlock.java    From NOVA-Core with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Block getBlockInstance(nova.core.world.World world, Vector3D position) {
	Block block = factory.build();
	block.components.add(new MCBlockTransform(block, world, position));
	if (!block.components.has(BlockProperty.BlockSound.class)) {
		BlockProperty.BlockSound properties = block.components.add(new BlockProperty.BlockSound());
		properties.setBlockSound(BlockProperty.BlockSound.BlockSoundTrigger.BREAK, new Sound("", soundTypeStone.getBreakSound()));
		properties.setBlockSound(BlockProperty.BlockSound.BlockSoundTrigger.PLACE, new Sound("", soundTypeStone.func_150496_b()));
		properties.setBlockSound(BlockProperty.BlockSound.BlockSoundTrigger.WALK, new Sound("", soundTypeStone.getStepResourcePath()));
		this.stepSound = soundTypeStone;
	}
	return block;
}
 
Example #22
Source File: AbstractFeatureTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
protected static Mesh getMesh() {
	final Mesh m = new NaiveDoubleMesh();
	// To prevent duplicates, map each (x, y, z) triple to its own index.
	final Map<Vector3D, Long> indexMap = new HashMap<>();
	final LongArray indices = new LongArray();
	try {
		Files.lines(Paths.get(AbstractFeatureTest.class.getResource("3d_geometric_features_mesh.txt").toURI()))
									.forEach(l -> {
										String[] coord = l.split(" ");
										final double x = Double.parseDouble(coord[0]);
										final double y = Double.parseDouble(coord[1]);
										final double z = Double.parseDouble(coord[2]);
										final Vector3D vertex = new Vector3D(x, y, z);
										final long vIndex = indexMap.computeIfAbsent(vertex, //
											v -> m.vertices().add(x, y, z));
										indices.add(vIndex);
									});
	} catch (IOException | URISyntaxException exc) {
		exc.printStackTrace();
	}
	for (int i = 0; i < indices.size(); i += 3) {
		final long v0 = indices.get(i);
		final long v1 = indices.get(i + 1);
		final long v2 = indices.get(i + 2);
		m.triangles().add(v0, v1, v2);
	}
	return m;
}
 
Example #23
Source File: CircleTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testSpace() {
    Circle circle = new Circle(new S2Point(1.2, 2.5), new S2Point(-4.3, 0), 1.0e-10);
    for (double alpha = 0; alpha < MathUtils.TWO_PI; alpha += 0.1) {
        Vector3D p = new Vector3D(FastMath.cos(alpha), circle.getXAxis(),
                                  FastMath.sin(alpha), circle.getYAxis());
        Vector3D q = circle.toSpace(new S1Point(alpha)).getVector();
        Assert.assertEquals(0.0, p.distance(q), 1.0e-10);
        Assert.assertEquals(0.5 * FastMath.PI, Vector3D.angle(circle.getPole(), q), 1.0e-10);
    }
}
 
Example #24
Source File: Face.java    From NOVA-Core with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Gets the center of this face.
 *
 * @return Center
 */
public Vector3D getCenter() {
	if (vertices.size() >= 3) {
		return vertices
			.stream()
			.map(v -> v.vec)
			.reduce(Vector3D.ZERO, Vector3D::add)
			.scalarMultiply(1f / vertices.size());
	}

	return Vector3D.ZERO;
}
 
Example #25
Source File: Vector3DFormatAbstractTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testNan() {
    Vector3D c = Vector3D.NaN;
    String expected = "{(NaN); (NaN); (NaN)}";
    String actual = vector3DFormat.format(c);
    Assert.assertEquals(expected, actual);
}
 
Example #26
Source File: SphericalPolygonsSetTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testFullSphere() {
    SphericalPolygonsSet full = new SphericalPolygonsSet(1.0e-10);
    UnitSphereRandomVectorGenerator random =
            new UnitSphereRandomVectorGenerator(3, new Well1024a(0x852fd2a0ed8d2f6dl));
    for (int i = 0; i < 1000; ++i) {
        Vector3D v = new Vector3D(random.nextVector());
        Assert.assertEquals(Location.INSIDE, full.checkPoint(new S2Point(v)));
    }
    Assert.assertEquals(4 * FastMath.PI, new SphericalPolygonsSet(0.01, new S2Point[0]).getSize(), 1.0e-10);
    Assert.assertEquals(0, new SphericalPolygonsSet(0.01, new S2Point[0]).getBoundarySize(), 1.0e-10);
    Assert.assertEquals(0, full.getBoundaryLoops().size());
    Assert.assertTrue(full.getEnclosingCap().getRadius() > 0);
    Assert.assertTrue(Double.isInfinite(full.getEnclosingCap().getRadius()));
}
 
Example #27
Source File: Vector3DFormatAbstractTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testParseNonDefaultSetting() {
    String source =
        "[1" + getDecimalCharacter() +
        "2323 : 1" + getDecimalCharacter() +
        "4343 : 1" + getDecimalCharacter() +
        "6333]";
    Vector3D expected = new Vector3D(1.2323, 1.4343, 1.6333);
    Vector3D actual = vector3DFormatSquare.parse(source);
    Assert.assertEquals(expected, actual);
}
 
Example #28
Source File: PlaneTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testThreePoints() throws MathArithmeticException {
    Vector3D p1 = new Vector3D(1.2, 3.4, -5.8);
    Vector3D p2 = new Vector3D(3.4, -5.8, 1.2);
    Vector3D p3 = new Vector3D(-2.0, 4.3, 0.7);
    Plane    p  = new Plane(p1, p2, p3);
    Assert.assertTrue(p.contains(p1));
    Assert.assertTrue(p.contains(p2));
    Assert.assertTrue(p.contains(p3));
}
 
Example #29
Source File: Vector3DFormatAbstractTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testNan() {
    Vector3D c = Vector3D.NaN;
    String expected = "{(NaN); (NaN); (NaN)}";
    String actual = vector3DFormat.format(c);
    Assert.assertEquals(expected, actual);
}
 
Example #30
Source File: Vector3DFormatAbstractTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testNan() {
    Vector3D c = Vector3D.NaN;
    String expected = "{(NaN); (NaN); (NaN)}";
    String actual = vector3DFormat.format(c);
    Assert.assertEquals(expected, actual);
}