/** * Initializes a set of {@link Spherical} coordinates from the provided set of {@link Cartesian} coordinates. * <p> The radius and magnitude for spherical coordinates are computed using the standard methods. Note that if a component of the cartesian components underflows upon squaring the resulting spherical coordinates may not be correct. * @param coordinates The set of Cartesian coordinates. */ public Spherical(@Nonnull Cartesian coordinates) { double x = coordinates.getX(); double y = coordinates.getY(); double z = coordinates.getZ(); double radialSquared = x * x + y * y; m_clock = Math.atan2(y, x); m_cone = Math.atan2(Math.sqrt(radialSquared), z); m_magnitude = Math.sqrt(radialSquared + z * z); }
/** * 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); }
/** * Forms a diagonal matrix from the input vector. * @param vector The vector. * @return The diagonal matrix */ @Nonnull public static Matrix3By3 diagonalMatrix(@Nonnull Cartesian vector) { return diagonalMatrix(vector.getX(), vector.getY(), vector.getZ()); }
/** * Forms the cross product of the specified set of {@link Cartesian} coordinates with this instance. * @param other The set of {@link Cartesian} coordinates to cross with this instance. * @return A set of {@link Cartesian} coordinates that represents the result of the product. */ @CS2JWarning("Unhandled attribute removed: Pure") @Nonnull public final Cartesian cross(@Nonnull Cartesian other) { return new Cartesian(m_y * other.getZ() - m_z * other.getY(), m_z * other.getX() - m_x * other.getZ(), m_x * other.getY() - m_y * other.getX()); }
/** * Forms the dot product of the specified set of {@link Cartesian} coordinates with this instance. * @param other The set of {@link Cartesian} coordinates to dot with this instance. * @return A {@code double} that represents the result of the product. */ @CS2JWarning("Unhandled attribute removed: Pure") public final double dot(@Nonnull Cartesian other) { return m_x * other.getX() + m_y * other.getY() + m_z * other.getZ(); }
/** * 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()); }
/** * Subtracts the specified set of {@link Cartesian} coordinates from this instance. * @param other The subtrahend, or value which is to be subtracted from this instance. * @return A set of {@link Cartesian} coordinates that represents the result of the subtraction. */ @CS2JWarning("Unhandled attribute removed: Pure") @Nonnull public final Cartesian subtract(@Nonnull Cartesian other) { return new Cartesian(m_x - other.getX(), m_y - other.getY(), m_z - other.getZ()); }
/** * Adds the specified set of {@link Cartesian} coordinates to this instance. * @param other The addend, or value which is to be added to this instance. * @return A set of {@link Cartesian} coordinates that represents the result of the addition. */ @CS2JWarning("Unhandled attribute removed: Pure") @Nonnull public final Cartesian add(@Nonnull Cartesian other) { return new Cartesian(m_x + other.getX(), m_y + other.getY(), m_z + other.getZ()); }
/** * Writes a {@link Cartesian} value as an array in X, Y, Z order. * @param output The stream to which to write the value. * @param value The value to write. */ public static void writeCartesian3(CesiumOutputStream output, @Nonnull Cartesian value) { output.writeStartSequence(); output.writeValue(value.getX()); output.writeValue(value.getY()); output.writeValue(value.getZ()); output.writeEndSequence(); }
/** * Writes a list of {@link Cartesian} values as an array in X, Y, Z order. * @param output The stream to which to write the value. * @param values The values to write. */ public static void writeCartesian3List(CesiumOutputStream output, Iterable<Cartesian> values) { output.writeStartSequence(); for (final Cartesian value : values) { output.writeValue(value.getX()); output.writeValue(value.getY()); output.writeValue(value.getZ()); } output.writeEndSequence(); }
/** * Writes a {@link Motion1} value as an array in X, Y, Z, vX, vY, vZ order. * @param output The stream to which to write the value. * @param value The value to write. */ public static void writeCartesian3Velocity(CesiumOutputStream output, @Nonnull Motion1<Cartesian> value) { output.writeStartSequence(); output.writeValue(value.getValue().getX()); output.writeValue(value.getValue().getY()); output.writeValue(value.getValue().getZ()); output.writeValue(value.getFirstDerivative().getX()); output.writeValue(value.getFirstDerivative().getY()); output.writeValue(value.getFirstDerivative().getZ()); output.writeEndSequence(); }
/** * Tests that initialization of and access to the type's values works correctly. */ @Test public final void testHoldValue() { Cartesian test = new Cartesian(1.0, 2.0, 3.0); Assert.assertEquals(1.0, test.getX(), 0d); Assert.assertEquals(2.0, test.getY(), 0d); Assert.assertEquals(3.0, test.getZ(), 0d); }
private final void _TestFromMatrix3By3(double angle, @Nonnull Cartesian axis) { Cartesian unit = Cartesian.toCartesian(axis.normalize()); double c = Math.cos(angle); double s = Math.sin(angle); double w = c; double x = s * unit.getX(); double y = s * unit.getY(); double z = s * unit.getZ(); UnitQuaternion quaternion = new UnitQuaternion(w, x, y, z); Matrix3By3 matrix = new Matrix3By3(quaternion); UnitQuaternion test = new UnitQuaternion(matrix); Assert.assertEquals(w, quaternion.getW(), Constants.Epsilon15); Assert.assertEquals(x, quaternion.getX(), Constants.Epsilon15); Assert.assertEquals(y, quaternion.getY(), Constants.Epsilon15); Assert.assertEquals(z, quaternion.getZ(), Constants.Epsilon15); }
/** * Tests the multiplication methods and operators. */ @Test public final void testMultiply() { UnitCartesian original = new UnitCartesian(2.0, 3.0, 6.0); Cartesian multiplied = UnitCartesian.multiply(original, 7.0); Assert.assertEquals(2.0, multiplied.getX(), 0d); Assert.assertEquals(3.0, multiplied.getY(), 0d); Assert.assertEquals(6.0, multiplied.getZ(), 0d); multiplied = UnitCartesian.multiply(7.0, original); Assert.assertEquals(2.0, multiplied.getX(), 0d); Assert.assertEquals(3.0, multiplied.getY(), 0d); Assert.assertEquals(6.0, multiplied.getZ(), 0d); }
/** * Tests the multiplication methods and operators. */ @Test public final void testDivide() { Cartesian original = new Cartesian(2.0, 4.0, 6.0); Cartesian result = Cartesian.divide(original, 2.0); Assert.assertEquals(1.0, result.getX(), 0d); Assert.assertEquals(2.0, result.getY(), 0d); Assert.assertEquals(3.0, result.getZ(), 0d); result = original.divide(2.0); Assert.assertEquals(1.0, result.getX(), 0d); Assert.assertEquals(2.0, result.getY(), 0d); Assert.assertEquals(3.0, result.getZ(), 0d); }
/** * Tests the multiplication methods and operators. */ @Test public final void testDivide() { UnitCartesian original = new UnitCartesian(2.0, 3.0, 6.0); Cartesian result = UnitCartesian.divide(original, 2.0); Assert.assertEquals(2.0 / 14.0, result.getX(), 0d); Assert.assertEquals(3.0 / 14.0, result.getY(), 0d); Assert.assertEquals(6.0 / 14.0, result.getZ(), 0d); result = original.divide(2.0); Assert.assertEquals(2.0 / 14.0, result.getX(), 0d); Assert.assertEquals(3.0 / 14.0, result.getY(), 0d); Assert.assertEquals(6.0 / 14.0, result.getZ(), 0d); }
/** * Tests negation of a set of coordinates. */ @Test public final void testNegation() { Cartesian c = Cartesian.negate(new Cartesian(1.0, 2.0, 3.0)); Assert.assertEquals(-1.0, c.getX(), 0d); Assert.assertEquals(-2.0, c.getY(), 0d); Assert.assertEquals(-3.0, c.getZ(), 0d); }
/** * Tests the addition methods and operators. */ @Test public final void testAdd() { Cartesian original = new Cartesian(10.0, 20.0, 30.0); Cartesian toAdd = new Cartesian(1.0, 2.0, 3.0); Cartesian result = Cartesian.add(original, toAdd); Assert.assertEquals(11.0, result.getX(), 0d); Assert.assertEquals(22.0, result.getY(), 0d); Assert.assertEquals(33.0, result.getZ(), 0d); result = original.add(toAdd); Assert.assertEquals(11.0, result.getX(), 0d); Assert.assertEquals(22.0, result.getY(), 0d); Assert.assertEquals(33.0, result.getZ(), 0d); }
/** * Tests the subtraction methods and operators. */ @Test public final void testSubtract() { Cartesian original = new Cartesian(10.0, 20.0, 30.0); Cartesian toSubtract = new Cartesian(1.0, 2.0, 3.0); Cartesian result = Cartesian.subtract(original, toSubtract); Assert.assertEquals(9.0, result.getX(), 0d); Assert.assertEquals(18.0, result.getY(), 0d); Assert.assertEquals(27.0, result.getZ(), 0d); result = original.subtract(toSubtract); Assert.assertEquals(9.0, result.getX(), 0d); Assert.assertEquals(18.0, result.getY(), 0d); Assert.assertEquals(27.0, result.getZ(), 0d); }
/** * Tests implicit conversion from {@link UnitCartesian} coordinates. */ @Test public final void testConversionFromUnitCartesian() { UnitCartesian unit = new UnitCartesian(1.0, 1.0, 1.0); Cartesian test = Cartesian.toCartesian(unit); Assert.assertEquals(unit.getX(), test.getX(), 0d); Assert.assertEquals(unit.getY(), test.getY(), 0d); Assert.assertEquals(unit.getZ(), test.getZ(), 0d); }