Class RationalPoint_2

java.lang.Object
Jcg.geometry.RationalPoint_2
All Implemented Interfaces:
Comparable<Point_>, Point_

public class RationalPoint_2 extends Object implements Point_
A class for representing a 2D points with rational coordinates
Author:
Luca Castelli Aleardi (Ecole Polytechnique, dec 2022)
  • Field Details

    • x

      public Rational x
      geometric coordinates of the points (rational numbers)
    • y

      public Rational y
      geometric coordinates of the points (rational numbers)
    • index

      public int index
      integer index of the point: useful in some applications
  • Constructor Details

    • RationalPoint_2

      public RationalPoint_2()
    • RationalPoint_2

      public RationalPoint_2(Rational x, Rational y)
      Initialize a 2D point with rational coordinates.

      Warning: this constructor does not define the index of the point
      Parameters:
      x - x-coordinate
      y - y-coordinate
    • RationalPoint_2

      public RationalPoint_2(int x, int y)
      Initialize a rational 2D point, with integer coordinates.

      Warning: this constructor does not define the index of the point
      Parameters:
      x - x-coordinate
      y - y-coordinate
    • RationalPoint_2

      public RationalPoint_2(GridPoint_2 p)
      Initialize a rational 2D point equal to an integer point p.

      Warning: this constructor does not define the index of the point
      Parameters:
      p - integer 2D point
    • RationalPoint_2

      public RationalPoint_2(Rational x, Rational y, int index)
      Initialize a 2D points with rational coordinates, and an index
      Parameters:
      x - x-coordinate
      y - y-coordinate
      index - index (useful for indexing points in some applications)
    • RationalPoint_2

      public RationalPoint_2(RationalPoint_2 p)
      Make a copy of the input point p

      Warning: p must be a Rational_2 point
      Parameters:
      p - input point to copy (p must be a Rational_2 point)
    • RationalPoint_2

      public RationalPoint_2(Point_ p)
      Make a copy of the input point p

      Warning: p must be a Rational_2 point
      Parameters:
      p - input point to copy (p must be a Rational_2 point)
  • Method Details

    • getIndex

      public int getIndex()
      Return the index
    • getX

      public Rational getX()
      Return the x-coordinate
    • getY

      public Rational getY()
      Return the y-coordinate
    • setIndex

      public void setIndex(int index)
      Set the index
    • setX

      public void setX(Number x)
      Set the x-coordinate of the current point

      Remark: the number x must be either
      -) an Integer number
      -) or a Rational number
    • setY

      public void setY(Number y)
      Set the y-coordinate of the current point

      Remark: the number y must be either
      -) an integer number
      -) or a Rational number
    • translateOf

      public void translateOf(Vector_ o)
      Translate the current point of the vector o
      Specified by:
      translateOf in interface Point_
    • equals

      public boolean equals(Object o)
      Check whether the current point is equal to point 'o'.

      Warning: point 'o' must be of type RationalPoint_2
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Warning: the result is very bad for rational points in [0..1]
      Overrides:
      hashCode in class Object
    • distanceFrom

      public double distanceFrom(RationalPoint_2 p)
    • squareDistance

      public Rational squareDistance(Point_ o)
      Return the square of the Euclidean distance between the current point 'this' and a point o
      Specified by:
      squareDistance in interface Point_
    • barycenter

      public void barycenter(Point_[] points)
      Set the current point as the barycenter of an array of points
      Specified by:
      barycenter in interface Point_
    • linearCombination

      public void linearCombination(Point_[] points, Number[] coefficients)
      Set the current point to be the linear combination of the input points, with respect to the given input coefficients
      Specified by:
      linearCombination in interface Point_
    • linearCombination

      public static RationalPoint_2 linearCombination(RationalPoint_2[] points, Number[] coefficients)
      Return a new rational point defined by the linear combination of the input points, with respect to the given input coefficients
    • toString

      public String toString()
      Description copied from interface: Point_
      Return a string (representation of the point)
      Specified by:
      toString in interface Point_
      Overrides:
      toString in class Object
    • dimension

      public int dimension()
      Description copied from interface: Point_
      Return the dimension of the space
      Specified by:
      dimension in interface Point_
    • getCartesian

      public Rational getCartesian(int dim)
      Return the d-th coordinate of the point
      Specified by:
      getCartesian in interface Point_
      Parameters:
      dim - the d-th coordinate of the point:
      dim=0 for x-coordinate, dim=1 for y-coordinate
    • setCartesian

      public void setCartesian(int dim, Number v)
      Set the d-th coordinate of the point
      Specified by:
      setCartesian in interface Point_
      Parameters:
      dim - the d-th coordinate of the point:
      dim=0 for x-coordinate, dim=1 for y-coordinate
    • setOrigin

      public void setOrigin()
      Set the coordinates of the current point to be (0, 0)
      Specified by:
      setOrigin in interface Point_
    • minus

      public Vector_ minus(Point_ q)
      Return the integer grid vector (p-q), where q is the current point

      Warning: q is assumed to be an integer GridPoint_2
      Specified by:
      minus in interface Point_
      Returns:
      a new GridVector_2 vector corresponding to (p-q)
    • sum

      public RationalPoint_2 sum(Vector_ v)
    • compareTo

      public int compareTo(Point_ q)
      Compare two points (lexicographic order on coordinates)
      Specified by:
      compareTo in interface Comparable<Point_>
      Parameters:
      q - the point to compare to the current point (this)
      Returns:
      -1 if the current point is smaller (with respect to lexicographic order) to the point q; it returns 0 is the two points have equal coordinates. It returns 1 otherwise.
    • compareCartesian

      public int compareCartesian(Point_ o, int i)
      Compare the i-th coordinate of two points
      Specified by:
      compareCartesian in interface Point_
      Parameters:
      o - the point to compare
      i - the i-th coordinate to compare
      Returns:
      -1 if the i-th coordinate of the current point this is smaller then i-th coordinate of point o, return 0 if both points have the same i-th coordinate, and return 1 otherwise