Class Vector3d

java.lang.Object
org.eclipse.mosaic.lib.math.Vector3d
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
PointCloud.Point, SpatialObject

public class Vector3d extends Object implements Serializable
See Also:
  • Field Details

    • x

      public double x
    • y

      public double y
    • z

      public double z
  • Constructor Details

    • Vector3d

      public Vector3d()
      Constructor for Vector3d, which initializes it as V_0.
           |0|
       v = |0|
           |0|
       
    • Vector3d

      public Vector3d(double x, double y, double z)
      Constructor for Vector3d, initializing it with the given coordinates.
           |x|
       v = |y|
           |z|
       
      Parameters:
      x - X-Coordinate
      y - Y-Coordinate
      z - Z-Coordinate
    • Vector3d

      public Vector3d(Vector3d v)
      Constructor for Vector3d, initializing it with a copy of the coordinates from another given Vector3d.
        Vector3d(v_j):
               |x_j|
           v = |y_j|
               |z_j|
       
      Parameters:
      v - Vector3d to be copied
  • Method Details

    • set

      public Vector3d set(Vector3d v)
      Sets the coordinates of the Vector3d to the given value, setting it to a copy of the coordinates from another given Vector3d.
      Parameters:
      v - Vector3d to be copied
      Returns:
      the vector on which set has been called
    • set

      public Vector3d set(double x, double y, double z)
      Sets the coordinates of the Vector3d to the given values.
      Parameters:
      x - X-Coordinate
      y - Y-Coordinate
      z - Z-Coordinate
      Returns:
      the vector on which set has been called
    • set

      public Vector3d set(double f)
      Sets all entries of the Vector3d to the given value.
      Parameters:
      f - given value
      Returns:
      the vector on which set has been called
    • multiply

      public Vector3d multiply(double f)
      Multiplies a scalar to the Vector3d.
        v_i.multiply(f):
            x_i = x_i * f
            y_i = y_i * f
            z_i = z_i * f
       
      Parameters:
      f - scalar of type double
      Returns:
      the vector on which multiply has been called
    • multiply

      public Vector3d multiply(double f, Vector3d result)
      Multiplies a scalar to a Vector3d, storing the multiplication-result into a given vector.
        v_i.multiply(f, v_r):
            x_r = x_i * f
            y_r = y_i * f
            z_r = z_i * f
       
      Parameters:
      f - scalar of type double
      result - the Vector3d where the multiplication result should be saved to
      Returns:
      the result-vector
    • scale

      public Vector3d scale(Vector3d scale)
      Coordinate-wise multiplication of two vectors.
        v_i.scale(v_j):
            x_i = x_i * x_j
            y_i = y_i * y_j
            z_i = z_i * z_j
       
      Parameters:
      scale - the Vector3d to be scaled with
      Returns:
      the vector on which scale has been called
    • scale

      public Vector3d scale(Vector3d scale, Vector3d result)
      Coordinate-wise multiplication of two vectors, storing the scale-result into a given vector.
        v_i.scale(v_j, v_r):
            x_r = x_i * x_j
            y_r = y_i * y_j
            z_r = z_i * z_j
       
      Parameters:
      scale - the Vector3d to be scaled with
      result - the Vector3d where the scale-result should be saved to
      Returns:
      the result-vector
    • add

      public Vector3d add(Vector3d v)
      Coordinate-wise addition of two vectors.
        v_i.add(v_j):
            x_i = x_i + x_j
            y_i = y_i + y_j
            z_i = z_i + z_j
       
      Parameters:
      v - the Vector3d to be added
      Returns:
      the vector on which add has been called
    • add

      public Vector3d add(Vector3d v, Vector3d result)
      Coordinate-wise addition of two vectors, storing the addition-result into a given vector.
        v_i.add(v_j, v_r):
            x_r = x_i + x_j
            y_r = y_i + y_j
            z_r = z_i + z_j
       
      Parameters:
      v - the Vector3d to be added
      result - the Vector3d where the addition-result should be saved to
      Returns:
      the result-vector
    • subtract

      public Vector3d subtract(Vector3d v)
      Coordinate-wise subtraction of two vectors.
        v_i.subtract(v_j):
            x_i = x_i - x_j
            y_i = y_i - y_j
            z_i = z_i - z_j
       
      Parameters:
      v - the Vector3d to be subtracted
      Returns:
      the vector on which subtract has been called
    • subtract

      public Vector3d subtract(Vector3d v, Vector3d result)
      Coordinate-wise subtraction of two vectors, storing the subtraction-result into a given vector.
        v_i.subtract(v_j, v_r):
            x_r = x_i - x_j
            y_r = y_i - y_j
            z_r = z_i - z_j
       
      Parameters:
      v - the Vector3d to be subtracted
      result - the Vector3d where the subtraction-result should be saved to
      Returns:
      the result-vector
    • dot

      public double dot(Vector3d v)
      The dot product of two Vector3d resulting in a scalar.
        v_i.dot(v_j): = x_i * x_j + y_i * y_j + z_i * z_j
       
      Parameters:
      v - the Vector3d to be used for the dot product
      Returns:
      the resulting scalar
    • cross

      public Vector3d cross(Vector3d v, Vector3d result)
      The cross-product of two Vector3d, storing the subtraction-result into a given vector.
        v_i.cross(v_j, v_r):
            x_r = y_i * z_j - z_i * y_j
            y_r = z_i * x_j - x_i * z_j
            z_r = x_i * y_j - y_i * x_j
       
      Parameters:
      v - the Vector3d to be used for the cross-product
      result - the Vector3d where the cross-product should be saved to
      Returns:
      the resulting Vector3d
    • angle

      public double angle(Vector3d v)
      Calculates and returns the angle between the current and the given vector in radians.
      Parameters:
      v - the given vector
      Returns:
      angle in radians
    • norm

      public Vector3d norm()
      Normalizes the Vector3d by dividing it by its magnitude().
      Returns:
      the normalized Vector3d
    • norm

      public Vector3d norm(Vector3d result)
      Normalizes the Vector3d by dividing it by its magnitude(), storing the result into a given vector.
      Parameters:
      result - the Vector3d where the normalization should be saved to
      Returns:
      the normalized Vector3d
    • magnitude

      public double magnitude()
    • magnitudeSqr

      public double magnitudeSqr()
    • distanceTo

      public double distanceTo(Vector3d v)
      Method to determine the Euclidean distance between the two points represented by two Vector3ds, resulting in a scalar value.
       v_i.distanceTo(v_j) = sqrt((x_j - x_i)^2 + (y_j - y_i)^2 + (z_j - z_i)^2)
       
      Parameters:
      v - the Vector3d to which the distance should be determined
      Returns:
      the resulting Euclidean distance
    • distanceSqrTo

      public double distanceSqrTo(Vector3d v)
      Method to determine the sqquared Euclidean distance between the two points represented by two Vector3ds, resulting in a scalar value.
       v_i.distanceSqrTo(v_j) = (x_j - x_i)^2 + (y_j - y_i)^2 + (z_j - z_i)^2
       
      Parameters:
      v - the Vector3d to which the squared distance should be determined
      Returns:
      the resulting squared Euclidean distance
    • rotateDeg

      public Vector3d rotateDeg(double angleDeg, Vector3d axis)
      Rotates this Vector3d by the specified angle (in degrees) around the given axis.
      Parameters:
      angleDeg - Rotation angle in degrees
      axis - Rotation axis
      Returns:
      the rotated Vector3d
    • rotate

      public Vector3d rotate(double angle, Vector3d axis)
      Rotates this Vector3d by the specified angle (in radians) around the given axis.
      Parameters:
      angle - Rotation angle in radians
      axis - Rotation axis
      Returns:
      the rotated Vector3d
    • rotate

      public Vector3d rotate(double angle, double axisX, double axisY, double axisZ)
      Rotates this Vector3d by the specified angle (in radians) around the given axis.
      Parameters:
      angle - Rotation angle in radians
      axisX - Rotation axis x-component
      axisY - Rotation axis y-component
      axisZ - Rotation axis z-component
      Returns:
      the rotated Vector3d
    • toArray

      public void toArray(double[] result, int offset)
      Writes the Vector3d to an array using doubles, given an offset as start-index.
      Parameters:
      result - the array where the result should be saved to
      offset - the start-index for writing
    • toArray

      public void toArray(float[] result, int offset)
      Writes the Vector3d to an array using floats, given an offset as start-index.
      Parameters:
      result - the array where the result should be saved to
      offset - the start-index for writing
    • toCartesian

      public CartesianPoint toCartesian()
      Conversion of Vector3d to a CartesianPoint within MOSAIC's coordinate system.
      Returns:
      the resulting CartesianPoint
    • toCartesian

      public MutableCartesianPoint toCartesian(MutableCartesianPoint result)
      Conversion of Vector3d to a CartesianPoint within MOSAIC's coordinate system, storing the results in a given MutableCartesianPoint.
      Parameters:
      result - a MutableCartesianPoint where the conversion will be saved to
      Returns:
      the resulting CartesianPoint
    • toGeo

      public GeoPoint toGeo()
      Conversion of Vector3d to a GeoPoint using the underlying GeoProjection.
      Returns:
      the resulting GeoPoint
    • toGeo

      public MutableGeoPoint toGeo(MutableGeoPoint result)
      Projection of Vector3d to a GeoPoint using the underlying GeoProjection, storing the result in a given MutableGeoPoint.
      Parameters:
      result - the MutableGeoPoint where the projection will be saved to
      Returns:
      the resulting MutableGeoPoint
    • isFuzzyEqual

      public boolean isFuzzyEqual(Vector3d other)
      Parameters:
      other - the Vector3d to be compared
      Returns:
      true if all coordinates of both Vector3ds are fuzzy-equal, else {@link false}
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object