com.kuka.nav.geometry
Class Point2D

java.lang.Object
  extended by com.kuka.nav.geometry.Point2D
All Implemented Interfaces:
Serializable, Comparable<Point2D>

public final class Point2D
extends Object
implements Serializable, Comparable<Point2D>

Immutable representation of a 2-dimensional point. To quote Murray, R. et al — A mathematical Introduction to Robotic Manipulation, Section 3.1 the following propositions are hold:

  1. Sum and difference of vectors are vectors
  2. The sum of a vector and a point is a point
  3. The difference between two points is a vector
  4. The sum of two points is meaningless

See Also:
Serialized Form

Field Summary
static Point2D ORIGIN
          Immutable Point2D instance representing the origin of a coordinate system.
 
Constructor Summary
Point2D()
          Returns a new instance of this class with 0,0 coordinates.
Point2D(double x, double y)
          Returns a new instance of this class.
Point2D(com.kuka.math.geometry.Point3D p)
          Constructs a new point from a given 3D point by dropping the third (z) coordinate.
Point2D(Vector2D vector)
          Returns a new instance of this class.
 
Method Summary
 Point2D add(Vector2D other)
          Adds the given vector to this point, resulting in a new point.
 boolean approxEquals(Point2D p, double epsilon)
          Compares for equality within an epsilon envelope.
 int compareTo(Point2D o)
           
 double distance(Point2D to)
          Returns the distance to another point.
 boolean equals(Object obj)
          Compares the specified object for equality with this point.
 double get(int index)
          Gets a coordinate of the point at the specified index, where 0 denotes the x and 1 the y coordinate.
 double getX()
          Returns the x coordinate of the point.
 double getY()
          Returns the y coordinate of the point.
 int hashCode()
          Returns the hash code for this point.
static Point2D of(double x, double y)
          Returns an immutable Point2D instance constructed from its cartesian X and Y coordinates.
static Point2D of(Vector2D vector)
          Returns an immutable Point2D instance from a vector that points from the origin to the new point.
 Vector2D subtract(Point2D other)
          Subtracts the given point from this point, resulting in the connecting vector pointing from the other point to this point.
 com.kuka.math.geometry.Point3D to3D()
          Embeds this 2D point into the 3D space.
 String toString()
          Returns the point value formatted as a column vector in a way compatible with popular scientific numerical computing applications.
 String toString(NumberFormat fmt)
          Returns the point value formatted as a column vector in a way similar to popular scientific numerical computing applications.
 Vector2D toVector()
          Returns this point as a vector, which is the vector pointing from the origin to this point.
 Point2D withX(double value)
          Returns a new instance (copy) of the point, with the x element replaced by the new value.
 Point2D withY(double value)
          Returns a new instance (copy) of the point, with the y element replaced by the new value.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ORIGIN

public static final Point2D ORIGIN
Immutable Point2D instance representing the origin of a coordinate system.

Constructor Detail

Point2D

public Point2D()
Returns a new instance of this class with 0,0 coordinates.


Point2D

public Point2D(double x,
               double y)
Returns a new instance of this class.

Parameters:
x - x coordinate of the point
y - y coordinate of the point

Point2D

public Point2D(Vector2D vector)
Returns a new instance of this class.

Parameters:
vector - vector pointing from origin to the position of the point

Point2D

public Point2D(com.kuka.math.geometry.Point3D p)
Constructs a new point from a given 3D point by dropping the third (z) coordinate.

Parameters:
p - a 3D point
Method Detail

of

public static Point2D of(double x,
                         double y)
Returns an immutable Point2D instance constructed from its cartesian X and Y coordinates.

Parameters:
x - the cartesian X coordinate of the point
y - the cartesian Y coordinate of the point
Returns:
an immutable Point2D instance

of

public static Point2D of(Vector2D vector)
Returns an immutable Point2D instance from a vector that points from the origin to the new point.

Parameters:
vector - the vector from origin to the point
Returns:
an immutable Point2D instance
Throws:
IllegalArgumentException - if vector is null

toVector

public Vector2D toVector()
Returns this point as a vector, which is the vector pointing from the origin to this point.

Returns:
a vector instance.

get

public double get(int index)
Gets a coordinate of the point at the specified index, where 0 denotes the x and 1 the y coordinate.

Parameters:
index - The index of the coordinate, must be between 0 and 1.
Returns:
The coordinate at the specified index.
Throws:
IndexOutOfBoundsException - illegal index
See Also:
getX(), getY()

getX

public double getX()
Returns the x coordinate of the point.

Returns:
The x coordinate of the point.
See Also:
getY(), get(int)

getY

public double getY()
Returns the y coordinate of the point.

Returns:
The y coordinate of the point.
See Also:
getX(), get(int)

withX

public Point2D withX(double value)
Returns a new instance (copy) of the point, with the x element replaced by the new value.

Parameters:
value - The x element of the point.
Returns:
a new instance of the class

withY

public Point2D withY(double value)
Returns a new instance (copy) of the point, with the y element replaced by the new value.

Parameters:
value - The y element of the point.
Returns:
a new instance of the class

add

public Point2D add(Vector2D other)
Adds the given vector to this point, resulting in a new point.

Parameters:
other - The vector which will be added to this point.
Returns:
The resulting point.

subtract

public Vector2D subtract(Point2D other)
Subtracts the given point from this point, resulting in the connecting vector pointing from the other point to this point.

Parameters:
other - The point which will be subtracted from this point.
Returns:
The resulting connecting vector.

distance

public double distance(Point2D to)
Returns the distance to another point.

Parameters:
to - another point
Returns:
the distance between this and the other point

to3D

public com.kuka.math.geometry.Point3D to3D()
Embeds this 2D point into the 3D space.

Returns:
the corresponding 3D point

toString

public String toString()
Returns the point value formatted as a column vector in a way compatible with popular scientific numerical computing applications. The numerical values will be printed in the same format as defined in Double.toString(double).

The following string can be regarded as typical:

[1.234; 300.0; -20.2]

Overrides:
toString in class Object
Returns:
a textual representation of the point

toString

public String toString(NumberFormat fmt)
Returns the point value formatted as a column vector in a way similar to popular scientific numerical computing applications. The numerical values will be printed using the NumberFormat.format(double) method of the given formatter.

Example: The following code snippet, used on a given Point2D point

 NumberFormat fmt = NumberFormat.getNumberInstance(Locale.US);
 fmt.setMinimumFractionDigits(1);
 fmt.setMaximumFractionDigits(3);
 System.out.println(point.toString(fmt));
 
might give the following output:
 [-1.234; 1.414; 20.0]
 

Parameters:
fmt - the NumberFormat used to format the number values
Returns:
a textual representation of the point

hashCode

public int hashCode()
Returns the hash code for this point. The hash code is computed by a combination of all the data elements defined by this interface.

Overrides:
hashCode in class Object
Returns:
hash code for this point.

equals

public boolean equals(Object obj)
Compares the specified object for equality with this point. Points are equal if all data elements returned by this interface are equal.

Overrides:
equals in class Object
Parameters:
obj - Object to be compared with this point.
Returns:
true if the object is equal to this point.

compareTo

public int compareTo(Point2D o)
Specified by:
compareTo in interface Comparable<Point2D>

approxEquals

public boolean approxEquals(Point2D p,
                            double epsilon)
Compares for equality within an epsilon envelope.

Parameters:
p - the other point to compare to
epsilon - the tolerance
Returns:
true if the points are within the epsilon tolerance


Copyright © 2019. All rights reserved.