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

The following examples show how to use org.apache.commons.math3.geometry.euclidean.threed.Vector3D#getX() . 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: 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();
		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 2
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: Allow serialization of arbitrary vertex formats.
	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 3
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 4
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 BWParticle) {
		Particle particle = ((BWParticle) entity).createParticle(world);
		Vector3D position = entity.position();
		particle.posX = position.getX();
		particle.posY = position.getY();
		particle.posZ = position.getZ();
		FMLClientHandler.instance().getClient().effectRenderer.addEffect(particle);
		return Game.natives().toNova(particle);
	} else {
		FWParticle bwEntityFX = new FWParticle(world, entity);
		FMLClientHandler.instance().getClient().effectRenderer.addEffect(bwEntityFX);
		return bwEntityFX.wrapped;
	}
}
 
Example 5
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 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 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 7
Source File: RayTracer.java    From NOVA-Core with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Calculates intersection with the given ray between a certain distance
 * interval.
 * <p>
 * Ray-box intersection is using IEEE numerical properties to ensure the
 * test is both robust and efficient, as described in:
 * <br>
 * <code>Amy Williams, Steve Barrus, R. Keith Morley, and Peter Shirley: "An
 * Efficient and Robust Ray-Box Intersection Algorithm" Journal of graphics
 * tools, 10(1):49-54, 2005</code>
 * @param cuboid The cuboid to trace
 * @param minDist The minimum distance
 * @param maxDist The maximum distance
 * @return intersection point on the bounding box (only the first is
 * returned) or null if no intersection
 */
public Optional<Vector3D> rayTrace(Cuboid cuboid, double minDist, double maxDist) {
	Vector3D bbox;

	double tMin;
	double tMax;

	bbox = ray.signDirX ? cuboid.max : cuboid.min;
	tMin = (bbox.getX() - ray.origin.getX()) * ray.invDir.getX();
	bbox = ray.signDirX ? cuboid.min : cuboid.max;
	tMax = (bbox.getX() - ray.origin.getX()) * ray.invDir.getX();

	//Y
	bbox = ray.signDirY ? cuboid.max : cuboid.min;
	double tyMin = (bbox.getY() - ray.origin.getY()) * ray.invDir.getY();
	bbox = ray.signDirY ? cuboid.min : cuboid.max;
	double tyMax = (bbox.getY() - ray.origin.getY()) * ray.invDir.getY();

	//Check with the current tMin and tMax to see if the clipping is out of bounds
	if ((tMin > tyMax) || (tyMin > tMax)) {
		return Optional.empty();
	}

	//Reset tMin and tMax
	if (tyMin > tMin) {
		tMin = tyMin;
	}
	if (tyMax < tMax) {
		tMax = tyMax;
	}
	bbox = ray.signDirZ ? cuboid.max : cuboid.min;
	double tzMin = (bbox.getZ() - ray.origin.getZ()) * ray.invDir.getZ();
	bbox = ray.signDirZ ? cuboid.min : cuboid.max;
	double tzMax = (bbox.getZ() - ray.origin.getZ()) * ray.invDir.getZ();

	//Check with the current tMin and tMax to see if the clipping is out of bounds
	if ((tMin > tzMax) || (tzMin > tMax)) {
		return Optional.empty();
	}

	//Reset tMin and tMax
	if (tzMin > tMin) {
		tMin = tzMin;
	}
	if (tzMax < tMax) {
		tMax = tzMax;
	}

	if ((tMin < maxDist) && (tMax > minDist)) {
		return Optional.of(ray.origin.add(ray.dir.scalarMultiply(tMin)));
	}

	return Optional.empty();
}
 
Example 8
Source File: BWRigidBody.java    From NOVA-Core with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void setVelocity(Vector3D velocity) {
	mcEntity().motionX = velocity.getX();
	mcEntity().motionY = velocity.getY();
	mcEntity().motionZ = velocity.getZ();
}
 
Example 9
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 10
Source File: BWRigidBody.java    From NOVA-Core with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void setVelocity(Vector3D velocity) {
	mcEntity().motionX = velocity.getX();
	mcEntity().motionY = velocity.getY();
	mcEntity().motionZ = velocity.getZ();
}
 
Example 11
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 12
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().spawnEntity(entityItem);
	return EntityConverter.instance().toNova(entityItem);
}
 
Example 13
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 14
Source File: Vector3DUtil.java    From NOVA-Core with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static Vector3D zCross(Vector3D vec) {
	return new Vector3D(-vec.getY(), vec.getX(), 0);
}
 
Example 15
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 16
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 17
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 EntityConverter.instance().toNova(entityItem);
}
 
Example 18
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 19
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 20
Source File: Vector3DUtil.java    From NOVA-Core with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Calculates one by vectos.
 * @param vec vector to be reciprocated.
 * @return reciprocal of vec.
 */
public static Vector3D reciprocal(Vector3D vec) {
	return new Vector3D(1 / vec.getX(), 1 / vec.getY(), 1 / vec.getZ());
}