Class Vec

java.lang.Object
rekit.primitives.geometry.Vec
All Implemented Interfaces:
Cloneable, Operable<Vec>

@ClassParser(VecParser.class) public final class Vec extends Object implements Cloneable, Operable<Vec>
A three dimensional Vector with operations.
Author:
Angelo Aracri
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final float
    The x-component of the vector.
    final float
    The y-component of the vector.
    final float
    The optional z-component of the vector.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Vec()
    Short-hand constructor that takes the default value (0|0).
    Vec(double x, double y)
    Constructor that takes the initial coordinates an saves them.
    Vec(float xy)
    Constructor that takes one initial coordinate an saves them as x and y.
    Vec(float x, float y)
    Constructor that takes the initial coordinates an saves them.
    Vec(float x, float y, float z)
    Constructor that takes the initial coordinates an saves them.
    Vec(int x, int y)
    Constructor that takes the initial coordinates an saves them.
  • Method Summary

    Modifier and Type
    Method
    Description
    abs()
    Apply Math.abs(float) to x and y component and create new vector.
    add(Vec vec)
    Adds another vector to this vector and returns a new Vector.
    addX(float deltaX)
    Adds a given number to the x-component and returns a new Vector.
    addY(float deltaY)
    Adds a given number to the y-component and returns a new Vector.
     
    get()
    Always ! Enter the code: return this;
    float
    getAngleTo(Vec other)
    Get the angle to another vector.
    Multiplies the vectors x-component and its y-component with the x-component and y-component of another Vector and returns a new Vector.
    float
    Calculate the 2-norm of this vector.
    rotate(double angle)
    Rotate this vector relative to (0|0).
    rotate(double angle, Vec relative)
    Rotate this vector relative to a vector.
    scalar(float scalar)
    Multiplies the vector with a scalar and returns a new Vector.
    scalar(float scalarX, float scalarY)
    Multiplies the vectors x-component and its y-component with separate scalars and returns a new Vector.
    setX(float x)
    Sets number to the x-component and returns a new Vector.
    setY(float y)
    Sets number to the y-component and returns a new Vector.
    setZ(float z)
    Create a new vector with this x,y values but a new z value.
    sin()
    Calculate the sin of x and y.
    sub(Vec other)
    Apply subtrahend.
     
    translate2D(float offset)
    Translate a 3D-Vector to 2D.

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • x

      public final float x
      The x-component of the vector.
    • y

      public final float y
      The y-component of the vector.
    • z

      public final float z
      The optional z-component of the vector.
  • Constructor Details

    • Vec

      public Vec(float x, float y, float z)
      Constructor that takes the initial coordinates an saves them.
      Parameters:
      x - the initial x-component of the vector
      y - the initial y-component of the vector
      z - the initial z-component of the vector
    • Vec

      public Vec(float x, float y)
      Constructor that takes the initial coordinates an saves them.
      Parameters:
      x - the initial x-component of the vector
      y - the initial y-component of the vector
    • Vec

      public Vec(double x, double y)
      Constructor that takes the initial coordinates an saves them. Note that only floats are used internally.
      Parameters:
      x - the initial x-component of the vector
      y - the initial y-component of the vector
    • Vec

      public Vec(int x, int y)
      Constructor that takes the initial coordinates an saves them.
      Parameters:
      x - the initial x-component of the vector
      y - the initial y-component of the vector
    • Vec

      public Vec(float xy)
      Constructor that takes one initial coordinate an saves them as x and y.
      Parameters:
      xy - the initial x- and y-component of the vector
    • Vec

      public Vec()
      Short-hand constructor that takes the default value (0|0).
  • Method Details

    • setX

      public Vec setX(float x)
      Sets number to the x-component and returns a new Vector.
      Parameters:
      x - the new x-component of the vector
      Returns:
      the vector with the new x-component
    • addX

      public Vec addX(float deltaX)
      Adds a given number to the x-component and returns a new Vector.
      Parameters:
      deltaX - the number to add to the original x-component of the vector
      Returns:
      the vector with the new x-component
    • setY

      public Vec setY(float y)
      Sets number to the y-component and returns a new Vector.
      Parameters:
      y - the new y-component of the vector
      Returns:
      the vector with the new y-component
    • addY

      public Vec addY(float deltaY)
      Adds a given number to the y-component and returns a new Vector.
      Parameters:
      deltaY - the number to add to the original y-component of the vector
      Returns:
      the vector with the new y-component
    • add

      public Vec add(Vec vec)
      Adds another vector to this vector and returns a new Vector.
      Specified by:
      add in interface Operable<Vec>
      Parameters:
      vec - the other vector to add
      Returns:
      the sum of the vectors
    • sub

      public Vec sub(Vec other)
      Description copied from interface: Operable
      Apply subtrahend.
      Specified by:
      sub in interface Operable<Vec>
      Parameters:
      other - the other
      Returns:
      the object itself
    • sin

      public Vec sin()
      Calculate the sin of x and y.
      Returns:
      a new vector (sinx, siny)
    • scalar

      public Vec scalar(float scalar)
      Multiplies the vector with a scalar and returns a new Vector.
      Specified by:
      scalar in interface Operable<Vec>
      Parameters:
      scalar - the scalar to multiply the vector with
      Returns:
      the resulting vector
    • scalar

      public Vec scalar(float scalarX, float scalarY)
      Multiplies the vectors x-component and its y-component with separate scalars and returns a new Vector.
      Parameters:
      scalarX - the scalar to multiply the vectors x-component with
      scalarY - the scalar to multiply the vectors x-component with
      Returns:
      the resulting vector
    • multiply

      public Vec multiply(Vec vec)
      Multiplies the vectors x-component and its y-component with the x-component and y-component of another Vector and returns a new Vector.
      Specified by:
      multiply in interface Operable<Vec>
      Parameters:
      vec - vector to multiply with
      Returns:
      the resulting vector
    • getAngleTo

      public float getAngleTo(Vec other)
      Get the angle to another vector.
      Parameters:
      other - the other vector
      Returns:
      the angle (rad)
    • rotate

      public Vec rotate(double angle, Vec relative)
      Rotate this vector relative to a vector.
      Parameters:
      angle - the angle
      relative - the relative vector for rotation
      Returns:
      the new vector
    • rotate

      public Vec rotate(double angle)
      Rotate this vector relative to (0|0).
      Parameters:
      angle - the angle
      Returns:
      the new vector
    • abs

      public Vec abs()
      Apply Math.abs(float) to x and y component and create new vector.
      Returns:
      the resulting vector
    • norm

      public float norm()
      Calculate the 2-norm of this vector.
      Returns:
      the 2-norm
    • clone

      public Vec clone()
      Overrides:
      clone in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • setZ

      public Vec setZ(float z)
      Create a new vector with this x,y values but a new z value.
      Parameters:
      z - the new z value
      Returns:
      a new vector (x,y,z)
    • translate2D

      public Vec translate2D(float offset)
      Translate a 3D-Vector to 2D.
      Parameters:
      offset - the offset (3D)
      Returns:
      the new vector
    • get

      public Vec get()
      Description copied from interface: Operable
      Always ! Enter the code: return this;
      Specified by:
      get in interface Operable<Vec>
      Returns:
      this