Java Code Examples for org.apache.commons.math3.geometry.euclidean.threed.Vector3D#ZERO
The following examples show how to use
org.apache.commons.math3.geometry.euclidean.threed.Vector3D#ZERO .
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: GaussNewtonOptimizerWithSVDTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test @Override public void testNonInvertible() throws Exception { /* SVD can compute a solution to singular problems. * In this case the target vector, b, is not in the * span of the jacobian matrix, A. The closes point * to b on the plane spanned by A is computed. */ LinearProblem problem = new LinearProblem(new double[][]{ {1, 2, -3}, {2, 1, 3}, {-3, 0, -9} }, new double[]{1, 1, 1}); Optimum optimum = optimizer.optimize(problem.getBuilder().build()); Plane span = new Plane(Vector3D.ZERO, new Vector3D(1, 2, -3), new Vector3D(2, 1, 0), TOl); double expected = FastMath.abs(span.getOffset(new Vector3D(1, 1, 1))); double actual = optimum.getResiduals().getNorm(); //verify Assert.assertEquals(expected, actual, TOl); }
Example 2
Source File: GaussNewtonOptimizerWithSVDTest.java From astor with GNU General Public License v2.0 | 6 votes |
@Test @Override public void testNonInvertible() throws Exception { /* SVD can compute a solution to singular problems. * In this case the target vector, b, is not in the * span of the jacobian matrix, A. The closes point * to b on the plane spanned by A is computed. */ LinearProblem problem = new LinearProblem(new double[][]{ {1, 2, -3}, {2, 1, 3}, {-3, 0, -9} }, new double[]{1, 1, 1}); Optimum optimum = optimizer.optimize(problem.getBuilder().build()); Plane span = new Plane(Vector3D.ZERO, new Vector3D(1, 2, -3), new Vector3D(2, 1, 0), TOl); double expected = FastMath.abs(span.getOffset(new Vector3D(1, 1, 1))); double actual = optimum.getResiduals().getNorm(); //verify Assert.assertEquals(expected, actual, TOl); }
Example 3
Source File: BWRigidBody.java From NOVA-Core with GNU Lesser General Public License v3.0 | 6 votes |
void updateTranslation(double deltaTime) { //Integrate velocity to displacement Vector3D displacement = velocity().scalarMultiply(deltaTime); mcEntity().move(MoverType.SELF, 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 4
Source File: BWRigidBody.java From NOVA-Core with GNU Lesser General Public License v3.0 | 6 votes |
void updateRotation(double deltaTime) { //Integrate angular velocity to angular displacement Rotation angularVel = angularVelocity(); Rotation deltaRotation = RotationUtil.slerp(Rotation.IDENTITY, angularVel, deltaTime); entity().transform().setRotation(entity().rotation().applyTo(deltaRotation)); //Integrate torque to angular velocity Vector3D torque = netTorque.scalarMultiply(deltaTime); if (!Vector3D.ZERO.equals(torque)) { setAngularVelocity(angularVelocity().applyTo(new Rotation(Vector3DUtil.FORWARD, torque))); } //Clear net torque netTorque = Vector3D.ZERO; //Apply drag Vector3D eulerAngularVel = angularVelocity().applyInverseTo(Vector3DUtil.FORWARD); addTorque(eulerAngularVel.negate().scalarMultiply(angularDrag())); }
Example 5
Source File: BWRigidBody.java From NOVA-Core with GNU Lesser General Public License v3.0 | 6 votes |
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 6
Source File: BWRigidBody.java From NOVA-Core with GNU Lesser General Public License v3.0 | 6 votes |
void updateRotation(double deltaTime) { //Integrate angular velocity to angular displacement Rotation angularVel = angularVelocity(); Rotation deltaRotation = RotationUtil.slerp(Rotation.IDENTITY, angularVel, deltaTime); entity().transform().setRotation(entity().rotation().applyTo(deltaRotation)); //Integrate torque to angular velocity Vector3D torque = netTorque.scalarMultiply(deltaTime); if (!Vector3D.ZERO.equals(torque)) { setAngularVelocity(angularVelocity().applyTo(new Rotation(Vector3DUtil.FORWARD, torque))); } //Clear net torque netTorque = Vector3D.ZERO; //Apply drag Vector3D eulerAngularVel = angularVelocity().applyInverseTo(Vector3DUtil.FORWARD); addTorque(eulerAngularVel.negate().scalarMultiply(angularDrag())); }
Example 7
Source File: BWRigidBody.java From NOVA-Core with GNU Lesser General Public License v3.0 | 6 votes |
void updateRotation(double deltaTime) { //Integrate angular velocity to angular displacement Rotation angularVel = angularVelocity(); Rotation deltaRotation = RotationUtil.slerp(Rotation.IDENTITY, angularVel, deltaTime); entity().transform().setRotation(entity().rotation().applyTo(deltaRotation)); //Integrate torque to angular velocity Vector3D torque = netTorque.scalarMultiply(deltaTime); if (!Vector3D.ZERO.equals(torque)) { setAngularVelocity(angularVelocity().applyTo(new Rotation(Vector3DUtil.FORWARD, torque))); } //Clear net torque netTorque = Vector3D.ZERO; //Apply drag Vector3D eulerAngularVel = angularVelocity().applyInverseTo(Vector3DUtil.FORWARD); addTorque(eulerAngularVel.negate().scalarMultiply(angularDrag())); }
Example 8
Source File: BWRigidBody.java From NOVA-Core with GNU Lesser General Public License v3.0 | 6 votes |
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 9
Source File: TriangularFacet.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
/** * Compute the centroid of this facet. */ private void computeCentroid() { centroid = Vector3D.ZERO; Iterator<Vertex> it = vertices.iterator(); while (it.hasNext()) { centroid = centroid.add(it.next()); } centroid = centroid.scalarMultiply(1 / (double) vertices.size()); }
Example 10
Source File: Face.java From NOVA-Core with GNU Lesser General Public License v3.0 | 5 votes |
/** * 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 11
Source File: PropertiesComputer.java From astor with GNU General Public License v2.0 | 5 votes |
/** Simple constructor. * @param tolerance below which points are consider to be identical */ public PropertiesComputer(final double tolerance) { this.tolerance = tolerance; this.summedArea = 0; this.summedBarycenter = Vector3D.ZERO; this.convexCellsInsidePoints = new ArrayList<Vector3D>(); }
Example 12
Source File: PropertiesComputer.java From astor with GNU General Public License v2.0 | 5 votes |
/** Simple constructor. * @param tolerance below which points are consider to be identical */ public PropertiesComputer(final double tolerance) { this.tolerance = tolerance; this.summedArea = 0; this.summedBarycenter = Vector3D.ZERO; this.convexCellsInsidePoints = new ArrayList<Vector3D>(); }
Example 13
Source File: TransformUtilTest.java From NOVA-Core with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void testTranslation() { Vector3D start = Vector3D.ZERO; assertThat(TransformUtil.transform(start, TransformUtil.translationMatrix(0, 0, 0))).isEqualTo(start); Vector3D by = new Vector3D(3, 0, -6); assertThat(TransformUtil.transform(start, TransformUtil.translationMatrix(by))).isEqualTo(by); start = Vector3DUtil.ONE; assertThat(TransformUtil.transform(start, TransformUtil.translationMatrix(by))).isEqualTo(start.add(by)); }
Example 14
Source File: WavefrontObjectModelProvider.java From NOVA-Core with GNU Lesser General Public License v3.0 | 5 votes |
private Vector3D getNormal(int index) { try { return vertexNormals.get(index < 0 ? index + textureCoordinates.size() : index - 1); } catch (IndexOutOfBoundsException e) { System.err.println("[OBJ]: Can't get vertexNormal " + index + "! Is this model corrupted?"); return Vector3D.ZERO; } }
Example 15
Source File: WavefrontObjectModelProvider.java From NOVA-Core with GNU Lesser General Public License v3.0 | 5 votes |
private Vector3D getVertex(int index) { try { return vertices.get(index < 0 ? index + textureCoordinates.size() : index - 1); } catch (IndexOutOfBoundsException e) { System.err.println("[OBJ]: Can't get vertex " + index + "! Is this model corrupted?"); return Vector3D.ZERO; } }
Example 16
Source File: BWBakedModel.java From NOVA-Core with GNU Lesser General Public License v3.0 | 4 votes |
@SuppressWarnings("unchecked") public Face quadToFace(BakedQuad quad) { Face face = new Face(); final VertexFormat format = this.format; // 1.11.2 stores VertexFormat on a per-quad basis. int[] data = quad.getVertexData(); Optional<TextureAtlasSprite> texture = Optional.ofNullable(wrapped.getTexture()); final Optional<VertexFormatElement> posElement = ((Collection<VertexFormatElement>)format.getElements()).stream() .filter(VertexFormatElement::isPositionElement) .findFirst(); final Optional<VertexFormatElement> uvElement = ((Collection<VertexFormatElement>)format.getElements()).stream() .filter(vfe -> vfe.getUsage() == VertexFormatElement.EnumUsage.UV) .findFirst(); face.texture = texture .filter(t -> uvElement.isPresent()) .map(TextureAtlasSprite::getIconName) .map(ResourceLocation::new) .map(AssetConverter.instance()::toNovaTexture); // `VertexFormat` offsets are for a `ByteBuffer` // `data` is an int array, so we convert the offsets // TODO: support offsets which are not divisible by four final int posOffset = posElement.map(VertexFormatElement::getOffset).map(i -> i / 4).orElse(-1); final int uvOffset = uvElement.map(VertexFormatElement::getOffset).map(i -> i / 4).orElse(-1); final int colorOffset = format.hasColor() ? (format.getColorOffset() / 4) : -1; final int normalOffset = format.hasNormal() ? (format.getNormalOffset() / 4) : -1; for (int i = 0; i < data.length; i += 7) { Vector3D pos = posElement.isPresent() ? new Vector3D( Float.intBitsToFloat(data[i + posOffset]), Float.intBitsToFloat(data[i + posOffset + 1]), Float.intBitsToFloat(data[i + posOffset + 2])) : Vector3D.ZERO; Vector2D uv = uvElement.isPresent() ? new Vector2D( deinterpolateU(Float.intBitsToFloat(data[i + uvOffset]), texture), deinterpolateV(Float.intBitsToFloat(data[i + uvOffset + 1]), texture)) : Vector2D.ZERO; Vertex vertex = new Vertex(pos, uv); if (format.hasColor()) { if (DefaultVertexFormats.BLOCK.equals(format)) vertex.color = Color.argb(data[i + colorOffset]); else vertex.color = Color.rgba(data[i + colorOffset]); } Optional<Vector3D> normal = Optional.empty(); if (format.hasNormal()) { int mergedNormal = data[i + normalOffset]; if (mergedNormal != 0) normal = Optional.of(new Vector3D(((byte)(mergedNormal & 0xFF)) / 127D, ((byte)((mergedNormal >> 8) & 0xFF)) / 127D, ((byte)((mergedNormal >> 16) & 0xFF)) / 127D)); } if (format.hasNormal()) vertex.normal = normal; face.drawVertex(vertex); } face.normal = Vector3DUtil.calculateNormal(face); return face; }
Example 17
Source File: BWBakedModel.java From NOVA-Core with GNU Lesser General Public License v3.0 | 4 votes |
public Face quadToFace(BakedQuad quad) { Face face = new Face(); final VertexFormat format = quad.getFormat(); int[] data = quad.getVertexData(); Optional<TextureAtlasSprite> texture = Optional.ofNullable(quad.getSprite() == null ? wrapped.getParticleTexture() : quad.getSprite()); final Optional<VertexFormatElement> posElement = ((Collection<VertexFormatElement>)format.getElements()).stream() .filter(VertexFormatElement::isPositionElement) .findFirst(); final Optional<VertexFormatElement> uvElement = ((Collection<VertexFormatElement>)format.getElements()).stream() .filter(vfe -> vfe.getUsage() == VertexFormatElement.EnumUsage.UV) .findFirst(); face.texture = texture .filter(t -> uvElement.isPresent()) .map(TextureAtlasSprite::getIconName) .map(ResourceLocation::new) .map(AssetConverter.instance()::toNovaTexture); // `VertexFormat` offsets are for a `ByteBuffer` // `data` is an int array, so we convert it // TODO: support offsets which are not divisible by four final int posOffset = posElement.map(VertexFormatElement::getIndex).map(i -> i / 4).orElse(-1); final int uvOffset = uvElement.map(VertexFormatElement::getIndex).map(i -> i / 4).orElse(-1); final int colorOffset = format.hasColor() ? (format.getColorOffset() / 4) : -1; final int normalOffset = format.hasNormal() ? (format.getNormalOffset() / 4) : -1; for (int i = 0; i < data.length; i += 7) { Vector3D pos = posElement.isPresent() ? new Vector3D( Float.intBitsToFloat(data[i + posOffset]), Float.intBitsToFloat(data[i + posOffset + 1]), Float.intBitsToFloat(data[i + posOffset + 2])) : Vector3D.ZERO; Vector2D uv = uvElement.isPresent() ? new Vector2D( deinterpolateU(Float.intBitsToFloat(data[i + uvOffset]), texture), deinterpolateV(Float.intBitsToFloat(data[i + uvOffset + 1]), texture)) : Vector2D.ZERO; Vertex vertex = new Vertex(pos, uv); if (format.hasColor()) { vertex.color = Color.argb(data[i + colorOffset]); } Optional<Vector3D> normal = Optional.empty(); if (format.hasNormal()) { int mergedNormal = data[i + normalOffset]; if (mergedNormal != 0) normal = Optional.of(new Vector3D(((byte)(mergedNormal & 0xFF)) / 127D, ((byte)((mergedNormal >> 8) & 0xFF)) / 127D, ((byte)((mergedNormal >> 16) & 0xFF)) / 127D)); } if (format.hasNormal()) vertex.normal = normal; face.drawVertex(vertex); } face.normal = Vector3DUtil.calculateNormal(face); return face; }
Example 18
Source File: NovaAssertions.java From NOVA-Core with GNU Lesser General Public License v3.0 | 4 votes |
private AlmostEqualAssertionVector3D(Vector3D actual) { super(actual, AlmostEqualAssertionVector3D.class, Vector3D.ZERO); }