32#ifndef RCSC_GEOM_VECTOR2D_H
33#define RCSC_GEOM_VECTOR2D_H
118 x = radius *
dir.cos();
119 y = radius *
dir.sin();
141 return x *
x +
y *
y;
151 return std::sqrt(
r2() );
214 return Vector2D( std::fabs(
x ), std::fabs(
y ) );
223 return std::fabs(
x );
232 return std::fabs(
y );
329 return scale( scalar );
341 if ( std::fabs( scalar ) >
EPSILON )
357 return ( std::pow( this->x - p.x, 2 )
358 + std::pow( this->y - p.y, 2 ) );
370 return std::sqrt(
dist2( p ) );
400 double mag = this->
r();
407 return scale( len / mag );
448 return assign( this->x * c - this->y * s,
449 this->x * s + this->y * c );
489 double radius = this->
r();
490 x = radius *
dir.cos();
491 y = radius *
dir.sin();
502 return this->x * v.x + this->y * v.y;
522 return this->x * v.y - this->y * v.x;
533 return this->x == other.x
534 && this->y == other.y;
545 return std::fabs( this->x - other.x ) <
EPSILON
546 && std::fabs( this->y - other.y ) <
EPSILON;
591 return v1.innerProduct( v2 );
605 return v1.outerProduct( v2 );
616 std::ostream &
print( std::ostream & os )
const
618 os <<
'(' <<
x <<
", " <<
y <<
')';
629 const double & prec = 0.1 )
const
631 os <<
'(' << rint(
x / prec ) * prec
632 <<
", " << rint(
y / prec ) * prec <<
')';
644 :
public std::binary_function< Vector2D, Vector2D, bool > {
653 const second_argument_type & rhs )
const
655 return lhs.x < rhs.x;
664 :
public std::binary_function< Vector2D, Vector2D, bool > {
673 const second_argument_type & rhs )
const
675 return lhs.y < rhs.y;
684 :
public std::binary_function< Vector2D, Vector2D, bool > {
693 const second_argument_type & rhs )
const
695 return lhs.absX() < rhs.absX();
704 :
public std::binary_function< Vector2D, Vector2D, bool > {
713 const second_argument_type & rhs )
const
715 return lhs.absY() < rhs.absY();
724 :
public std::binary_function< Vector2D, Vector2D, bool > {
733 const second_argument_type & rhs )
const
735 return ( lhs.x < rhs.x
752 :
public std::binary_function< Vector2D, Vector2D, bool > {
761 const second_argument_type & rhs )
const
763 return ( lhs.y < rhs.y
764 || ( lhs.y == rhs.y && lhs.x < rhs.x ) );
773 :
public std::binary_function< Vector2D, Vector2D, bool > {
782 const second_argument_type & rhs )
const
784 return lhs.equals( rhs );
795 template <
typename REGION >
797 :
public std::unary_function< Vector2D, bool > {
799 const REGION M_region;
807 result_type
operator()(
const argument_type & position )
const
809 return M_region.contains( position );
916template <
typename T >
924template <
typename T >
932template <
typename T >
940template <
typename T >
948template <
typename T >
957template <
typename T >
966template <
typename T >
974template <
typename T >
982template <
typename T >
990template <
typename T >
1010 return v.
print( os );
degree wrapper class Header File.
degree wrapper class
Definition angle_deg.h:45
const double & degree() const
get value of this angle
Definition angle_deg.h:133
double cos() const
calculate cosine
Definition angle_deg.h:301
static double atan2_deg(const double &y, const double &x)
static utility. calculate arc tangent value from XY
Definition angle_deg.h:495
static const double DEG2RAD
constant variable to convert DEGREE to RADIAN.
Definition angle_deg.h:67
double sin() const
calculate sine
Definition angle_deg.h:310
result_type operator()(const first_argument_type &lhs, const second_argument_type &rhs) const
functional operator.
Definition vector_2d.h:692
result_type operator()(const first_argument_type &lhs, const second_argument_type &rhs) const
functional operator.
Definition vector_2d.h:712
result_type operator()(const first_argument_type &lhs, const second_argument_type &rhs) const
functional operator.
Definition vector_2d.h:781
IsWithin(const REGION ®ion)
constructor
Definition vector_2d.h:803
result_type operator()(const argument_type &position) const
functional operator
Definition vector_2d.h:807
result_type operator()(const first_argument_type &lhs, const second_argument_type &rhs) const
functional operator.
Definition vector_2d.h:652
result_type operator()(const first_argument_type &lhs, const second_argument_type &rhs) const
functional operator.
Definition vector_2d.h:732
result_type operator()(const first_argument_type &lhs, const second_argument_type &rhs) const
functional operator.
Definition vector_2d.h:672
result_type operator()(const first_argument_type &lhs, const second_argument_type &rhs) const
functional operator.
Definition vector_2d.h:760
2D point vector class
Definition vector_2d.h:47
Vector2D abs() const
get new vector that XY values were set to absolute value.
Definition vector_2d.h:212
Vector2D normalizedVector() const
get new normalized vector that the length is set to 1.0 but angle is same
Definition vector_2d.h:434
static Vector2D from_polar(const double &mag, const AngleDeg &theta)
get new Vector created by POLAR value.
Definition vector_2d.h:574
std::ostream & print(std::ostream &os) const
output XY values to ostream.
Definition vector_2d.h:616
static const double ERROR_VALUE
constant error value for XY (= std::numeric_limits< doulble >::max()).
Definition vector_2d.h:59
AngleDeg th() const
get the angle of vector.
Definition vector_2d.h:194
Vector2D & rotate(const AngleDeg &angle)
rotate this vector with 'angle'.
Definition vector_2d.h:457
const Vector2D & invalidate()
invalidate this object
Definition vector_2d.h:128
Vector2D & setDir(const AngleDeg &dir)
set vector's angle to 'angle'
Definition vector_2d.h:487
Vector2D & reverse()
reverse vector components
Definition vector_2d.h:377
double r() const
get the length of vector.
Definition vector_2d.h:148
Vector2D & add(const Vector2D &v)
add vector.
Definition vector_2d.h:240
Vector2D & add(const double &xx, const double &yy)
add XY values respectively.
Definition vector_2d.h:253
double norm2() const
get the squared norm value. this method is equivalent to r2().
Definition vector_2d.h:167
Vector2D operator-() const
create reversed vector
Definition vector_2d.h:287
Vector2D & normalize()
normalize vector. length is set to 1.0.
Definition vector_2d.h:424
double dist(const Vector2D &p) const
get the distance from this to 'p'.
Definition vector_2d.h:366
Vector2D & rotate(const double °)
rotate this vector with 'deg'
Definition vector_2d.h:444
Vector2D setLengthVector(const double &len) const
get new vector that the length is set to 'len'
Definition vector_2d.h:415
double absY() const
get absolute y value
Definition vector_2d.h:230
static const Vector2D INVALIDATED
invalidated value vector
Definition vector_2d.h:62
static Vector2D polar2vector(const double &mag, const AngleDeg &theta)
get new Vector created by POLAR value.
Definition vector_2d.h:560
double y
Y coordinate.
Definition vector_2d.h:65
Vector2D rotatedVector(const double °) const
get new vector that is rotated by 'deg'.
Definition vector_2d.h:467
Vector2D rotatedVector(const AngleDeg &angle) const
get new vector that is rotated by 'angle'.
Definition vector_2d.h:477
const Vector2D & operator-=(const Vector2D &v)
subtract vector to itself
Definition vector_2d.h:311
std::ostream & printRound(std::ostream &os, const double &prec=0.1) const
output rounded XY values to ostream.
Definition vector_2d.h:628
double norm() const
get the norm value. this method is equivalent to r().
Definition vector_2d.h:158
static double inner_product(const Vector2D &v1, const Vector2D &v2)
get inner(dot) product for v1 and v2.
Definition vector_2d.h:588
Vector2D()
default constructor.
Definition vector_2d.h:70
double dist2(const Vector2D &p) const
get the squared distance from this to 'p'.
Definition vector_2d.h:354
const Vector2D & operator+() const
return this vector
Definition vector_2d.h:278
double length() const
get the length of vector. this method is equivalent to r().
Definition vector_2d.h:176
double innerProduct(const Vector2D &v) const
get inner(dot) product with 'v'.
Definition vector_2d.h:500
AngleDeg dir() const
get the angle of vector. this method is equivalent to th().
Definition vector_2d.h:203
Vector2D & scale(const double &scalar)
scale this vector
Definition vector_2d.h:266
const Vector2D & operator*=(const double &scalar)
multiplied by 'scalar'
Definition vector_2d.h:324
double x
X coordinate.
Definition vector_2d.h:64
static double outer_product(const Vector2D &v1, const Vector2D &v2)
get outer(cross) product for v1 and v2.
Definition vector_2d.h:602
static const double EPSILON
constant threshold value for calculation error
Definition vector_2d.h:56
Vector2D & setLength(const double &len)
set vector length to 'len'.
Definition vector_2d.h:398
bool isValid() const
check if this vector is valid or not.
Definition vector_2d.h:90
Vector2D & assign(const double &xx, const double &yy)
assign XY value directly.
Definition vector_2d.h:101
const Vector2D & operator+=(const Vector2D &v)
add vector to itself
Definition vector_2d.h:298
Vector2D & setPolar(const double &radius, const AngleDeg &dir)
assign XY value from POLAR value.
Definition vector_2d.h:115
double length2() const
get the squared length value. this method is equivalent to r2().
Definition vector_2d.h:185
double r2() const
get the squared length of vector.
Definition vector_2d.h:139
bool equals(const Vector2D &other) const
check if this vector is strictly same as given vector.
Definition vector_2d.h:531
double absX() const
get absolute x value
Definition vector_2d.h:221
double outerProduct(const Vector2D &v) const
get virtal outer(cross) product with 'v'.
Definition vector_2d.h:511
Vector2D reversedVector() const
get reversed vector.
Definition vector_2d.h:388
bool equalsWeakly(const Vector2D &other) const
check if this vector is weakly same as given vector.
Definition vector_2d.h:542
const Vector2D & operator/=(const double &scalar)
divided by 'scalar'.
Definition vector_2d.h:338
Vector2D(const double &xx, const double &yy)
create Vector with XY value directly.
Definition vector_2d.h:80
const rcsc::Vector2D operator-(const rcsc::Vector2D &lhs, const rcsc::Vector2D &rhs)
operator sub(T, T)
Definition vector_2d.h:877
bool operator<=(const rcsc::Vector2D &lhs, const T &rhs)
never used
const rcsc::Vector2D operator/(const rcsc::Vector2D &lhs, const double &rhs)
operator div(T, U)
Definition vector_2d.h:907
bool operator==(const rcsc::Vector2D &lhs, const rcsc::Vector2D &rhs)
check vectors are strictly same or not.
Definition vector_2d.h:827
std::ostream & operator<<(std::ostream &os, const rcsc::Vector2D &v)
stream operator
Definition vector_2d.h:1007
bool operator!=(const rcsc::Vector2D &lhs, const rcsc::Vector2D &rhs)
check vectors are strictly different or not.
Definition vector_2d.h:843
const rcsc::Vector2D operator+(const rcsc::Vector2D &lhs, const rcsc::Vector2D &rhs)
operator add(T, T)
Definition vector_2d.h:862
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:892
bool operator>=(const rcsc::Vector2D &lhs, const T &rhs)
never used