Jpp 19.3.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JGEOMETRY2D::JVector2D Class Reference

Data structure for vector in two dimensions. More...

#include <JVector2D.hh>

Inheritance diagram for JGEOMETRY2D::JVector2D:
JMATH::JMath< JFirst_t, JSecond_t > JGEOMETRY2D::JCenter2D JGEOMETRY2D::JPosition2D JDETECTOR::JAnchor JGEOMETRY2D::JAxis2D JGEOMETRY2D::JCircle2D JGEOMETRY3D::JCylinder3D

Public Member Functions

 JVector2D ()
 Default constructor.
 
 JVector2D (const double x, const double y)
 Constructor.
 
double getX () const
 Get x position.
 
double getY () const
 Get y position.
 
JVector2Dnegate ()
 Negate vector.
 
JVector2Dadd (const JVector2D &vector)
 Add vector.
 
JVector2Dsub (const JVector2D &vector)
 Subtract vector.
 
JVector2Dmul (const double factor)
 Scale vector.
 
JVector2Ddiv (const double factor)
 Scale vector.
 
JVector2Dtransform (const JMatrix2D &T)
 Transform.
 
bool equals (const JVector2D &vector, const double precision=std::numeric_limits< double >::min()) const
 Check equality.
 
double getLengthSquared () const
 Get length squared.
 
double getLength () const
 Get length.
 
double getDistanceSquared (const JVector2D &point) const
 Get squared of distance to point.
 
double getDistance (const JVector2D &point) const
 Get distance to point.
 
double getDot (const JVector2D &point) const
 Get dot product.
 
double getPerpDot (const JVector2D &point) const
 Get perpendicular dot product.
 
JFirst_t & mul (const JSecond_t &object)
 Multiply with object.
 

Protected Attributes

double __x
 
double __y
 

Detailed Description

Data structure for vector in two dimensions.

This class implements the JMATH::JMath interface.

Definition at line 32 of file JVector2D.hh.

Constructor & Destructor Documentation

◆ JVector2D() [1/2]

JGEOMETRY2D::JVector2D::JVector2D ( )
inline

Default constructor.

Definition at line 39 of file JVector2D.hh.

39 :
40 __x(0.0),
41 __y(0.0)
42 {}

◆ JVector2D() [2/2]

JGEOMETRY2D::JVector2D::JVector2D ( const double x,
const double y )
inline

Constructor.

Parameters
xx value
yy value

Definition at line 51 of file JVector2D.hh.

52 :
53 __x(x),
54 __y(y)
55 {}

Member Function Documentation

◆ getX()

double JGEOMETRY2D::JVector2D::getX ( ) const
inline

Get x position.

Returns
x position

Definition at line 63 of file JVector2D.hh.

64 {
65 return __x;
66 }

◆ getY()

double JGEOMETRY2D::JVector2D::getY ( ) const
inline

Get y position.

Returns
y position

Definition at line 74 of file JVector2D.hh.

75 {
76 return __y;
77 }

◆ negate()

JVector2D & JGEOMETRY2D::JVector2D::negate ( )
inline

Negate vector.

Returns
this vector

Definition at line 85 of file JVector2D.hh.

86 {
87 __x = -__x;
88 __y = -__y;
89
90 return *this;
91 }

◆ add()

JVector2D & JGEOMETRY2D::JVector2D::add ( const JVector2D & vector)
inline

Add vector.

Parameters
vectorvector
Returns
this vector

Definition at line 100 of file JVector2D.hh.

101 {
102 __x += vector.getX();
103 __y += vector.getY();
104
105 return *this;
106 }

◆ sub()

JVector2D & JGEOMETRY2D::JVector2D::sub ( const JVector2D & vector)
inline

Subtract vector.

Parameters
vectorvector
Returns
this vector

Definition at line 115 of file JVector2D.hh.

116 {
117 __x -= vector.getX();
118 __y -= vector.getY();
119
120 return *this;
121 }

◆ mul() [1/2]

JVector2D & JGEOMETRY2D::JVector2D::mul ( const double factor)
inline

Scale vector.

Parameters
factormultiplication factor
Returns
this vector

Definition at line 130 of file JVector2D.hh.

131 {
132 __x *= factor;
133 __y *= factor;
134
135 return *this;
136 }

◆ div()

JVector2D & JGEOMETRY2D::JVector2D::div ( const double factor)
inline

Scale vector.

Parameters
factordivision factor
Returns
this vector

Definition at line 145 of file JVector2D.hh.

146 {
147 __x /= factor;
148 __y /= factor;
149
150 return *this;
151 }

◆ transform()

JVector2D & JGEOMETRY2D::JVector2D::transform ( const JMatrix2D & T)
inline

Transform.

Parameters
Tmatrix
Returns
this vector

Definition at line 160 of file JVector2D.hh.

161 {
162 T.transform(__x, __y);
163
164 return *this;
165 }

◆ equals()

bool JGEOMETRY2D::JVector2D::equals ( const JVector2D & vector,
const double precision = std::numeric_limits<double>::min() ) const
inline

Check equality.

Parameters
vectorvector
precisionprecision
Returns
true if vectors are equal; else false

Definition at line 175 of file JVector2D.hh.

177 {
178 return (fabs(getX() - vector.getX()) <= precision &&
179 fabs(getY() - vector.getY()) <= precision);
180 }
double getY() const
Get y position.
Definition JVector2D.hh:74
double getX() const
Get x position.
Definition JVector2D.hh:63

◆ getLengthSquared()

double JGEOMETRY2D::JVector2D::getLengthSquared ( ) const
inline

Get length squared.

Returns
square of length

Definition at line 188 of file JVector2D.hh.

189 {
190 return getX()*getX() + getY()*getY();
191 }

◆ getLength()

double JGEOMETRY2D::JVector2D::getLength ( ) const
inline

Get length.

Returns
length

Definition at line 199 of file JVector2D.hh.

200 {
201 return sqrt(getLengthSquared());
202 }
double getLengthSquared() const
Get length squared.
Definition JVector2D.hh:188

◆ getDistanceSquared()

double JGEOMETRY2D::JVector2D::getDistanceSquared ( const JVector2D & point) const
inline

Get squared of distance to point.

Parameters
pointpoint
Returns
square of distance

Definition at line 211 of file JVector2D.hh.

212 {
213 return JVector2D(point).sub(*this).getLengthSquared();
214 }
JVector2D()
Default constructor.
Definition JVector2D.hh:39

◆ getDistance()

double JGEOMETRY2D::JVector2D::getDistance ( const JVector2D & point) const
inline

Get distance to point.

Parameters
pointpoint
Returns
distance

Definition at line 223 of file JVector2D.hh.

224 {
225 return sqrt(getDistanceSquared(point));
226 }
double getDistanceSquared(const JVector2D &point) const
Get squared of distance to point.
Definition JVector2D.hh:211

◆ getDot()

double JGEOMETRY2D::JVector2D::getDot ( const JVector2D & point) const
inline

Get dot product.

Parameters
pointvector
Returns
dot product

Definition at line 235 of file JVector2D.hh.

236 {
237 return
238 getX() * point.getX() +
239 getY() * point.getY();
240 }

◆ getPerpDot()

double JGEOMETRY2D::JVector2D::getPerpDot ( const JVector2D & point) const
inline

Get perpendicular dot product.

Parameters
pointvector
Returns
perpendicular dot product

Definition at line 249 of file JVector2D.hh.

250 {
251 return
252 getX() * point.getY() -
253 getY() * point.getX();
254 }

◆ mul() [2/2]

template<class JFirst_t , class JSecond_t >
JFirst_t & JMATH::JMath< JFirst_t, JSecond_t >::mul ( const JSecond_t & object)
inlineinherited

Multiply with object.

Parameters
objectobject
Returns
result object

Definition at line 354 of file JMath.hh.

355 {
356 return static_cast<JFirst_t&>(*this) = JFirst_t().mul(static_cast<const JFirst_t&>(*this), object);
357 }

Member Data Documentation

◆ __x

double JGEOMETRY2D::JVector2D::__x
protected

Definition at line 257 of file JVector2D.hh.

◆ __y

double JGEOMETRY2D::JVector2D::__y
protected

Definition at line 258 of file JVector2D.hh.


The documentation for this class was generated from the following file: