Class Coord2d

java.lang.Object
org.jzy3d.maths.Coord2d
All Implemented Interfaces:
Serializable

public class Coord2d extends Object implements Serializable
A Coord2d stores a 2 dimensional coordinate for cartesian (x,y) or polar (a,r) mode, and provide operators allowing to add, substract, multiply and divises coordinate values, as well as computing the distance between two points, and converting polar and cartesian coordinates.
Author:
Martin Pernollet
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Coord2d
     
    static final Coord2d
    An invalid Coord2d has value NaN for each dimension.
    static final Coord2d
    The origin is a Coord2d having value 0 for each dimension.
    float
     
    float
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a 2d coordinate with the value 0 for each dimension.
    Coord2d(double xi)
     
    Coord2d(double xi, double yi)
    Creates a 2d coordinate.
    Coord2d(float xi, float yi)
    Creates a 2d coordinate.
  • Method Summary

    Modifier and Type
    Method
    Description
    add(float value)
    Add a value to all components of the current Coord and return the result in a new Coord2d.
    add(float x, float y)
     
    Add a Coord2d to the current one and return the result in a new Coord2d.
    void
    addSelf(float x, float y)
     
    void
     
    void
    addSelfX(float x)
     
    void
    addSelfY(float y)
     
    static Coord2d
    addWeighted(Coord2d a, Coord2d b, float weigthA, float weightB)
     
    Converts the current Coord3d into cartesian coordinates and return the result in a new Coord3d.
    Return a duplicate of this 3d coordinate.
    double
    Compute the distance between two coordinates.
    double
     
    div(float value)
    Divise all components of the current Coord by the same value and return the result in a new Coord3d.
    div(float x, float y)
     
    Divise a Coord2d to the current one and return the result in a new Coord2d.
    void
    divSelf(float value)
     
    boolean
     
    Return a real polar value, with an angle in the range [0;2*PI] https://en.wikipedia.org/wiki/Polar_coordinate_system
    float
     
    float
     
    int
     
    static Coord2d
    interpolate(Coord2d a, Coord2d b, float weigthA)
     
    interpolation(Coord2d c, float ratio)
    Returns an interpolated point between the current and given point, according to an input ratio in [0;1] that indicates how near to the current point the new point will stand.
     
    mul(float value)
    Multiply all components of the current Coord and return the result in a new Coord3d.
    mul(float x, float y)
     
    Multiply a Coord2d to the current one and return the result in a new Coord2d.
    mulSelf(float x, float y)
     
     
    Converts the current Coord2d into polar coordinates and return the result in a new Coord2d.
    void
    set(float x, float y)
     
    void
     
    sub(float value)
    Substract a value to all components of the current Coord and return the result in a new Coord2d.
    sub(float x, float y)
     
    Substract a Coord2d to the current one and return the result in a new Coord2d.
     
    float[]
    Return an array representation of this coordinate.
    Return a string representation of this coordinate.

    Methods inherited from class java.lang.Object

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

    • ORIGIN

      public static final Coord2d ORIGIN
      The origin is a Coord2d having value 0 for each dimension.
    • IDENTITY

      public static final Coord2d IDENTITY
    • INVALID

      public static final Coord2d INVALID
      An invalid Coord2d has value NaN for each dimension.
    • x

      public float x
    • y

      public float y
  • Constructor Details

    • Coord2d

      public Coord2d()
      Creates a 2d coordinate with the value 0 for each dimension.
    • Coord2d

      public Coord2d(float xi, float yi)
      Creates a 2d coordinate. When using polar mode, x represents angle, and y represents distance.
    • Coord2d

      public Coord2d(double xi, double yi)
      Creates a 2d coordinate. When using polar mode, x represents angle, and y represents distance.
    • Coord2d

      public Coord2d(double xi)
  • Method Details

    • clone

      public Coord2d clone()
      Return a duplicate of this 3d coordinate.
      Overrides:
      clone in class Object
    • set

      public void set(Coord2d c)
    • set

      public void set(float x, float y)
    • add

      public Coord2d add(Coord2d c2)
      Add a Coord2d to the current one and return the result in a new Coord2d.
      Parameters:
      c2 -
      Returns:
      the result Coord2d
    • addSelf

      public void addSelf(Coord2d c2)
    • addSelf

      public void addSelf(float x, float y)
    • addSelfX

      public void addSelfX(float x)
    • addSelfY

      public void addSelfY(float y)
    • add

      public Coord2d add(float value)
      Add a value to all components of the current Coord and return the result in a new Coord2d.
      Parameters:
      value -
      Returns:
      the result Coord2d
    • add

      public Coord2d add(float x, float y)
    • sub

      public Coord2d sub(Coord2d c2)
      Substract a Coord2d to the current one and return the result in a new Coord2d.
      Parameters:
      c2 -
      Returns:
      the result Coord2d
    • sub

      public Coord2d sub(float value)
      Substract a value to all components of the current Coord and return the result in a new Coord2d.
      Parameters:
      value -
      Returns:
      the result Coord2d
    • sub

      public Coord2d sub(float x, float y)
    • mul

      public Coord2d mul(Coord2d c2)
      Multiply a Coord2d to the current one and return the result in a new Coord2d.
      Parameters:
      c2 -
      Returns:
      the result Coord2d
    • mul

      public Coord2d mul(float x, float y)
    • mul

      public Coord2d mul(float value)
      Multiply all components of the current Coord and return the result in a new Coord3d.
      Parameters:
      value -
      Returns:
      the result Coord3d
    • mulSelf

      public Coord2d mulSelf(Coord2d c)
    • mulSelf

      public Coord2d mulSelf(float x, float y)
    • div

      public Coord2d div(Coord2d c2)
      Divise a Coord2d to the current one and return the result in a new Coord2d.
      Parameters:
      c2 -
      Returns:
      the result Coord2d
    • div

      public Coord2d div(float value)
      Divise all components of the current Coord by the same value and return the result in a new Coord3d.
      Parameters:
      value -
      Returns:
      the result Coord3d
    • div

      public Coord2d div(float x, float y)
    • divSelf

      public void divSelf(float value)
    • cartesian

      public Coord2d cartesian()
      Converts the current Coord3d into cartesian coordinates and return the result in a new Coord3d.
      Returns:
      the result Coord3d
    • polar

      public Coord2d polar()
      Converts the current Coord2d into polar coordinates and return the result in a new Coord2d.
    • fullPolar

      public Coord2d fullPolar()
      Return a real polar value, with an angle in the range [0;2*PI] https://en.wikipedia.org/wiki/Polar_coordinate_system
    • distance

      public double distance(Coord2d c)
      Compute the distance between two coordinates.
    • distanceSq

      public double distanceSq(Coord2d c)
    • interpolation

      public Coord2d interpolation(Coord2d c, float ratio)
      Returns an interpolated point between the current and given point, according to an input ratio in [0;1] that indicates how near to the current point the new point will stand. A value of 1 will return a copy of the current point.
    • mean

      public Coord2d mean(Coord2d b)
    • addWeighted

      public static Coord2d addWeighted(Coord2d a, Coord2d b, float weigthA, float weightB)
    • interpolate

      public static Coord2d interpolate(Coord2d a, Coord2d b, float weigthA)
    • toString

      public String toString()
      Return a string representation of this coordinate.
      Overrides:
      toString in class Object
    • toArray

      public float[] toArray()
      Return an array representation of this coordinate.
    • getX

      public float getX()
    • getY

      public float getY()
    • hashCode

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

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • to3d

      public Coord3d to3d()