Jpp  16.0.0-rc.1
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Friends | List of all members
JGEOMETRY2D::JSegment2D Class Reference

Line segment in two dimensions. More...

#include <JSegment2D.hh>

Inheritance diagram for JGEOMETRY2D::JSegment2D:
std::pair< JFirst_t, JSecond_t >

Public Member Functions

 JSegment2D ()
 Default constructor. More...
 
 JSegment2D (const JVector2D &A, const JVector2D &B)
 Constructor. More...
 
double getLengthSquared () const
 Get length squared. More...
 
double getLength () const
 Get length. More...
 
bool intersects (const JSegment2D &segment) const
 Test whether two line segments intersect. More...
 
JVector2D getIntersection (const JSegment2D &segment) const
 Get intersection of two line segments. More...
 
double getDistanceSquared (const JVector2D &point) const
 Get squared of distance to point. More...
 
double getDistance (const JVector2D &point) const
 Get distance to point. More...
 
double getDot (const JSegment2D &segment) const
 Get dot product. More...
 

Friends

JReaderoperator>> (JReader &in, JSegment2D &segment)
 Read segment from input. More...
 
JWriteroperator<< (JWriter &out, const JSegment2D &segment)
 Write segment to output. More...
 

Detailed Description

Line segment in two dimensions.

Definition at line 35 of file JSegment2D.hh.

Constructor & Destructor Documentation

JGEOMETRY2D::JSegment2D::JSegment2D ( )
inline

Default constructor.

Definition at line 42 of file JSegment2D.hh.

42  :
43  JSegment2D_t()
44  {}
std::pair< JPosition2D, JPosition2D > JSegment2D_t
Type definition of line segment in two dimensions.
Definition: JSegment2D.hh:29
JGEOMETRY2D::JSegment2D::JSegment2D ( const JVector2D A,
const JVector2D B 
)
inline

Constructor.

Parameters
Astart position
Bend position

Definition at line 53 of file JSegment2D.hh.

54  :
55  JSegment2D_t(A,B)
56  {}
std::pair< JPosition2D, JPosition2D > JSegment2D_t
Type definition of line segment in two dimensions.
Definition: JSegment2D.hh:29

Member Function Documentation

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

Get length squared.

Returns
square of length

Definition at line 64 of file JSegment2D.hh.

65  {
66  return JVector2D(this->second - this->first).getLengthSquared();
67  }
Data structure for vector in two dimensions.
Definition: JVector2D.hh:32
double getLengthSquared() const
Get length squared.
Definition: JVector2D.hh:188
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
double JGEOMETRY2D::JSegment2D::getLength ( ) const
inline

Get length.

Returns
length

Definition at line 75 of file JSegment2D.hh.

76  {
77  return sqrt(getLengthSquared());
78  }
double getLengthSquared() const
Get length squared.
Definition: JSegment2D.hh:64
bool JGEOMETRY2D::JSegment2D::intersects ( const JSegment2D segment) const
inline

Test whether two line segments intersect.

Parameters
segmentline segment
Returns
true if two line segment intersect; else false

Definition at line 87 of file JSegment2D.hh.

88  {
89  return (getCCW(this->first, segment.first, this->second) != getCCW(this->first, segment.second, this->second) &&
90  getCCW(segment.first, this->first, segment.second) != getCCW(segment.first, this->second, segment.second));
91  }
then usage $script< detector file >< detectorfile > nIf the range of floors is the first detector file is aligned to the second before the comparison nIn this
bool getCCW(const T &a, const T &b, const T &c)
Check sequence of three points in X-Y plane.
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
JVector2D JGEOMETRY2D::JSegment2D::getIntersection ( const JSegment2D segment) const
inline

Get intersection of two line segments.

Parameters
segmentline segment
Returns
intersection point

Definition at line 100 of file JSegment2D.hh.

101  {
102  JVector2D da(this->second - this->first);
103  JVector2D db(segment.second - segment.first);
104 
105  const double gp = JMATH::getPerpDot(da, db);
106 
107  if (gp != 0.0) {
108 
109  da.mul(JMATH::getPerpDot(segment.second, segment.first));
110  db.mul(JMATH::getPerpDot(this->second, this->first));
111 
112  db.sub(da);
113  db.div(gp);
114 
115  return db;
116 
117  } else {
118  throw JDivisionByZero("JSegment2D::getIntersection()");
119  }
120  }
Data structure for vector in two dimensions.
Definition: JVector2D.hh:32
double getPerpDot(const JFirst_t &first, const JSecond_t &second)
Get perpendicular dot product of objects.
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
double JGEOMETRY2D::JSegment2D::getDistanceSquared ( const JVector2D point) const
inline

Get squared of distance to point.

Parameters
pointpoint
Returns
square of distance

Definition at line 129 of file JSegment2D.hh.

130  {
131  JVector2D D(this->second - this->first);
132 
133  const double gp = D.getLengthSquared();
134 
135  if (gp != 0.0) {
136 
137  const JVector2D U(point - this->first);
138 
139  double u = D.getDot(U);
140 
141  if (u < 0.0)
142  u = 0.0;
143  else if (u > gp)
144  u = 1.0;
145  else
146  u /= gp;
147 
148  D.mul(u);
149  D.sub(U);
150 
151  return D.getLengthSquared();
152 
153  } else {
154 
155  return first.getDistanceSquared(point);
156  }
157  }
Data structure for vector in two dimensions.
Definition: JVector2D.hh:32
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first
double u[N+1]
Definition: JPolint.hh:755
do echo Generating $dir eval D
Definition: JDrawLED.sh:53
double JGEOMETRY2D::JSegment2D::getDistance ( const JVector2D point) const
inline

Get distance to point.

Parameters
pointpoint
Returns
distance

Definition at line 166 of file JSegment2D.hh.

167  {
168  return sqrt(getDistanceSquared(point));
169  }
double getDistanceSquared(const JVector2D &point) const
Get squared of distance to point.
Definition: JSegment2D.hh:129
double JGEOMETRY2D::JSegment2D::getDot ( const JSegment2D segment) const
inline

Get dot product.

Parameters
segmentsegment
Returns
dot product

Definition at line 178 of file JSegment2D.hh.

179  {
180  return JVector2D(this->second - this->first).getDot(segment.second - segment.first);
181  }
Data structure for vector in two dimensions.
Definition: JVector2D.hh:32
double getDot(const JVector2D &point) const
Get dot product.
Definition: JVector2D.hh:235
then echo The file $DIR KM3NeT_00000001_00000000 root already please rename or remove it first

Friends And Related Function Documentation

JReader& operator>> ( JReader in,
JSegment2D segment 
)
friend

Read segment from input.

Parameters
inreader
segmentsegment
Returns
reader

Definition at line 191 of file JSegment2D.hh.

192  {
193  in >> segment.first;
194  in >> segment.second;
195 
196  return in;
197  }
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:42
JWriter& operator<< ( JWriter out,
const JSegment2D segment 
)
friend

Write segment to output.

Parameters
outwriter
segmentsegment
Returns
writer

Definition at line 207 of file JSegment2D.hh.

208  {
209  out << segment.first;
210  out << segment.second;
211 
212  return out;
213  }

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