Vector3D.java

  1. /*
  2.  * Licensed to the Apache Software Foundation (ASF) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * The ASF licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *      https://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */

  17. /*
  18.  * This is not the original file distributed by the Apache Software Foundation
  19.  * It has been modified by the Hipparchus project
  20.  */

  21. package org.hipparchus.geometry.euclidean.threed;

  22. import org.hipparchus.exception.LocalizedCoreFormats;
  23. import org.hipparchus.exception.MathIllegalArgumentException;
  24. import org.hipparchus.exception.MathRuntimeException;
  25. import org.hipparchus.geometry.Space;
  26. import org.hipparchus.geometry.Vector;
  27. import org.hipparchus.util.FastMath;
  28. import org.hipparchus.util.MathArrays;
  29. import org.hipparchus.util.MathUtils;
  30. import org.hipparchus.util.SinCos;

  31. import java.io.Serializable;
  32. import java.text.NumberFormat;

  33. /**
  34.  * This class implements vectors in a three-dimensional space.
  35.  * <p>Instance of this class are guaranteed to be immutable.</p>
  36.  */
  37. public class Vector3D implements Serializable, Vector<Euclidean3D, Vector3D> {

  38.     /** Null vector (coordinates: 0, 0, 0). */
  39.     public static final Vector3D ZERO   = new Vector3D(0, 0, 0);

  40.     /** First canonical vector (coordinates: 1, 0, 0). */
  41.     public static final Vector3D PLUS_I = new Vector3D(1, 0, 0);

  42.     /** Opposite of the first canonical vector (coordinates: -1, 0, 0). */
  43.     public static final Vector3D MINUS_I = new Vector3D(-1, 0, 0);

  44.     /** Second canonical vector (coordinates: 0, 1, 0). */
  45.     public static final Vector3D PLUS_J = new Vector3D(0, 1, 0);

  46.     /** Opposite of the second canonical vector (coordinates: 0, -1, 0). */
  47.     public static final Vector3D MINUS_J = new Vector3D(0, -1, 0);

  48.     /** Third canonical vector (coordinates: 0, 0, 1). */
  49.     public static final Vector3D PLUS_K = new Vector3D(0, 0, 1);

  50.     /** Opposite of the third canonical vector (coordinates: 0, 0, -1).  */
  51.     public static final Vector3D MINUS_K = new Vector3D(0, 0, -1);

  52.     // CHECKSTYLE: stop ConstantName
  53.     /** A vector with all coordinates set to NaN. */
  54.     public static final Vector3D NaN = new Vector3D(Double.NaN, Double.NaN, Double.NaN);
  55.     // CHECKSTYLE: resume ConstantName

  56.     /** A vector with all coordinates set to positive infinity. */
  57.     public static final Vector3D POSITIVE_INFINITY =
  58.         new Vector3D(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);

  59.     /** A vector with all coordinates set to negative infinity. */
  60.     public static final Vector3D NEGATIVE_INFINITY =
  61.         new Vector3D(Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY, Double.NEGATIVE_INFINITY);

  62.     /** Serializable version identifier. */
  63.     private static final long serialVersionUID = 1313493323784566947L;

  64.     /** Abscissa. */
  65.     private final double x;

  66.     /** Ordinate. */
  67.     private final double y;

  68.     /** Height. */
  69.     private final double z;

  70.     /** Simple constructor.
  71.      * Build a vector from its coordinates
  72.      * @param x abscissa
  73.      * @param y ordinate
  74.      * @param z height
  75.      * @see #getX()
  76.      * @see #getY()
  77.      * @see #getZ()
  78.      */
  79.     public Vector3D(double x, double y, double z) {
  80.         this.x = x;
  81.         this.y = y;
  82.         this.z = z;
  83.     }

  84.     /** Simple constructor.
  85.      * Build a vector from its coordinates
  86.      * @param v coordinates array
  87.      * @exception MathIllegalArgumentException if array does not have 3 elements
  88.      * @see #toArray()
  89.      */
  90.     public Vector3D(double[] v) throws MathIllegalArgumentException {
  91.         if (v.length != 3) {
  92.             throw new MathIllegalArgumentException(LocalizedCoreFormats.DIMENSIONS_MISMATCH,
  93.                                                    v.length, 3);
  94.         }
  95.         this.x = v[0];
  96.         this.y = v[1];
  97.         this.z = v[2];
  98.     }

  99.     /** Simple constructor.
  100.      * Build a vector from its azimuthal coordinates
  101.      * @param alpha azimuth (&alpha;) around Z
  102.      *              (0 is +X, &pi;/2 is +Y, &pi; is -X and 3&pi;/2 is -Y)
  103.      * @param delta elevation (&delta;) above (XY) plane, from -&pi;/2 to +&pi;/2
  104.      * @see #getAlpha()
  105.      * @see #getDelta()
  106.      */
  107.     public Vector3D(double alpha, double delta) {
  108.         SinCos sinCosAlpha = FastMath.sinCos(alpha);
  109.         SinCos sinCosDelta = FastMath.sinCos(delta);
  110.         this.x = sinCosAlpha.cos() * sinCosDelta.cos();
  111.         this.y = sinCosAlpha.sin() * sinCosDelta.cos();
  112.         this.z = sinCosDelta.sin();
  113.     }

  114.     /** Multiplicative constructor
  115.      * Build a vector from another one and a scale factor.
  116.      * The vector built will be a * u
  117.      * @param a scale factor
  118.      * @param u base (unscaled) vector
  119.      */
  120.     public Vector3D(double a, Vector3D u) {
  121.         this.x = a * u.x;
  122.         this.y = a * u.y;
  123.         this.z = a * u.z;
  124.     }

  125.     /** Linear constructor
  126.      * Build a vector from two other ones and corresponding scale factors.
  127.      * The vector built will be a1 * u1 + a2 * u2
  128.      * @param a1 first scale factor
  129.      * @param u1 first base (unscaled) vector
  130.      * @param a2 second scale factor
  131.      * @param u2 second base (unscaled) vector
  132.      */
  133.     public Vector3D(double a1, Vector3D u1, double a2, Vector3D u2) {
  134.         this.x = MathArrays.linearCombination(a1, u1.x, a2, u2.x);
  135.         this.y = MathArrays.linearCombination(a1, u1.y, a2, u2.y);
  136.         this.z = MathArrays.linearCombination(a1, u1.z, a2, u2.z);
  137.     }

  138.     /** Linear constructor
  139.      * Build a vector from three other ones and corresponding scale factors.
  140.      * The vector built will be a1 * u1 + a2 * u2 + a3 * u3
  141.      * @param a1 first scale factor
  142.      * @param u1 first base (unscaled) vector
  143.      * @param a2 second scale factor
  144.      * @param u2 second base (unscaled) vector
  145.      * @param a3 third scale factor
  146.      * @param u3 third base (unscaled) vector
  147.      */
  148.     public Vector3D(double a1, Vector3D u1, double a2, Vector3D u2,
  149.                     double a3, Vector3D u3) {
  150.         this.x = MathArrays.linearCombination(a1, u1.x, a2, u2.x, a3, u3.x);
  151.         this.y = MathArrays.linearCombination(a1, u1.y, a2, u2.y, a3, u3.y);
  152.         this.z = MathArrays.linearCombination(a1, u1.z, a2, u2.z, a3, u3.z);
  153.     }

  154.     /** Linear constructor
  155.      * Build a vector from four other ones and corresponding scale factors.
  156.      * The vector built will be a1 * u1 + a2 * u2 + a3 * u3 + a4 * u4
  157.      * @param a1 first scale factor
  158.      * @param u1 first base (unscaled) vector
  159.      * @param a2 second scale factor
  160.      * @param u2 second base (unscaled) vector
  161.      * @param a3 third scale factor
  162.      * @param u3 third base (unscaled) vector
  163.      * @param a4 fourth scale factor
  164.      * @param u4 fourth base (unscaled) vector
  165.      */
  166.     public Vector3D(double a1, Vector3D u1, double a2, Vector3D u2,
  167.                     double a3, Vector3D u3, double a4, Vector3D u4) {
  168.         this.x = MathArrays.linearCombination(a1, u1.x, a2, u2.x, a3, u3.x, a4, u4.x);
  169.         this.y = MathArrays.linearCombination(a1, u1.y, a2, u2.y, a3, u3.y, a4, u4.y);
  170.         this.z = MathArrays.linearCombination(a1, u1.z, a2, u2.z, a3, u3.z, a4, u4.z);
  171.     }

  172.     /** Get the abscissa of the vector.
  173.      * @return abscissa of the vector
  174.      * @see #Vector3D(double, double, double)
  175.      */
  176.     public double getX() {
  177.         return x;
  178.     }

  179.     /** Get the ordinate of the vector.
  180.      * @return ordinate of the vector
  181.      * @see #Vector3D(double, double, double)
  182.      */
  183.     public double getY() {
  184.         return y;
  185.     }

  186.     /** Get the height of the vector.
  187.      * @return height of the vector
  188.      * @see #Vector3D(double, double, double)
  189.      */
  190.     public double getZ() {
  191.         return z;
  192.     }

  193.     /** Get the vector coordinates as a dimension 3 array.
  194.      * @return vector coordinates
  195.      * @see #Vector3D(double[])
  196.      */
  197.     public double[] toArray() {
  198.         return new double[] { x, y, z };
  199.     }

  200.     /** {@inheritDoc} */
  201.     @Override
  202.     public Space getSpace() {
  203.         return Euclidean3D.getInstance();
  204.     }

  205.     /** {@inheritDoc} */
  206.     @Override
  207.     public Vector3D getZero() {
  208.         return ZERO;
  209.     }

  210.     /** {@inheritDoc} */
  211.     @Override
  212.     public double getNorm1() {
  213.         return FastMath.abs(x) + FastMath.abs(y) + FastMath.abs(z);
  214.     }

  215.     /** {@inheritDoc} */
  216.     @Override
  217.     public double getNorm() {
  218.         // there are no cancellation problems here, so we use the straightforward formula
  219.         return FastMath.sqrt (x * x + y * y + z * z);
  220.     }

  221.     /** {@inheritDoc} */
  222.     @Override
  223.     public double getNormSq() {
  224.         // there are no cancellation problems here, so we use the straightforward formula
  225.         return x * x + y * y + z * z;
  226.     }

  227.     /** {@inheritDoc} */
  228.     @Override
  229.     public double getNormInf() {
  230.         return FastMath.max(FastMath.max(FastMath.abs(x), FastMath.abs(y)), FastMath.abs(z));
  231.     }

  232.     /** Get the azimuth of the vector.
  233.      * @return azimuth (&alpha;) of the vector, between -&pi; and +&pi;
  234.      * @see #Vector3D(double, double)
  235.      */
  236.     public double getAlpha() {
  237.         return FastMath.atan2(y, x);
  238.     }

  239.     /** Get the elevation of the vector.
  240.      * @return elevation (&delta;) of the vector, between -&pi;/2 and +&pi;/2
  241.      * @see #Vector3D(double, double)
  242.      */
  243.     public double getDelta() {
  244.         return FastMath.asin(z / getNorm());
  245.     }

  246.     /** {@inheritDoc} */
  247.     @Override
  248.     public Vector3D add(final Vector3D v) {
  249.         return new Vector3D(x + v.x, y + v.y, z + v.z);
  250.     }

  251.     /** {@inheritDoc} */
  252.     @Override
  253.     public Vector3D add(double factor, final Vector3D v) {
  254.         return new Vector3D(1, this, factor, v);
  255.     }

  256.     /** {@inheritDoc} */
  257.     @Override
  258.     public Vector3D subtract(final Vector3D v) {
  259.         return new Vector3D(x - v.x, y - v.y, z - v.z);
  260.     }

  261.     /** {@inheritDoc} */
  262.     @Override
  263.     public Vector3D subtract(final double factor, final Vector3D v) {
  264.         return new Vector3D(1, this, -factor, v);
  265.     }

  266.     /** Get a vector orthogonal to the instance.
  267.      * <p>There are an infinite number of normalized vectors orthogonal
  268.      * to the instance. This method picks up one of them almost
  269.      * arbitrarily. It is useful when one needs to compute a reference
  270.      * frame with one of the axes in a predefined direction. The
  271.      * following example shows how to build a frame having the k axis
  272.      * aligned with the known vector u :
  273.      * </p>
  274.      * <pre><code>
  275.      *   Vector3D k = u.normalize();
  276.      *   Vector3D i = k.orthogonal();
  277.      *   Vector3D j = Vector3D.crossProduct(k, i);
  278.      * </code></pre>
  279.      * @return a new normalized vector orthogonal to the instance
  280.      * @exception MathRuntimeException if the norm of the instance is null
  281.      */
  282.     public Vector3D orthogonal() throws MathRuntimeException {

  283.         double threshold = 0.6 * getNorm();
  284.         if (threshold == 0) {
  285.             throw new MathRuntimeException(LocalizedCoreFormats.ZERO_NORM);
  286.         }

  287.         if (FastMath.abs(x) <= threshold) {
  288.             double inverse  = 1 / FastMath.sqrt(y * y + z * z);
  289.             return new Vector3D(0, inverse * z, -inverse * y);
  290.         } else if (FastMath.abs(y) <= threshold) {
  291.             double inverse  = 1 / FastMath.sqrt(x * x + z * z);
  292.             return new Vector3D(-inverse * z, 0, inverse * x);
  293.         }
  294.         double inverse  = 1 / FastMath.sqrt(x * x + y * y);
  295.         return new Vector3D(inverse * y, -inverse * x, 0);

  296.     }

  297.     /** Compute the angular separation between two vectors.
  298.      * <p>This method computes the angular separation between two
  299.      * vectors using the dot product for well separated vectors and the
  300.      * cross product for almost aligned vectors. This allows to have a
  301.      * good accuracy in all cases, even for vectors very close to each
  302.      * other.</p>
  303.      * @param v1 first vector
  304.      * @param v2 second vector
  305.      * @return angular separation between v1 and v2
  306.      * @exception MathRuntimeException if either vector has a null norm
  307.      */
  308.     public static double angle(Vector3D v1, Vector3D v2) throws MathRuntimeException {

  309.         double normProduct = v1.getNorm() * v2.getNorm();
  310.         if (normProduct == 0) {
  311.             throw new MathRuntimeException(LocalizedCoreFormats.ZERO_NORM);
  312.         }

  313.         double dot = v1.dotProduct(v2);
  314.         double threshold = normProduct * 0.9999;
  315.         if ((dot < -threshold) || (dot > threshold)) {
  316.             // the vectors are almost aligned, compute using the sine
  317.             Vector3D v3 = crossProduct(v1, v2);
  318.             if (dot >= 0) {
  319.                 return FastMath.asin(v3.getNorm() / normProduct);
  320.             }
  321.             return FastMath.PI - FastMath.asin(v3.getNorm() / normProduct);
  322.         }

  323.         // the vectors are sufficiently separated to use the cosine
  324.         return FastMath.acos(dot / normProduct);

  325.     }

  326.     /** {@inheritDoc} */
  327.     @Override
  328.     public Vector3D negate() {
  329.         return new Vector3D(-x, -y, -z);
  330.     }

  331.     /** {@inheritDoc} */
  332.     @Override
  333.     public Vector3D scalarMultiply(double a) {
  334.         return new Vector3D(a * x, a * y, a * z);
  335.     }

  336.     /** {@inheritDoc} */
  337.     @Override
  338.     public boolean isNaN() {
  339.         return Double.isNaN(x) || Double.isNaN(y) || Double.isNaN(z);
  340.     }

  341.     /** {@inheritDoc} */
  342.     @Override
  343.     public boolean isInfinite() {
  344.         return !isNaN() && (Double.isInfinite(x) || Double.isInfinite(y) || Double.isInfinite(z));
  345.     }

  346.     /**
  347.      * Test for the equality of two 3D vectors.
  348.      * <p>
  349.      * If all coordinates of two 3D vectors are exactly the same, and none are
  350.      * {@code Double.NaN}, the two 3D vectors are considered to be equal.
  351.      * </p>
  352.      * <p>
  353.      * {@code NaN} coordinates are considered to affect globally the vector
  354.      * and be equals to each other - i.e, if either (or all) coordinates of the
  355.      * 3D vector are equal to {@code Double.NaN}, the 3D vector is equal to
  356.      * {@link #NaN}.
  357.      * </p>
  358.      *
  359.      * @param other Object to test for equality to this
  360.      * @return true if two 3D vector objects are equal, false if
  361.      *         object is null, not an instance of Vector3D, or
  362.      *         not equal to this Vector3D instance
  363.      *
  364.      */
  365.     @Override
  366.     public boolean equals(Object other) {

  367.         if (this == other) {
  368.             return true;
  369.         }

  370.         if (other instanceof Vector3D) {
  371.             final Vector3D rhs = (Vector3D)other;
  372.             return x == rhs.x && y == rhs.y && z == rhs.z || isNaN() && rhs.isNaN();
  373.         }

  374.         return false;

  375.     }

  376.     /**
  377.      * Test for the equality of two 3D vectors.
  378.      * <p>
  379.      * If all coordinates of two 3D vectors are exactly the same, and none are
  380.      * {@code NaN}, the two 3D vectors are considered to be equal.
  381.      * </p>
  382.      * <p>
  383.      * In compliance with IEEE754 handling, if any coordinates of any of the
  384.      * two vectors are {@code NaN}, then the vectors are considered different.
  385.      * This implies that {@link #NaN Vector3D.NaN}.equals({@link #NaN Vector3D.NaN})
  386.      * returns {@code false} despite the instance is checked against itself.
  387.      * </p>
  388.      *
  389.      * @param other Object to test for equality to this
  390.      * @return true if two 3D vector objects are equal, false if
  391.      *         object is null, not an instance of Vector3D, or
  392.      *         not equal to this Vector3D instance
  393.      * @since 2.1
  394.      */
  395.     public boolean equalsIeee754(Object other) {

  396.         if (this == other && !isNaN()) {
  397.             return true;
  398.         }

  399.         if (other instanceof Vector3D) {
  400.             final Vector3D rhs = (Vector3D) other;
  401.             return x == rhs.x && y == rhs.y && z == rhs.z;
  402.         }

  403.         return false;

  404.     }

  405.     /**
  406.      * Get a hashCode for the 3D vector.
  407.      * <p>
  408.      * All NaN values have the same hash code.</p>
  409.      *
  410.      * @return a hash code value for this object
  411.      */
  412.     @Override
  413.     public int hashCode() {
  414.         if (isNaN()) {
  415.             return 642;
  416.         }
  417.         return 643 * (164 * MathUtils.hash(x) +  3 * MathUtils.hash(y) +  MathUtils.hash(z));
  418.     }

  419.     /** {@inheritDoc}
  420.      * <p>
  421.      * The implementation uses specific multiplication and addition
  422.      * algorithms to preserve accuracy and reduce cancellation effects.
  423.      * It should be very accurate even for nearly orthogonal vectors.
  424.      * </p>
  425.      * @see MathArrays#linearCombination(double, double, double, double, double, double)
  426.      */
  427.     @Override
  428.     public double dotProduct(final Vector3D v) {
  429.         return MathArrays.linearCombination(x, v.x, y, v.y, z, v.z);
  430.     }

  431.     /** Compute the cross-product of the instance with another vector.
  432.      * @param v other vector
  433.      * @return the cross product this ^ v as a new Vector3D
  434.      */
  435.     public Vector3D crossProduct(final Vector3D v) {
  436.         return new Vector3D(MathArrays.linearCombination(y, v.z, -z, v.y),
  437.                             MathArrays.linearCombination(z, v.x, -x, v.z),
  438.                             MathArrays.linearCombination(x, v.y, -y, v.x));
  439.     }

  440.     /** {@inheritDoc} */
  441.     @Override
  442.     public double distance1(Vector3D v) {
  443.         final double dx = FastMath.abs(v.x - x);
  444.         final double dy = FastMath.abs(v.y - y);
  445.         final double dz = FastMath.abs(v.z - z);
  446.         return dx + dy + dz;
  447.     }

  448.     /** {@inheritDoc} */
  449.     @Override
  450.     public double distance(Vector3D v) {
  451.         final double dx = v.x - x;
  452.         final double dy = v.y - y;
  453.         final double dz = v.z - z;
  454.         return FastMath.sqrt(dx * dx + dy * dy + dz * dz);
  455.     }

  456.     /** {@inheritDoc} */
  457.     @Override
  458.     public double distanceInf(Vector3D v) {
  459.         final double dx = FastMath.abs(v.x - x);
  460.         final double dy = FastMath.abs(v.y - y);
  461.         final double dz = FastMath.abs(v.z - z);
  462.         return FastMath.max(FastMath.max(dx, dy), dz);
  463.     }

  464.     /** {@inheritDoc} */
  465.     @Override
  466.     public double distanceSq(Vector3D v) {
  467.         final double dx = v.x - x;
  468.         final double dy = v.y - y;
  469.         final double dz = v.z - z;
  470.         return dx * dx + dy * dy + dz * dz;
  471.     }

  472.     /** Compute the dot-product of two vectors.
  473.      * @param v1 first vector
  474.      * @param v2 second vector
  475.      * @return the dot product v1.v2
  476.      */
  477.     public static double dotProduct(Vector3D v1, Vector3D v2) {
  478.         return v1.dotProduct(v2);
  479.     }

  480.     /** Compute the cross-product of two vectors.
  481.      * @param v1 first vector
  482.      * @param v2 second vector
  483.      * @return the cross product v1 ^ v2 as a new Vector
  484.      */
  485.     public static Vector3D crossProduct(final Vector3D v1, final Vector3D v2) {
  486.         return v1.crossProduct(v2);
  487.     }

  488.     /** Compute the distance between two vectors according to the L<sub>1</sub> norm.
  489.      * <p>Calling this method is equivalent to calling:
  490.      * <code>v1.subtract(v2).getNorm1()</code> except that no intermediate
  491.      * vector is built</p>
  492.      * @param v1 first vector
  493.      * @param v2 second vector
  494.      * @return the distance between v1 and v2 according to the L<sub>1</sub> norm
  495.      */
  496.     public static double distance1(Vector3D v1, Vector3D v2) {
  497.         return v1.distance1(v2);
  498.     }

  499.     /** Compute the distance between two vectors according to the L<sub>2</sub> norm.
  500.      * <p>Calling this method is equivalent to calling:
  501.      * <code>v1.subtract(v2).getNorm()</code> except that no intermediate
  502.      * vector is built</p>
  503.      * @param v1 first vector
  504.      * @param v2 second vector
  505.      * @return the distance between v1 and v2 according to the L<sub>2</sub> norm
  506.      */
  507.     public static double distance(Vector3D v1, Vector3D v2) {
  508.         return v1.distance(v2);
  509.     }

  510.     /** Compute the distance between two vectors according to the L<sub>&infin;</sub> norm.
  511.      * <p>Calling this method is equivalent to calling:
  512.      * <code>v1.subtract(v2).getNormInf()</code> except that no intermediate
  513.      * vector is built</p>
  514.      * @param v1 first vector
  515.      * @param v2 second vector
  516.      * @return the distance between v1 and v2 according to the L<sub>&infin;</sub> norm
  517.      */
  518.     public static double distanceInf(Vector3D v1, Vector3D v2) {
  519.         return v1.distanceInf(v2);
  520.     }

  521.     /** Compute the square of the distance between two vectors.
  522.      * <p>Calling this method is equivalent to calling:
  523.      * <code>v1.subtract(v2).getNormSq()</code> except that no intermediate
  524.      * vector is built</p>
  525.      * @param v1 first vector
  526.      * @param v2 second vector
  527.      * @return the square of the distance between v1 and v2
  528.      */
  529.     public static double distanceSq(Vector3D v1, Vector3D v2) {
  530.         return v1.distanceSq(v2);
  531.     }

  532.     /** {@inheritDoc} */
  533.     @Override
  534.     public Vector3D moveTowards(final Vector3D other, final double ratio) {
  535.         return new Vector3D(x + ratio * (other.x - x),
  536.                             y + ratio * (other.y - y),
  537.                             z + ratio * (other.z - z));
  538.     }

  539.     /** Get a string representation of this vector.
  540.      * @return a string representation of this vector
  541.      */
  542.     @Override
  543.     public String toString() {
  544.         return Vector3DFormat.getVector3DFormat().format(this);
  545.     }

  546.     /** {@inheritDoc} */
  547.     @Override
  548.     public String toString(final NumberFormat format) {
  549.         return new Vector3DFormat(format).format(this);
  550.     }

  551. }