public class Real2 extends Object implements EuclidConstants
| Modifier and Type | Field and Description |
|---|---|
double |
x
the first floating point value
|
double |
y
the second floating point value
|
C_AMP, C_APOS, C_ATSIGN, C_BACKSLASH, C_BACKSPACE, C_CARET, C_COLON, C_COMMA, C_DEL, C_DOLLAR, C_EQUALS, C_FORMFEED, C_HASH, C_LANGLE, C_LBRAK, C_LCURLY, C_LSQUARE, C_MINUS, C_NBSP, C_NEWLINE, C_NL, C_PERCENT, C_PERIOD, C_PIPE, C_PLUS, C_POUND, C_QUERY, C_QUOT, C_RANGLE, C_RBRAK, C_RCURLY, C_RETURN, C_RSQUARE, C_SEMICOLON, C_SHRIEK, C_SLASH, C_SPACE, C_STAR, C_TAB, C_TILDE, C_UNDER, EPS, F_S, NONWHITEPUNC, NONWHITEPUNC0, NONWHITEPUNC0REGEX, ONE_THIRD, PUNC, S_AMP, S_APOS, S_ATSIGN, S_BACKSLASH, S_CARET, S_COLON, S_COMMA, S_DOLLAR, S_EMPTY, S_EQUALS, S_FORMFEED, S_HASH, S_LANGLE, S_LBRAK, S_LCURLY, S_LSQUARE, S_MINUS, S_NEWLINE, S_NL, S_PERCENT, S_PERIOD, S_PIPE, S_PLUS, S_POUND, S_QUERY, S_QUOT, S_RANGLE, S_RBRAK, S_RCURLY, S_RETURN, S_RSQUARE, S_SEMICOLON, S_SHRIEK, S_SLASH, S_SPACE, S_STAR, S_TAB, S_TILDE, S_UNDER, S_WHITEREGEX, TWO_THIRDS, U_S, WHITESPACE| Constructor and Description |
|---|
Real2()
constructor.
|
Real2(double[] x)
constructor.
|
Real2(double x,
double y)
constructor.
|
Real2(Int2 int2)
constructor.
|
Real2(int x,
int y)
constructor.
|
Real2(Real2 r)
copy constructor
|
Real2(String s)
two reals separated by whitespace
OR
(real, real)
|
Real2(String s,
String delimiter)
two integers separated by delimiter
|
| Modifier and Type | Method and Description |
|---|---|
static Real2[] |
addPolygonOnLine(Real2 point1,
Real2 point2,
int nPoints,
int end,
Real2 repelPoint)
creates a polygon
returns a point array from two points Serial numbers of points are 0 and
end that is point1 is points[0] and point2 is points[end] if end == 0,
end =>1
|
void |
clear()
set to 0 0
|
static Real2 |
createFromString(String s)
reads output format from toString()
"(x,y)"
|
double |
dotProduct(Real2 r)
get dot product
|
double |
elementAt(int elem)
get either value counts from ZERO
|
Real2 |
format(int places)
round to decimal places.
|
double |
getAngle()
get angle between origin and this point (i.e polar coords) - uses atan2
(that is anticlockwise from X axis); if x == y == 0.0 presumably returns
NaN
|
static Angle |
getAngle(Real2 p1,
Real2 p2,
Real2 p3)
get angle between 3 Real2s (the second is in the centre)
|
static Real2 |
getCentroid(List<Real2> p2Vector)
get centroid of all points.
|
double |
getDistance(Real2 r)
get distance to another Real2
|
static RealMatrix |
getDistanceMatrix(List<Real2> coords1,
List<Real2> coords2)
get rectangular distance matrix.
|
double |
getLength()
get length of Real2 if centered on origin
|
Real2 |
getMidPoint(Real2 p)
point midway between 'this' and 'p'
|
static int |
getSerialOfNearestPoint(List<Real2> p2v,
Real2 point)
get serialNumber of nearest point
|
double |
getSquaredDistance(Real2 r)
get squared distance to another Real2
|
Real2 |
getTransformed(Transform2 t)
gets a point transformed by a rot-trans matrix does NOT MODIFY 'this'
|
Real2 |
getUnitVector()
get unit vector
|
double |
getX()
get X value
|
double[] |
getXY()
get x y as array.
|
double |
getY()
get Y value
|
boolean |
isEqualTo(Real2 r)
Deprecated.
|
boolean |
isEqualTo(Real2 r,
double eps)
equality.
|
boolean |
isOrigin()
Deprecated.
USE epsilon method
|
boolean |
isOrigin(double epsilon)
is the point the origin.
|
Real2 |
makePoint(double rad,
double theta)
make a new point at (dist, theta) from this
|
Real2 |
multiplyBy(double f)
retuen multiplication of a point by a scalar
does not alter this
|
void |
multiplyEquals(double f)
multiply a point by a scalar
alters this
|
void |
negative()
multiply both components by minus one MODIFIES 'this'
|
Real2 |
plus(Real2 r2)
add two points to give vector sum
|
void |
plusEquals(Real2 r2)
add two points to give vector sum
|
void |
setX(double xx)
set x.
|
void |
setY(double yy)
set y.
|
void |
sortAscending()
sorts x and y so that x <= y
|
void |
sortDescending()
sorts x and y so that x >= y
|
Real2 |
subtract(Real2 r2)
subtract two points to give vector difference
|
void |
swap()
swaps the x and y values
|
String |
toString()
to string.
|
void |
transformBy(Transform2 t)
transforms the point by a rot-trans matrix MODIFIES 'this' Note the next
routine is often better
|
public double x
public double y
public Real2()
public Real2(double x,
double y)
x - the first floating point valuey - the second floating point valuepublic Real2(int x,
int y)
x - the first integer valuey - the second integer valuepublic Real2(Int2 int2)
int2 - An object of type Int2 containing two integer valuespublic Real2(String s)
s - the string containing two reals separated by whitespacepublic Real2(String s, String delimiter)
s - the string containing two integers separated by delimiterdelimiter - the delimiterpublic Real2(double[] x)
x - the two componentspublic Real2(Real2 r)
r - the real object to be copiedpublic static Real2 createFromString(String s)
s - string representation of real, "(x,y)"public void swap()
public void sortAscending()
public void sortDescending()
public void clear()
public void setX(double xx)
xx - floating point x value to be setpublic void setY(double yy)
yy - floating point y value to be setpublic boolean isEqualTo(Real2 r)
r - to testpublic boolean isEqualTo(Real2 r, double eps)
r - to testeps - tolerancepublic boolean isOrigin()
public boolean isOrigin(double epsilon)
epsilon - Epsilonpublic Real2 plus(Real2 r2)
r2 - the specified real to be added with this realpublic void plusEquals(Real2 r2)
r2 - the specified real to be added and assigned with this realpublic Real2 subtract(Real2 r2)
r2 - the specified real to be subtracted from this realpublic void negative()
public Real2 multiplyBy(double f)
f - a floating point scalar valuepublic void multiplyEquals(double f)
f - a floating point scalar valuepublic double getX()
public double getY()
public double elementAt(int elem)
throws EuclidRuntimeException
elem - index of elementEuclidRuntimeExceptionpublic double getLength()
public double getDistance(Real2 r)
r - the specified real to be measured against this realpublic double getSquaredDistance(Real2 r)
r - the specified real to be measured against this realpublic Real2 getMidPoint(Real2 p)
p - the specified real to be measured against this realpublic Real2 getUnitVector()
EuclidRuntimeException - this was of zero lengthpublic double dotProduct(Real2 r)
r - the specified real to be measured against this realpublic static Angle getAngle(Real2 p1, Real2 p2, Real2 p3)
p1 - point 1p2 - point 2p3 - point 3public void transformBy(Transform2 t)
t - rot-trans matrixpublic Real2 getTransformed(Transform2 t)
t - rot-trans matrixpublic static Real2[] addPolygonOnLine(Real2 point1, Real2 point2, int nPoints, int end, Real2 repelPoint)
point1 - starting pointnPoints - number of points in the resulting polygonpoint2 - ending pointend - index of point2 in points arrayrepelPoint - repel pointpublic double getAngle()
public Real2 makePoint(double rad, double theta)
rad - the distance to new pointtheta - the angle to new point (anticlockwise from X axis), that is
theta=0 gives (rad, 0), theta=PI/2 gives (0, rad)public static Real2 getCentroid(List<Real2> p2Vector)
p2Vector - list of all real pointspublic static int getSerialOfNearestPoint(List<Real2> p2v, Real2 point)
p2v - list of all real pointspoint - point wrt which serialNumber is calculatedpublic static RealMatrix getDistanceMatrix(List<Real2> coords1, List<Real2> coords2)
coords1 - first coordinate of the rectanglecoords2 - second coordinate of the rectanglepublic double[] getXY()
public Real2 format(int places)
places - max number of decimals (3 = ****.ddd)Copyright © 1994–2024 Peter Murray-Rust. All rights reserved.