/** * Forms a new Cartesian vector as the product of this 3-by-3 matrix and the provided Cartesian vector. * @param vector The vector. * @return The resulting Cartesian vector. */ @CS2JWarning("Unhandled attribute removed: Pure") @Nonnull public final Cartesian multiply(@Nonnull Cartesian vector) { return new Cartesian(m_m11 * vector.getX() + m_m12 * vector.getY() + m_m13 * vector.getZ(), m_m21 * vector.getX() + m_m22 * vector.getY() + m_m23 * vector.getZ(), m_m31 * vector.getX() + m_m32 * vector.getY() + m_m33 * vector.getZ()); }
/** * Adds a specified set of {@link Cartesian} coordinates to another specified set of {@link Cartesian} coordinates. * @param left The augend, or value to which {@code right} is to be added. * @param right The addend, or value which is to be added to {@code left}. * @return A set of {@link Cartesian} coordinates that represents the result of the addition. */ @CS2JInfo("This method implements the functionality of the overloaded operator: 'Cartesian +(Cartesian,Cartesian)'") @Nonnull public static Cartesian add(@Nonnull Cartesian left, @Nonnull Cartesian right) { return left.add(right); }
/** * Divides a specified set of {@link Cartesian} coordinates by a scalar. * @param left The dividend, or value which is to be divided by {@code right}. * @param right The divisor, or value which is to divide {@code left}. * @return A set of {@link Cartesian} coordinates that represents the result of the division. */ @CS2JInfo("This method implements the functionality of the overloaded operator: 'Cartesian /(Cartesian,System.Double)'") @Nonnull public static Cartesian divide(@Nonnull Cartesian left, double right) { return left.divide(right); }
/** * Initializes a set of {@link UnitCartesian} coordinates from the provided set of {@link Cartesian} coordinates. * @param coordinates The set of {@link Cartesian} coordinates. * @exception ArithmeticException The magnitude of the provided coordinates must not be zero. * @exception ArithmeticException The magnitude of the provided coordinates must not be infinite. */ public UnitCartesian(@Nonnull Cartesian coordinates) { this(coordinates.getX(), coordinates.getY(), coordinates.getZ(), Normalization.UNNORMALIZED); }
/** * Subtracts a specified set of {@link UnitCartesian} coordinates from a specified set of {@link Cartesian} coordinates. * @param left The minuend, or value from which {@code right} is to be subtracted. * @param right The subtrahend, or value which is to be subtracted from {@code left}. * @return A set of {@link Cartesian} coordinates that represents the result of the subtraction. */ @CS2JInfo("This method implements the functionality of the overloaded operator: 'Cartesian -(Cartesian,UnitCartesian)'") @Nonnull public static Cartesian subtract(@Nonnull Cartesian left, @Nonnull UnitCartesian right) { return left.subtract(Cartesian.toCartesian(right)); }
/** * Tests rotation by a {@link UnitQuaternion}. */ @Test public final void testRotateByUnitQuaternion() { double angle = Math.PI / 3.0; // half angle of 120 degree rotation double cos = Math.cos(angle); double sin = Math.sin(angle); Cartesian axis = Cartesian.toCartesian((new Cartesian(1.0, 1.0, 1.0)).normalize()); // unit vector along [1,1,1] double w = cos; double x = sin * axis.getX(); double y = sin * axis.getY(); double z = sin * axis.getZ(); // The original vector is along the x-axis. Cartesian original = new Cartesian(1.0, 0.0, 0.0); // The rotated vector is along the z-axis. Cartesian rotated = original.rotate(new UnitQuaternion(w, x, y, z)); Assert.assertEquals(0.0, rotated.getX(), Constants.Epsilon15); Assert.assertEquals(0.0, rotated.getY(), Constants.Epsilon15); Assert.assertEquals(1.0, rotated.getZ(), Constants.Epsilon15); }
/** * Multiplies this instance by a scalar. * @param scalar The multiplier, or value which is to multiply this instance. * @return A set of {@link Cartesian} coordinates that represents the result of the multiplication. */ @CS2JWarning("Unhandled attribute removed: Pure") @Nonnull public final Cartesian multiply(double scalar) { return new Cartesian(m_x * scalar, m_y * scalar, m_z * scalar); }
Cartesian first = new Cartesian(1.0, 2.0, 3.0); Cartesian second = new Cartesian(1.0, 2.0, 3.0); AssertHelper.assertEquals(first, second); AssertHelper.assertEquals(second, first); Assert.assertTrue(Cartesian.equals(first, second)); Assert.assertTrue(Cartesian.equals(second, first)); Assert.assertFalse(Cartesian.notEquals(first, second)); Assert.assertFalse(Cartesian.notEquals(second, first)); Assert.assertTrue(first.equalsType(second)); Assert.assertTrue(second.equalsType(first)); second = new Cartesian(0.0, 2.0, 3.0); AssertHelper.assertNotEqual(first, second); AssertHelper.assertNotEqual(second, first); Assert.assertFalse(Cartesian.equals(first, second)); Assert.assertFalse(Cartesian.equals(second, first)); Assert.assertTrue(Cartesian.notEquals(first, second)); Assert.assertTrue(Cartesian.notEquals(second, first)); Assert.assertFalse(first.equalsType(second)); Assert.assertFalse(second.equalsType(first)); second = new Cartesian(1.0, 0.0, 3.0); AssertHelper.assertNotEqual(first, second); AssertHelper.assertNotEqual(second, first); Assert.assertFalse(Cartesian.equals(first, second)); Assert.assertFalse(Cartesian.equals(second, first)); Assert.assertTrue(Cartesian.notEquals(first, second)); Assert.assertTrue(Cartesian.notEquals(second, first)); Assert.assertFalse(first.equalsType(second)); Assert.assertFalse(second.equalsType(first)); second = new Cartesian(1.0, 2.0, 0.0);
/** * Tests that normalization of a {@link Cartesian} with infinite magnitude produces an {@link ArithmeticException}. */ @Test public final void testNormalizeOfInfiniteMagnitude() { ExpectedExceptionHelper.expectException(getRule$expectedException(), ArithmeticException.class); Cartesian test = new Cartesian(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY); UnitCartesian unit = test.normalize(); }
/** * Tests the {@code IsUndefined} ({@link Cartesian#getIsUndefined get}) method. */ @Test public final void testIsUndefined() { Assert.assertFalse(new Cartesian(1.0, 1.0, 1.0).getIsUndefined()); Assert.assertTrue(Cartesian.getUndefined().getIsUndefined()); Assert.assertTrue(new Cartesian(Double.NaN, 1.0, 1.0).getIsUndefined()); Assert.assertTrue(new Cartesian(1.0, Double.NaN, 1.0).getIsUndefined()); Assert.assertTrue(new Cartesian(1.0, 1.0, Double.NaN).getIsUndefined()); }
/** * Tests math operators */ @Test public final void testMathOperatorsWithCartesian() { Matrix3By3 test = new Matrix3By3(1.0, 2.0, 4.0, 2.0, 3.0, 5.0, 4.0, 5.0, 6.0); Cartesian mult = new Cartesian(1D, 2D, 3D); Assert.assertTrue((new Cartesian(17D, 23D, 32D).equalsType(test.multiply(mult)))); Assert.assertTrue((new Cartesian(17D, 23D, 32D).equalsType(Matrix3By3.multiply(test, mult)))); }
/** * Tests the Dot method. */ @Test public final void testDotProduct() { UnitCartesian first = new UnitCartesian(1.0, 3.0, -2.0); UnitCartesian second = new UnitCartesian(4.0, -2.0, -1.0); Assert.assertEquals(0D, first.dot(Cartesian.toCartesian(second)), Constants.Epsilon15); Assert.assertEquals(0D, second.dot(Cartesian.toCartesian(first)), Constants.Epsilon15); Cartesian result = new Cartesian(4.0, -2.0, -1.0); Assert.assertEquals(0, first.dot(result), 0d); }
/** * Tests thats the {@link Cartesian#equalsEpsilon} method returns true when the difference is exactly epsilon. */ @Test public final void testEqualsEpsilonExact() { Cartesian first = new Cartesian(0.1, 0.1, 0.1); Cartesian second = new Cartesian(0.1, 0.1, 0.1); Assert.assertTrue(second.equalsEpsilon(first, 0D)); }
/** * Tests that GetHashCode returns something at least reasonably random. */ @Test public final void testGetHashCode() { Cartesian object1 = new Cartesian(1.0, 2.0, 3.0); Cartesian object2 = new Cartesian(1.0, 2.0, 3.0); Cartesian object3 = new Cartesian(1.0, 2.0, 3.1); Assert.assertEquals((int) object1.hashCode(), (int) object2.hashCode()); AssertHelper.assertNotEqual(object1.hashCode(), object3.hashCode()); }
/** * Tests the {@code Magnitude} ({@link Cartesian#getMagnitude get}) property. */ @Test public final void testMagnitude() { Cartesian test = new Cartesian(2.0, 3.0, 6.0); Assert.assertEquals(7.0, test.getMagnitude(), 0d); }
/** * Tests the {@code MostOrthogonalAxis} ({@link Cartesian#getMostOrthogonalAxis get}) method. */ @Test public final void testMostOrthogonalAxis() { Cartesian cartesian = new Cartesian(1.0, 2.0, 3.0); AssertHelper.assertEquals(UnitCartesian.getUnitX(), cartesian.getMostOrthogonalAxis()); cartesian = new Cartesian(2.0, 3.0, 1.0); AssertHelper.assertEquals(UnitCartesian.getUnitZ(), cartesian.getMostOrthogonalAxis()); cartesian = new Cartesian(3.0, 1.0, 2.0); AssertHelper.assertEquals(UnitCartesian.getUnitY(), cartesian.getMostOrthogonalAxis()); }
/** * Tests that normalization of a {@link Cartesian} with zero magnitude produces an {@link UnsupportedCaseException}. */ @Test public final void testNormalizeOfZeroMagnitude() { ExpectedExceptionHelper.expectException(getRule$expectedException(), ArithmeticException.class); Cartesian test = Cartesian.getZero(); UnitCartesian unit = test.normalize(); }
/** * Indicates whether another object is exactly equal to this instance. * @param obj The object to compare to this instance. * @return {@code true} if {@code obj} is an instance of this type and represents the same value as this instance; otherwise, {@code false}. */ @Override public boolean equals(Object obj) { return obj instanceof Cartesian && equalsType((Cartesian) obj); }