Class RationalPoint_2
java.lang.Object
Jcg.geometry.RationalPoint_2
- All Implemented Interfaces:
Comparable<Point_>,Point_
A class for representing a 2D points with rational coordinates
- Author:
- Luca Castelli Aleardi (Ecole Polytechnique, dec 2022)
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionRationalPoint_2(int x, int y) Initialize a rational 2D point, with integer coordinates.Initialize a rational 2D point equal to an integer point p.Make a copy of the input point p
Warning: p must be a Rational_2 pointMake a copy of the input point p
Warning: p must be a Rational_2 pointRationalPoint_2(Rational x, Rational y) Initialize a 2D point with rational coordinates.RationalPoint_2(Rational x, Rational y, int index) Initialize a 2D points with rational coordinates, and an index -
Method Summary
Modifier and TypeMethodDescriptionvoidbarycenter(Point_[] points) Set the current point as the barycenter of an array of pointsintcompareCartesian(Point_ o, int i) Compare the i-th coordinate of two pointsintCompare two points (lexicographic order on coordinates)intReturn the dimension of the spacedoublebooleanCheck whether the current point is equal to point 'o'.getCartesian(int dim) Return the d-th coordinate of the pointintgetIndex()Return the indexgetX()Return the x-coordinategetY()Return the y-coordinateinthashCode()Warning: the result is very bad for rational points in [0..1]voidlinearCombination(Point_[] points, Number[] coefficients) Set the current point to be the linear combination of the input points, with respect to the given input coefficientsstatic RationalPoint_2linearCombination(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 coefficientsReturn the integer grid vector (p-q), where q is the current point
Warning: q is assumed to be an integer GridPoint_2voidsetCartesian(int dim, Number v) Set the d-th coordinate of the pointvoidsetIndex(int index) Set the indexvoidSet the coordinates of the current point to be (0, 0)voidSet the x-coordinate of the current point
Remark: the number x must be either
-) an Integer number
-) or a Rational numbervoidSet the y-coordinate of the current point
Remark: the number y must be either
-) an integer number
-) or a Rational numberReturn the square of the Euclidean distance between the current point 'this' and a point otoString()Return a string (representation of the point)voidTranslate the current point of the vector o
-
Field Details
-
x
geometric coordinates of the points (rational numbers) -
y
geometric coordinates of the points (rational numbers) -
index
public int indexinteger index of the point: useful in some applications
-
-
Constructor Details
-
RationalPoint_2
public RationalPoint_2() -
RationalPoint_2
-
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-coordinatey- y-coordinate
-
RationalPoint_2
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
-
RationalPoint_2
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
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
Return the x-coordinate -
getY
Return the y-coordinate -
setIndex
public void setIndex(int index) Set the index -
setX
Set the x-coordinate of the current point
Remark: the number x must be either
-) an Integer number
-) or a Rational number -
setY
Set the y-coordinate of the current point
Remark: the number y must be either
-) an integer number
-) or a Rational number -
translateOf
Translate the current point of the vector o- Specified by:
translateOfin interfacePoint_
-
equals
-
hashCode
-
distanceFrom
-
squareDistance
Return the square of the Euclidean distance between the current point 'this' and a point o- Specified by:
squareDistancein interfacePoint_
-
barycenter
Set the current point as the barycenter of an array of points- Specified by:
barycenterin interfacePoint_
-
linearCombination
Set the current point to be the linear combination of the input points, with respect to the given input coefficients- Specified by:
linearCombinationin interfacePoint_
-
linearCombination
Return a new rational point defined by the linear combination of the input points, with respect to the given input coefficients -
toString
-
dimension
-
getCartesian
Return the d-th coordinate of the point- Specified by:
getCartesianin interfacePoint_- Parameters:
dim- the d-th coordinate of the point:
dim=0 for x-coordinate, dim=1 for y-coordinate
-
setCartesian
Set the d-th coordinate of the point- Specified by:
setCartesianin interfacePoint_- Parameters:
dim- the d-th coordinate of the point:
dim=0 for x-coordinate, dim=1 for y-coordinate
-
setOrigin
-
minus
-
sum
-
compareTo
Compare two points (lexicographic order on coordinates)- Specified by:
compareToin interfaceComparable<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
Compare the i-th coordinate of two points- Specified by:
compareCartesianin interfacePoint_- Parameters:
o- the point to comparei- 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
-