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

The following examples show how to use org.apache.commons.math3.geometry.euclidean.threed.Rotation. 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: PlaneTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testRotate() throws MathArithmeticException, MathIllegalArgumentException {
    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);
    Vector3D oldNormal = p.getNormal();

    p = p.rotate(p2, new Rotation(p2.subtract(p1), 1.7));
    Assert.assertTrue(p.contains(p1));
    Assert.assertTrue(p.contains(p2));
    Assert.assertTrue(! p.contains(p3));

    p = p.rotate(p2, new Rotation(oldNormal, 0.1));
    Assert.assertTrue(! p.contains(p1));
    Assert.assertTrue(p.contains(p2));
    Assert.assertTrue(! p.contains(p3));

    p = p.rotate(p1, new Rotation(oldNormal, 0.1));
    Assert.assertTrue(! p.contains(p1));
    Assert.assertTrue(! p.contains(p2));
    Assert.assertTrue(! p.contains(p3));

}
 
Example #2
Source File: PlaneTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testRotate() throws MathArithmeticException, MathIllegalArgumentException {
    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);
    Vector3D oldNormal = p.getNormal();

    p = p.rotate(p2, new Rotation(p2.subtract(p1), 1.7));
    Assert.assertTrue(p.contains(p1));
    Assert.assertTrue(p.contains(p2));
    Assert.assertTrue(! p.contains(p3));

    p = p.rotate(p2, new Rotation(oldNormal, 0.1));
    Assert.assertTrue(! p.contains(p1));
    Assert.assertTrue(p.contains(p2));
    Assert.assertTrue(! p.contains(p3));

    p = p.rotate(p1, new Rotation(oldNormal, 0.1));
    Assert.assertTrue(! p.contains(p1));
    Assert.assertTrue(! p.contains(p2));
    Assert.assertTrue(! p.contains(p3));

}
 
Example #3
Source File: QuaternionTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public final void testPolarForm() {
    final Random r = new Random(48);
    final int numberOfTrials = 1000;
    for (int i = 0; i < numberOfTrials; i++) {
        final Quaternion q = new Quaternion(2 * (r.nextDouble() - 0.5), 2 * (r.nextDouble() - 0.5),
                                            2 * (r.nextDouble() - 0.5), 2 * (r.nextDouble() - 0.5));
        final Quaternion qP = q.getPositivePolarForm();

        Assert.assertTrue(qP.isUnitQuaternion(COMPARISON_EPS));
        Assert.assertTrue(qP.getQ0() >= 0);

        final Rotation rot = new Rotation(q.getQ0(), q.getQ1(), q.getQ2(), q.getQ3(), true);
        final Rotation rotP = new Rotation(qP.getQ0(), qP.getQ1(), qP.getQ2(), qP.getQ3(), true);

        Assert.assertEquals(rot.getAngle(), rotP.getAngle(), COMPARISON_EPS);
        Assert.assertEquals(rot.getAxis().getX(), rot.getAxis().getX(), COMPARISON_EPS);
        Assert.assertEquals(rot.getAxis().getY(), rot.getAxis().getY(), COMPARISON_EPS);
        Assert.assertEquals(rot.getAxis().getZ(), rot.getAxis().getZ(), COMPARISON_EPS);
    }
}
 
Example #4
Source File: PlaneTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testRotate() {
    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);
    Vector3D oldNormal = p.getNormal();

    p = p.rotate(p2, new Rotation(p2.subtract(p1), 1.7));
    Assert.assertTrue(p.contains(p1));
    Assert.assertTrue(p.contains(p2));
    Assert.assertTrue(! p.contains(p3));

    p = p.rotate(p2, new Rotation(oldNormal, 0.1));
    Assert.assertTrue(! p.contains(p1));
    Assert.assertTrue(p.contains(p2));
    Assert.assertTrue(! p.contains(p3));

    p = p.rotate(p1, new Rotation(oldNormal, 0.1));
    Assert.assertTrue(! p.contains(p1));
    Assert.assertTrue(! p.contains(p2));
    Assert.assertTrue(! p.contains(p3));

}
 
Example #5
Source File: BWRigidBody.java    From NOVA-Core with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 #6
Source File: PlaneTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testRotate() throws MathArithmeticException, MathIllegalArgumentException {
    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);
    Vector3D oldNormal = p.getNormal();

    p = p.rotate(p2, new Rotation(p2.subtract(p1), 1.7));
    Assert.assertTrue(p.contains(p1));
    Assert.assertTrue(p.contains(p2));
    Assert.assertTrue(! p.contains(p3));

    p = p.rotate(p2, new Rotation(oldNormal, 0.1));
    Assert.assertTrue(! p.contains(p1));
    Assert.assertTrue(p.contains(p2));
    Assert.assertTrue(! p.contains(p3));

    p = p.rotate(p1, new Rotation(oldNormal, 0.1));
    Assert.assertTrue(! p.contains(p1));
    Assert.assertTrue(! p.contains(p2));
    Assert.assertTrue(! p.contains(p3));

}
 
Example #7
Source File: QuaternionTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public final void testPolarForm() {
    final Random r = new Random(48);
    final int numberOfTrials = 1000;
    for (int i = 0; i < numberOfTrials; i++) {
        final Quaternion q = new Quaternion(2 * (r.nextDouble() - 0.5), 2 * (r.nextDouble() - 0.5),
                                            2 * (r.nextDouble() - 0.5), 2 * (r.nextDouble() - 0.5));
        final Quaternion qP = q.getPositivePolarForm();

        Assert.assertTrue(qP.isUnitQuaternion(COMPARISON_EPS));
        Assert.assertTrue(qP.getQ0() >= 0);

        final Rotation rot = new Rotation(q.getQ0(), q.getQ1(), q.getQ2(), q.getQ3(), true);
        final Rotation rotP = new Rotation(qP.getQ0(), qP.getQ1(), qP.getQ2(), qP.getQ3(), true);

        Assert.assertEquals(rot.getAngle(), rotP.getAngle(), COMPARISON_EPS);
        Assert.assertEquals(rot.getAxis().getX(), rot.getAxis().getX(), COMPARISON_EPS);
        Assert.assertEquals(rot.getAxis().getY(), rot.getAxis().getY(), COMPARISON_EPS);
        Assert.assertEquals(rot.getAxis().getZ(), rot.getAxis().getZ(), COMPARISON_EPS);
    }
}
 
Example #8
Source File: QuaternionTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public final void testPolarForm() {
    final Random r = new Random(48);
    final int numberOfTrials = 1000;
    for (int i = 0; i < numberOfTrials; i++) {
        final Quaternion q = new Quaternion(2 * (r.nextDouble() - 0.5), 2 * (r.nextDouble() - 0.5),
                                            2 * (r.nextDouble() - 0.5), 2 * (r.nextDouble() - 0.5));
        final Quaternion qP = q.getPositivePolarForm();

        Assert.assertTrue(qP.isUnitQuaternion(COMPARISON_EPS));
        Assert.assertTrue(qP.getQ0() >= 0);

        final Rotation rot = new Rotation(q.getQ0(), q.getQ1(), q.getQ2(), q.getQ3(), true);
        final Rotation rotP = new Rotation(qP.getQ0(), qP.getQ1(), qP.getQ2(), qP.getQ3(), true);

        Assert.assertEquals(rot.getAngle(), rotP.getAngle(), COMPARISON_EPS);
        Assert.assertEquals(rot.getAxis().getX(), rot.getAxis().getX(), COMPARISON_EPS);
        Assert.assertEquals(rot.getAxis().getY(), rot.getAxis().getY(), COMPARISON_EPS);
        Assert.assertEquals(rot.getAxis().getZ(), rot.getAxis().getZ(), COMPARISON_EPS);
    }
}
 
Example #9
Source File: PlaneTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testRotate() {
    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);
    Vector3D oldNormal = p.getNormal();

    p = p.rotate(p2, new Rotation(p2.subtract(p1), 1.7));
    Assert.assertTrue(p.contains(p1));
    Assert.assertTrue(p.contains(p2));
    Assert.assertTrue(! p.contains(p3));

    p = p.rotate(p2, new Rotation(oldNormal, 0.1));
    Assert.assertTrue(! p.contains(p1));
    Assert.assertTrue(p.contains(p2));
    Assert.assertTrue(! p.contains(p3));

    p = p.rotate(p1, new Rotation(oldNormal, 0.1));
    Assert.assertTrue(! p.contains(p1));
    Assert.assertTrue(! p.contains(p2));
    Assert.assertTrue(! p.contains(p3));

}
 
Example #10
Source File: PlaneTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testRotate() throws MathArithmeticException, MathIllegalArgumentException {
    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, 1.0e-10);
    Vector3D oldNormal = p.getNormal();

    p = p.rotate(p2, new Rotation(p2.subtract(p1), 1.7));
    Assert.assertTrue(p.contains(p1));
    Assert.assertTrue(p.contains(p2));
    Assert.assertTrue(! p.contains(p3));

    p = p.rotate(p2, new Rotation(oldNormal, 0.1));
    Assert.assertTrue(! p.contains(p1));
    Assert.assertTrue(p.contains(p2));
    Assert.assertTrue(! p.contains(p3));

    p = p.rotate(p1, new Rotation(oldNormal, 0.1));
    Assert.assertTrue(! p.contains(p1));
    Assert.assertTrue(! p.contains(p2));
    Assert.assertTrue(! p.contains(p3));

}
 
Example #11
Source File: PlaneTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testRotate() throws MathArithmeticException, MathIllegalArgumentException {
    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);
    Vector3D oldNormal = p.getNormal();

    p = p.rotate(p2, new Rotation(p2.subtract(p1), 1.7));
    Assert.assertTrue(p.contains(p1));
    Assert.assertTrue(p.contains(p2));
    Assert.assertTrue(! p.contains(p3));

    p = p.rotate(p2, new Rotation(oldNormal, 0.1));
    Assert.assertTrue(! p.contains(p1));
    Assert.assertTrue(p.contains(p2));
    Assert.assertTrue(! p.contains(p3));

    p = p.rotate(p1, new Rotation(oldNormal, 0.1));
    Assert.assertTrue(! p.contains(p1));
    Assert.assertTrue(! p.contains(p2));
    Assert.assertTrue(! p.contains(p3));

}
 
Example #12
Source File: QuaternionTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public final void testPolarForm() {
    final Random r = new Random(48);
    final int numberOfTrials = 1000;
    for (int i = 0; i < numberOfTrials; i++) {
        final Quaternion q = new Quaternion(2 * (r.nextDouble() - 0.5), 2 * (r.nextDouble() - 0.5),
                                            2 * (r.nextDouble() - 0.5), 2 * (r.nextDouble() - 0.5));
        final Quaternion qP = q.getPositivePolarForm();

        Assert.assertTrue(qP.isUnitQuaternion(COMPARISON_EPS));
        Assert.assertTrue(qP.getQ0() >= 0);

        final Rotation rot = new Rotation(q.getQ0(), q.getQ1(), q.getQ2(), q.getQ3(), true);
        final Rotation rotP = new Rotation(qP.getQ0(), qP.getQ1(), qP.getQ2(), qP.getQ3(), true);

        Assert.assertEquals(rot.getAngle(), rotP.getAngle(), COMPARISON_EPS);
        Assert.assertEquals(rot.getAxis().getX(), rot.getAxis().getX(), COMPARISON_EPS);
        Assert.assertEquals(rot.getAxis().getY(), rot.getAxis().getY(), COMPARISON_EPS);
        Assert.assertEquals(rot.getAxis().getZ(), rot.getAxis().getZ(), COMPARISON_EPS);
    }
}
 
Example #13
Source File: QuaternionTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public final void testPolarForm() {
    final Random r = new Random(48);
    final int numberOfTrials = 1000;
    for (int i = 0; i < numberOfTrials; i++) {
        final Quaternion q = new Quaternion(2 * (r.nextDouble() - 0.5), 2 * (r.nextDouble() - 0.5),
                                            2 * (r.nextDouble() - 0.5), 2 * (r.nextDouble() - 0.5));
        final Quaternion qP = q.getPositivePolarForm();

        Assert.assertTrue(qP.isUnitQuaternion(COMPARISON_EPS));
        Assert.assertTrue(qP.getQ0() >= 0);

        final Rotation rot = new Rotation(q.getQ0(), q.getQ1(), q.getQ2(), q.getQ3(), true);
        final Rotation rotP = new Rotation(qP.getQ0(), qP.getQ1(), qP.getQ2(), qP.getQ3(), true);

        Assert.assertEquals(rot.getAngle(), rotP.getAngle(), COMPARISON_EPS);
        Assert.assertEquals(rot.getAxis().getX(), rot.getAxis().getX(), COMPARISON_EPS);
        Assert.assertEquals(rot.getAxis().getY(), rot.getAxis().getY(), COMPARISON_EPS);
        Assert.assertEquals(rot.getAxis().getZ(), rot.getAxis().getZ(), COMPARISON_EPS);
    }
}
 
Example #14
Source File: BWRigidBody.java    From NOVA-Core with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 #15
Source File: RotationUtil.java    From NOVA-Core with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Returns the slerp interpolation of Rotations {@code a} and {@code b}, at
 * time {@code t}.
 * <p>
 * {@code t} should range in {@code [0,1]}. Result is a when {@code t=0 } and
 * {@code b} when {@code t=1}.
 * <p>
 * When {@code allowFlip} is true (default) the slerp interpolation will
 * always use the "shortest path" between the Rotations' orientations, by
 * "flipping" the source Rotation if needed.
 * @param a the first Rotation
 * @param b the second Rotation
 * @param t the temporal interpolation parameter
 * @param allowFlip tells whether or not the interpolation allows axis flip
 * @return The slerp interpolation of Rotations {@code a} and {@code b}, at time {@code t}.
 */
public static Rotation slerp(Rotation a, Rotation b, double t, boolean allowFlip) {
	// TODO: this method should not normalize the Rotation
	double cosAngle = dotProduct(a, b);

	double c1, c2;
	// Linear interpolation for close orientations
	if ((1.0 - FastMath.abs(cosAngle)) < 0.01) {
		c1 = 1.0f - t;
		c2 = t;
	} else {
		// Spherical interpolation
		double angle = FastMath.acos(FastMath.abs(cosAngle));
		double sinAngle = FastMath.sin(angle);
		c1 = FastMath.sin(angle * (1.0f - t)) / sinAngle;
		c2 = FastMath.sin(angle * t) / sinAngle;
	}

	// Use the shortest path
	if (allowFlip && (cosAngle < 0.0)) {
		c1 = -c1;
	}

	return new Rotation(c1 * a.getQ1() + c2 * b.getQ1(), c1 * a.getQ2() + c2 * b.getQ2(), c1 * a.getQ3()
		+ c2 * b.getQ3(), c1 * a.getQ0() + c2 * b.getQ0(), false);
}
 
Example #16
Source File: BWRigidBody.java    From NOVA-Core with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 #17
Source File: PlaneTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testRotate() throws MathArithmeticException, MathIllegalArgumentException {
    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, 1.0e-10);
    Vector3D oldNormal = p.getNormal();

    p = p.rotate(p2, new Rotation(p2.subtract(p1), 1.7));
    Assert.assertTrue(p.contains(p1));
    Assert.assertTrue(p.contains(p2));
    Assert.assertTrue(! p.contains(p3));

    p = p.rotate(p2, new Rotation(oldNormal, 0.1));
    Assert.assertTrue(! p.contains(p1));
    Assert.assertTrue(p.contains(p2));
    Assert.assertTrue(! p.contains(p3));

    p = p.rotate(p1, new Rotation(oldNormal, 0.1));
    Assert.assertTrue(! p.contains(p1));
    Assert.assertTrue(! p.contains(p2));
    Assert.assertTrue(! p.contains(p3));

}
 
Example #18
Source File: QuaternionTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
@Test
public final void testPolarForm() {
    final Random r = new Random(48);
    final int numberOfTrials = 1000;
    for (int i = 0; i < numberOfTrials; i++) {
        final Quaternion q = new Quaternion(2 * (r.nextDouble() - 0.5), 2 * (r.nextDouble() - 0.5),
                                            2 * (r.nextDouble() - 0.5), 2 * (r.nextDouble() - 0.5));
        final Quaternion qP = q.getPositivePolarForm();

        Assert.assertTrue(qP.isUnitQuaternion(COMPARISON_EPS));
        Assert.assertTrue(qP.getQ0() >= 0);

        final Rotation rot = new Rotation(q.getQ0(), q.getQ1(), q.getQ2(), q.getQ3(), true);
        final Rotation rotP = new Rotation(qP.getQ0(), qP.getQ1(), qP.getQ2(), qP.getQ3(), true);

        Assert.assertEquals(rot.getAngle(), rotP.getAngle(), COMPARISON_EPS);
        Assert.assertEquals(rot.getAxis().getX(), rot.getAxis().getX(), COMPARISON_EPS);
        Assert.assertEquals(rot.getAxis().getY(), rot.getAxis().getY(), COMPARISON_EPS);
        Assert.assertEquals(rot.getAxis().getZ(), rot.getAxis().getZ(), COMPARISON_EPS);
    }
}
 
Example #19
Source File: RayTraceTest.java    From NOVA-Core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test
public void testRayTraceEntity() {
	fakeWorld.setBlock(new Vector3D(5, 5, 5), RayTraceMod.solid);

	Entity entity = fakeWorld.addEntity(RayTraceMod.testEntity);
	entity.setPosition(new Vector3D(5.1, 0, 5.1));
	entity.setRotation(new Rotation(RotationUtil.DEFAULT_ORDER, 0, Math.PI / 2, 0));

	RayTracer rayTracer = new RayTracer(entity).setDistance(10);
	List<RayTracer.RayTraceBlockResult> rayTraceBlockResults = rayTracer.rayTraceBlocks(fakeWorld).collect(Collectors.toList());
	assertThat(rayTraceBlockResults.size()).isEqualTo(1);
}
 
Example #20
Source File: SphericalPolygonsSetTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private SubCircle create(Vector3D pole, Vector3D x, Vector3D y,
                         double tolerance, double ... limits) {
    RegionFactory<Sphere1D> factory = new RegionFactory<Sphere1D>();
    Circle circle = new Circle(pole, tolerance);
    Circle phased =
            (Circle) Circle.getTransform(new Rotation(circle.getXAxis(), circle.getYAxis(), x, y)).apply(circle);
    ArcsSet set = (ArcsSet) factory.getComplement(new ArcsSet(tolerance));
    for (int i = 0; i < limits.length; i += 2) {
        set = (ArcsSet) factory.union(set, new ArcsSet(limits[i], limits[i + 1], tolerance));
    }
    return new SubCircle(phased, set);
}
 
Example #21
Source File: CircleTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testTransform() {
    RandomGenerator random = new Well1024a(0x16992fc4294bf2f1l);
    UnitSphereRandomVectorGenerator sphRandom = new UnitSphereRandomVectorGenerator(3, random);
    for (int i = 0; i < 100; ++i) {

        Rotation r = new Rotation(new Vector3D(sphRandom.nextVector()),
                                  FastMath.PI * random.nextDouble());
        Transform<Sphere2D, Sphere1D> t = Circle.getTransform(r);

        S2Point  p = new S2Point(new Vector3D(sphRandom.nextVector()));
        S2Point tp = (S2Point) t.apply(p);
        Assert.assertEquals(0.0, r.applyTo(p.getVector()).distance(tp.getVector()), 1.0e-10);

        Circle  c = new Circle(new Vector3D(sphRandom.nextVector()), 1.0e-10);
        Circle tc = (Circle) t.apply(c);
        Assert.assertEquals(0.0, r.applyTo(c.getPole()).distance(tc.getPole()),   1.0e-10);
        Assert.assertEquals(0.0, r.applyTo(c.getXAxis()).distance(tc.getXAxis()), 1.0e-10);
        Assert.assertEquals(0.0, r.applyTo(c.getYAxis()).distance(tc.getYAxis()), 1.0e-10);
        Assert.assertEquals(c.getTolerance(), ((Circle) t.apply(c)).getTolerance(), 1.0e-10);

        SubLimitAngle  sub = new LimitAngle(new S1Point(MathUtils.TWO_PI * random.nextDouble()),
                                            random.nextBoolean(), 1.0e-10).wholeHyperplane();
        Vector3D psub = c.getPointAt(((LimitAngle) sub.getHyperplane()).getLocation().getAlpha());
        SubLimitAngle tsub = (SubLimitAngle) t.apply(sub, c, tc);
        Vector3D ptsub = tc.getPointAt(((LimitAngle) tsub.getHyperplane()).getLocation().getAlpha());
        Assert.assertEquals(0.0, r.applyTo(psub).distance(ptsub), 1.0e-10);

    }
}
 
Example #22
Source File: SubCircleTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private SubCircle create(Vector3D pole, Vector3D x, Vector3D y,
                         double tolerance, double ... limits) {
    RegionFactory<Sphere1D> factory = new RegionFactory<Sphere1D>();
    Circle circle = new Circle(pole, tolerance);
    Circle phased =
            (Circle) Circle.getTransform(new Rotation(circle.getXAxis(), circle.getYAxis(), x, y)).apply(circle);
    ArcsSet set = (ArcsSet) factory.getComplement(new ArcsSet(tolerance));
    for (int i = 0; i < limits.length; i += 2) {
        set = (ArcsSet) factory.union(set, new ArcsSet(limits[i], limits[i + 1], tolerance));
    }
    return new SubCircle(phased, set);
}
 
Example #23
Source File: SphericalPolygonsSet.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Build the vertices representing a regular polygon.
 * @param center center of the polygon (the center is in the inside half)
 * @param meridian point defining the reference meridian for first polygon vertex
 * @param outsideRadius distance of the vertices to the center
 * @param n number of sides of the polygon
 * @return vertices array
 */
private static S2Point[] createRegularPolygonVertices(final Vector3D center, final Vector3D meridian,
                                                      final double outsideRadius, final int n) {
    final S2Point[] array = new S2Point[n];
    final Rotation r0 = new Rotation(Vector3D.crossProduct(center, meridian), outsideRadius);
    array[0] = new S2Point(r0.applyTo(center));

    final Rotation r = new Rotation(center, MathUtils.TWO_PI / n);
    for (int i = 1; i < n; ++i) {
        array[i] = new S2Point(r.applyTo(array[i - 1].getVector()));
    }

    return array;
}
 
Example #24
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 #25
Source File: MatrixStack.java    From NOVA-Core with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Rotates the current matrix
 *
 * @param rotation The rotation to aply
 * @return The rorated matrix
 */
public MatrixStack rotate(Rotation rotation) {
	RealMatrix rotMat = MatrixUtils.createRealMatrix(4, 4);
	rotMat.setSubMatrix(rotation.getMatrix(), 0, 0);
	rotMat.setEntry(3, 3, 1);
	current = current.preMultiply(rotMat);
	return this;
}
 
Example #26
Source File: SphericalPolygonsSet.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** Build the vertices representing a regular polygon.
 * @param center center of the polygon (the center is in the inside half)
 * @param meridian point defining the reference meridian for first polygon vertex
 * @param outsideRadius distance of the vertices to the center
 * @param n number of sides of the polygon
 * @return vertices array
 */
private static S2Point[] createRegularPolygonVertices(final Vector3D center, final Vector3D meridian,
                                                      final double outsideRadius, final int n) {
    final S2Point[] array = new S2Point[n];
    final Rotation r0 = new Rotation(Vector3D.crossProduct(center, meridian), outsideRadius);
    array[0] = new S2Point(r0.applyTo(center));

    final Rotation r = new Rotation(center, MathUtils.TWO_PI / n);
    for (int i = 1; i < n; ++i) {
        array[i] = new S2Point(r.applyTo(array[i - 1].getVector()));
    }

    return array;
}
 
Example #27
Source File: SubCircleTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private SubCircle create(Vector3D pole, Vector3D x, Vector3D y,
                         double tolerance, double ... limits) {
    RegionFactory<Sphere1D> factory = new RegionFactory<Sphere1D>();
    Circle circle = new Circle(pole, tolerance);
    Circle phased =
            (Circle) Circle.getTransform(new Rotation(circle.getXAxis(), circle.getYAxis(), x, y)).apply(circle);
    ArcsSet set = (ArcsSet) factory.getComplement(new ArcsSet(tolerance));
    for (int i = 0; i < limits.length; i += 2) {
        set = (ArcsSet) factory.union(set, new ArcsSet(limits[i], limits[i + 1], tolerance));
    }
    return new SubCircle(phased, set);
}
 
Example #28
Source File: CircleTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void testTransform() {
    RandomGenerator random = new Well1024a(0x16992fc4294bf2f1l);
    UnitSphereRandomVectorGenerator sphRandom = new UnitSphereRandomVectorGenerator(3, random);
    for (int i = 0; i < 100; ++i) {

        Rotation r = new Rotation(new Vector3D(sphRandom.nextVector()),
                                  FastMath.PI * random.nextDouble());
        Transform<Sphere2D, Sphere1D> t = Circle.getTransform(r);

        S2Point  p = new S2Point(new Vector3D(sphRandom.nextVector()));
        S2Point tp = (S2Point) t.apply(p);
        Assert.assertEquals(0.0, r.applyTo(p.getVector()).distance(tp.getVector()), 1.0e-10);

        Circle  c = new Circle(new Vector3D(sphRandom.nextVector()), 1.0e-10);
        Circle tc = (Circle) t.apply(c);
        Assert.assertEquals(0.0, r.applyTo(c.getPole()).distance(tc.getPole()),   1.0e-10);
        Assert.assertEquals(0.0, r.applyTo(c.getXAxis()).distance(tc.getXAxis()), 1.0e-10);
        Assert.assertEquals(0.0, r.applyTo(c.getYAxis()).distance(tc.getYAxis()), 1.0e-10);
        Assert.assertEquals(c.getTolerance(), ((Circle) t.apply(c)).getTolerance(), 1.0e-10);

        SubLimitAngle  sub = new LimitAngle(new S1Point(MathUtils.TWO_PI * random.nextDouble()),
                                            random.nextBoolean(), 1.0e-10).wholeHyperplane();
        Vector3D psub = c.getPointAt(((LimitAngle) sub.getHyperplane()).getLocation().getAlpha());
        SubLimitAngle tsub = (SubLimitAngle) t.apply(sub, c, tc);
        Vector3D ptsub = tc.getPointAt(((LimitAngle) tsub.getHyperplane()).getLocation().getAlpha());
        Assert.assertEquals(0.0, r.applyTo(psub).distance(ptsub), 1.0e-10);

    }
}
 
Example #29
Source File: SphericalPolygonsSetTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
private SubCircle create(Vector3D pole, Vector3D x, Vector3D y,
                         double tolerance, double ... limits) {
    RegionFactory<Sphere1D> factory = new RegionFactory<Sphere1D>();
    Circle circle = new Circle(pole, tolerance);
    Circle phased =
            (Circle) Circle.getTransform(new Rotation(circle.getXAxis(), circle.getYAxis(), x, y)).apply(circle);
    ArcsSet set = (ArcsSet) factory.getComplement(new ArcsSet(tolerance));
    for (int i = 0; i < limits.length; i += 2) {
        set = (ArcsSet) factory.union(set, new ArcsSet(limits[i], limits[i + 1], tolerance));
    }
    return new SubCircle(phased, set);
}
 
Example #30
Source File: MCEntityTransform.java    From NOVA-Core with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void setRotation(Rotation rotation) {
	double[] euler = rotation.getAngles(RotationUtil.DEFAULT_ORDER);
	wrapper.rotationYaw = (float) Math.toDegrees(euler[0]);
	wrapper.rotationPitch = (float) Math.toDegrees(euler[1]);
}