32#ifndef RCSC_GEOM_VECTOR2D_H
33#define RCSC_GEOM_VECTOR2D_H
139 return x *
x +
y *
y;
149 return std::sqrt(
r2() );
212 return Vector2D( std::fabs(
x ), std::fabs(
y ) );
221 return std::fabs(
x );
230 return std::fabs(
y );
323 return scale( scalar );
334 if ( std::fabs( scalar ) >
EPSILON )
350 return ( std::pow( this->x - p.
x, 2 )
351 + std::pow( this->y - p.
y, 2 ) );
363 return std::sqrt(
dist2( p ) );
373 const double yy )
const
375 return ( std::pow( this->x - xx, 2 )
376 + std::pow( this->y - yy, 2 ) );
386 const double yy )
const
390 return std::sqrt(
dist2( xx, yy ) );
420 double mag = this->
r();
427 return scale( len / mag );
437 return Vector2D( *this ).setLength( len );
456 return Vector2D( *this ).normalize();
468 return assign( this->x * c - this->y * s,
469 this->x * s + this->y * c );
489 return Vector2D( *this ).rotate( deg );
509 double radius = this->
r();
522 return this->x * v.
x + this->y * v.
y;
542 return this->x * v.
y - this->y * v.
x;
553 return this->x == other.
x
554 && this->y == other.
y;
565 return std::fabs( this->x - other.
x ) <
EPSILON
566 && std::fabs( this->y - other.
y ) <
EPSILON;
636 std::ostream &
print( std::ostream & os )
const
638 os <<
'(' <<
x <<
", " <<
y <<
')';
649 const double prec = 0.1 )
const
651 os <<
'(' << rint(
x / prec ) * prec
652 <<
", " << rint(
y / prec ) * prec <<
')';
673 return lhs.
x < rhs.
x;
691 return lhs.
y < rhs.
y;
745 return ( lhs.
x < rhs.
x
768 return ( lhs.
y < rhs.
y
769 || ( lhs.
y == rhs.
y && lhs.
x < rhs.
x ) );
877template <
typename T >
885template <
typename T >
893template <
typename T >
901template <
typename T >
909template <
typename T >
918template <
typename T >
927template <
typename T >
935template <
typename T >
943template <
typename T >
951template <
typename T >
971 return v.
print( os );
degree wrapper class Header File.
degree wrapper class
Definition: angle_deg.h:45
double cos() const
calculate cosine
Definition: angle_deg.h:292
double degree() const
get value of this angle
Definition: angle_deg.h:130
static const double DEG2RAD
constant variable to convert DEGREE to RADIAN.
Definition: angle_deg.h:67
static double atan2_deg(const double y, const double x)
static utility. calculate arc tangent value from XY
Definition: angle_deg.h:486
double sin() const
calculate sine
Definition: angle_deg.h:301
2D point vector class
Definition: vector_2d.h:46
Vector2D abs() const
get new vector that XY values were set to absolute value.
Definition: vector_2d.h:210
Vector2D normalizedVector() const
get new normalized vector that the length is set to 1.0 but angle is same
Definition: vector_2d.h:454
double dist2(const double xx, const double yy) const
get the squared distance from this to (xx,yy).
Definition: vector_2d.h:372
Vector2D & scale(const double scalar)
scale this vector
Definition: vector_2d.h:264
Vector2D & setLength(const double len)
set vector length to 'len'.
Definition: vector_2d.h:418
std::ostream & print(std::ostream &os) const
output XY values to ostream.
Definition: vector_2d.h:636
AngleDeg th() const
get the angle of vector.
Definition: vector_2d.h:192
Vector2D & rotate(const AngleDeg &angle)
rotate this vector with 'angle'.
Definition: vector_2d.h:477
const Vector2D & invalidate()
invalidate this object
Definition: vector_2d.h:126
Vector2D & assign(const double xx, const double yy)
assign XY value directly.
Definition: vector_2d.h:100
Vector2D & setDir(const AngleDeg &dir)
set vector's angle to 'angle'
Definition: vector_2d.h:507
Vector2D rotatedVector(const double deg) const
get new vector that is rotated by 'deg'.
Definition: vector_2d.h:487
static const Vector2D INVALIDATED
invalidated value vector
Definition: vector_2d.h:61
Vector2D & reverse()
reverse vector components
Definition: vector_2d.h:397
double r() const
get the length of vector.
Definition: vector_2d.h:146
Vector2D & add(const Vector2D &v)
add vector.
Definition: vector_2d.h:238
static Vector2D from_polar(const double mag, const AngleDeg &theta)
get new Vector created by POLAR value.
Definition: vector_2d.h:594
Vector2D & setPolar(const double radius, const AngleDeg &dir)
assign XY value from POLAR value.
Definition: vector_2d.h:114
double norm2() const
get the squared norm value. this method is equivalent to r2().
Definition: vector_2d.h:165
Vector2D operator-() const
create reversed vector
Definition: vector_2d.h:284
Vector2D & normalize()
normalize vector. length is set to 1.0.
Definition: vector_2d.h:444
double dist(const Vector2D &p) const
get the distance from this to 'p'.
Definition: vector_2d.h:359
Vector2D(const double xx, const double yy)
create Vector with XY value directly.
Definition: vector_2d.h:79
Vector2D setLengthVector(const double len) const
get new vector that the length is set to 'len'
Definition: vector_2d.h:435
const Vector2D & operator/=(const double scalar)
divided by 'scalar'.
Definition: vector_2d.h:331
static Vector2D polar2vector(const double mag, const AngleDeg &theta)
get new Vector created by POLAR value.
Definition: vector_2d.h:580
double absY() const
get absolute y value
Definition: vector_2d.h:228
double y
Y coordinate.
Definition: vector_2d.h:64
Vector2D rotatedVector(const AngleDeg &angle) const
get new vector that is rotated by 'angle'.
Definition: vector_2d.h:497
const Vector2D & operator-=(const Vector2D &v)
subtract vector to itself
Definition: vector_2d.h:306
double norm() const
get the norm value. this method is equivalent to r().
Definition: vector_2d.h:156
static double inner_product(const Vector2D &v1, const Vector2D &v2)
get inner(dot) product for v1 and v2.
Definition: vector_2d.h:608
Vector2D()
default constructor.
Definition: vector_2d.h:69
double dist2(const Vector2D &p) const
get the squared distance from this to 'p'.
Definition: vector_2d.h:347
Vector2D & add(const double xx, const double yy)
add XY values respectively.
Definition: vector_2d.h:251
const Vector2D & operator+() const
return this vector
Definition: vector_2d.h:275
double length() const
get the length of vector. this method is equivalent to r().
Definition: vector_2d.h:174
static const double EPSILON
constant threshold value for calculation error
Definition: vector_2d.h:55
double innerProduct(const Vector2D &v) const
get inner(dot) product with 'v'.
Definition: vector_2d.h:520
AngleDeg dir() const
get the angle of vector. this method is equivalent to th().
Definition: vector_2d.h:201
const Vector2D & operator*=(const double scalar)
multiplied by 'scalar'
Definition: vector_2d.h:318
double x
X coordinate.
Definition: vector_2d.h:63
double dist(const double xx, const double yy) const
get the distance from this to (xx, yy).
Definition: vector_2d.h:385
static const double ERROR_VALUE
constant error value for XY (= std::numeric_limits< doulble >::max()).
Definition: vector_2d.h:58
static double outer_product(const Vector2D &v1, const Vector2D &v2)
get outer(cross) product for v1 and v2.
Definition: vector_2d.h:622
std::ostream & printRound(std::ostream &os, const double prec=0.1) const
output rounded XY values to ostream.
Definition: vector_2d.h:648
bool isValid() const
check if this vector is valid or not.
Definition: vector_2d.h:89
const Vector2D & operator+=(const Vector2D &v)
add vector to itself
Definition: vector_2d.h:294
double length2() const
get the squared length value. this method is equivalent to r2().
Definition: vector_2d.h:183
double r2() const
get the squared length of vector.
Definition: vector_2d.h:137
bool equals(const Vector2D &other) const
check if this vector is strictly same as given vector.
Definition: vector_2d.h:551
double absX() const
get absolute x value
Definition: vector_2d.h:219
double outerProduct(const Vector2D &v) const
get virtal outer(cross) product with 'v'.
Definition: vector_2d.h:531
Vector2D reversedVector() const
get reversed vector.
Definition: vector_2d.h:408
bool equalsWeakly(const Vector2D &other) const
check if this vector is weakly same as given vector.
Definition: vector_2d.h:562
Vector2D & rotate(const double deg)
rotate this vector with 'deg'
Definition: vector_2d.h:464
comparison predicate for absolute X value.
Definition: vector_2d.h:699
bool operator()(const Vector2D &lhs, const Vector2D &rhs) const
functional operator.
Definition: vector_2d.h:706
comparison predicate for absolute Y value.
Definition: vector_2d.h:717
bool operator()(const Vector2D &lhs, const Vector2D &rhs) const
functional operator.
Definition: vector_2d.h:724
comparison predicate for X value.
Definition: vector_2d.h:663
bool operator()(const Vector2D &lhs, const Vector2D &rhs) const
functional operator.
Definition: vector_2d.h:670
comparison predicate for XY value (X -> Y order).
Definition: vector_2d.h:735
bool operator()(const Vector2D &lhs, const Vector2D &rhs) const
functional operator.
Definition: vector_2d.h:742
comparison predicate for Y value.
Definition: vector_2d.h:681
bool operator()(const Vector2D &lhs, const Vector2D &rhs) const
functional operator.
Definition: vector_2d.h:688
comparison predicatio for XY value (Y -> X order)
Definition: vector_2d.h:758
bool operator()(const Vector2D &lhs, const Vector2D &rhs) const
functional operator.
Definition: vector_2d.h:765
const rcsc::Vector2D operator-(const rcsc::Vector2D &lhs, const rcsc::Vector2D &rhs)
operator sub(T, T)
Definition: vector_2d.h:838
bool operator<=(const rcsc::Vector2D &lhs, const T &rhs)
never used
bool operator==(const rcsc::Vector2D &lhs, const rcsc::Vector2D &rhs)
check vectors are strictly same or not.
Definition: vector_2d.h:788
std::ostream & operator<<(std::ostream &os, const rcsc::Vector2D &v)
stream operator
Definition: vector_2d.h:968
const rcsc::Vector2D operator/(const rcsc::Vector2D &lhs, const double rhs)
operator div(T, U)
Definition: vector_2d.h:868
bool operator!=(const rcsc::Vector2D &lhs, const rcsc::Vector2D &rhs)
check vectors are strictly different or not.
Definition: vector_2d.h:804
const rcsc::Vector2D operator+(const rcsc::Vector2D &lhs, const rcsc::Vector2D &rhs)
operator add(T, T)
Definition: vector_2d.h:823
bool operator>(const rcsc::Vector2D &lhs, const T &rhs)
never used
bool operator<(const rcsc::Vector2D &lhs, const T &rhs)
never used
const rcsc::Vector2D operator*(const rcsc::Vector2D &lhs, const double rhs)
operator mult(T, U)
Definition: vector_2d.h:853
bool operator>=(const rcsc::Vector2D &lhs, const T &rhs)
never used