OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Public Member Functions | Public Attributes | Friends | List of all members
ossimLine Class Reference

#include <ossimLine.h>

Public Member Functions

 ossimLine (const ossimDpt &p1=ossimDpt(0, 0), const ossimDpt &p2=ossimDpt(0, 0))
 
ossimDpt getVector () const
 
ossimDpt intersectInfinite (const ossimLine &line) const
 
ossimDpt intersectSegment (const ossimLine &line) const
 
ossimDpt midPoint () const
 
double length () const
 
ossimDpt normal () const
 
bool isPointWithin (const ossimDpt &point, double delta=FLT_EPSILON) const
 
bool isPointOnInfiniteLine (const ossimDpt &point, double delta=FLT_EPSILON) const
 

Public Attributes

ossimDpt theP1
 
ossimDpt theP2
 

Friends

OSSIM_DLL std::ostream & operator<< (std::ostream &out, const ossimLine &rhs)
 

Detailed Description

Definition at line 14 of file ossimLine.h.

Constructor & Destructor Documentation

◆ ossimLine()

ossimLine::ossimLine ( const ossimDpt p1 = ossimDpt(0,0),
const ossimDpt p2 = ossimDpt(0,0) 
)
inline

Definition at line 19 of file ossimLine.h.

21  :theP1(p1),
22  theP2(p2)
23  {
24  }
ossimDpt theP1
Definition: ossimLine.h:77
ossimDpt theP2
Definition: ossimLine.h:78

Member Function Documentation

◆ getVector()

ossimDpt ossimLine::getVector ( ) const
inline

Definition at line 27 of file ossimLine.h.

28  {
29  return (theP2-theP1);
30  }
ossimDpt theP1
Definition: ossimLine.h:77
ossimDpt theP2
Definition: ossimLine.h:78

◆ intersectInfinite()

ossimDpt ossimLine::intersectInfinite ( const ossimLine line) const

Computes the following equation:

Note: this object will be line a and the passed in object will be line b; and P1 and P2 coorespond to this object and P3 and P4 will coorespond to the passed in object.

Now find point formed at the intersection of line a and b:

Pa = P1 + ua ( P2 - P1 ) Pb = P3 + ub ( P4 - P3 ) const ossimDpt& ul_corner, const ossimDpt& lr_corner, ossimCoordSysOrientMode mode=OSSIM_LEFT_HANDED); x1 + ua (x2 - x1) = x3 + ub (x4 - x3) and y1 + ua (y2 - y1) = y3 + ub (y4 - y3)

Solve: ua = ((x4-x3)(y1-y3) - (y4-y3)(x1-x3))/ ((y4-y3)(x2-x1) - (x4-x3)(y2-y1)) ub = ((x2-x1)(y1-y3) - (y2-y1)(x1-x3))/ ((y4-y3)(x2-x1) - (x4-x3)(y2-y1)) substitute:

x = x1 + ua (x2 - x1) y = y1 + ua (y2 - y1)

Definition at line 20 of file ossimLine.cpp.

References FLT_EPSILON, ossimDpt::makeNan(), theP1, theP2, ossimDpt::x, and ossimDpt::y.

Referenced by ossimFeatherMosaic::ossimFeatherInputInformation::setVertexList().

21 {
22  ossimDpt result;
23  ossimDpt p3 = line.theP1;
24  ossimDpt p4 = line.theP2;
25 
26  double numerator = ((p4.x-p3.x)*(theP1.y-p3.y) - (p4.y-p3.y)*(theP1.x-p3.x));
27  double denominator = ((p4.y-p3.y)*(theP2.x-theP1.x) - (p4.x-p3.x)*(theP2.y-theP1.y));
28  result.makeNan();
29  // as long as the lines are not parallel
30  if(fabs(denominator) > FLT_EPSILON)
31  {
32  double ua = numerator/ denominator;
33  result = ossimDpt(theP1.x + ua*(theP2.x-theP1.x),
34  theP1.y + ua*(theP2.y-theP1.y));
35  }
36 
37  return result;
38 }
ossimDpt theP1
Definition: ossimLine.h:77
double y
Definition: ossimDpt.h:165
#define FLT_EPSILON
ossimDpt theP2
Definition: ossimLine.h:78
double x
Definition: ossimDpt.h:164
void makeNan()
Definition: ossimDpt.h:65

◆ intersectSegment()

ossimDpt ossimLine::intersectSegment ( const ossimLine line) const

Definition at line 40 of file ossimLine.cpp.

References FLT_EPSILON, length(), ossimDpt::makeNan(), theP1, theP2, ossimDpt::x, and ossimDpt::y.

41 {
42  ossimDpt result;
43  ossimDpt p3 = line.theP1;
44  ossimDpt p4 = line.theP2;
45 
46  double numerator = ((p4.x-p3.x)*(theP1.y-p3.y) - (p4.y-p3.y)*(theP1.x-p3.x));
47  double denominator = ((p4.y-p3.y)*(theP2.x-theP1.x) - (p4.x-p3.x)*(theP2.y-theP1.y));
48  result.makeNan();
49  // as long as the lines are not parallel
50  if(fabs(denominator) > FLT_EPSILON)
51  {
52  double ua = numerator/ denominator;
53 
54  if((ua >= -FLT_EPSILON) && (ua <= (1.0 + FLT_EPSILON)))
55  {
56  ossimDpt test = ossimDpt(theP1.x + ua*(theP2.x-theP1.x),
57  theP1.y + ua*(theP2.y-theP1.y));
58  ossimDpt midPoint = line.theP1 + (line.theP2-line.theP1)*.5;
59  if( ((test-midPoint).length()/line.length()) <= (.5+FLT_EPSILON))
60  {
61  result = test;
62  }
63  }
64  }
65 
66  return result;
67 }
ossimDpt theP1
Definition: ossimLine.h:77
double y
Definition: ossimDpt.h:165
#define FLT_EPSILON
ossimDpt theP2
Definition: ossimLine.h:78
ossimDpt midPoint() const
Definition: ossimLine.cpp:74
double x
Definition: ossimDpt.h:164
double length() const
Definition: ossimLine.cpp:69
void makeNan()
Definition: ossimDpt.h:65

◆ isPointOnInfiniteLine()

bool ossimLine::isPointOnInfiniteLine ( const ossimDpt point,
double  delta = FLT_EPSILON 
) const

Definition at line 99 of file ossimLine.cpp.

References FLT_EPSILON, ossimDpt::length(), ossimDpt::x, and ossimDpt::y.

100 {
101  if((point == theP1) || (point == theP2))
102  {
103  return true;
104  }
105  else if(fabs(theP1.x-theP2.x) <= FLT_EPSILON)
106  {
107  return (fabs(point.x - theP1.x) <= delta);
108  }
109  else if(fabs(theP1.y-theP2.y) <= FLT_EPSILON)
110  {
111  return (fabs(point.y - theP1.y) <= delta);
112  }
113  else
114  {
115  ossimDpt v1 = getVector();
116  v1 = v1 * (1.0/v1.length());
117  ossimDpt v2 = (point - theP1);
118  double s = v1.x*v2.x + v1.y*v2.y;
119  ossimDpt p = theP1 + v1*s;
120  double len = (point-p).length();
121 
122  if(len < delta)
123  {
124  return true;
125  }
126  else
127  {
128  return false;
129  }
130  }
131 
132  return false;
133 }
ossimDpt theP1
Definition: ossimLine.h:77
double y
Definition: ossimDpt.h:165
ossimDpt getVector() const
Definition: ossimLine.h:27
double length() const
Definition: ossimDpt.h:81
#define FLT_EPSILON
ossimDpt theP2
Definition: ossimLine.h:78
double x
Definition: ossimDpt.h:164
double length() const
Definition: ossimLine.cpp:69

◆ isPointWithin()

bool ossimLine::isPointWithin ( const ossimDpt point,
double  delta = FLT_EPSILON 
) const

Will return true if the point is on the line.

Definition at line 79 of file ossimLine.cpp.

References max, min, and ossimDrect::pointWithin().

Referenced by ossimPolyLine::isPointWithin().

80 {
81  if(isPointOnInfiniteLine(point, delta))
82  {
83  double minx = std::min(theP1.x, theP2.x);
84  double miny = std::min(theP1.y, theP2.y);
85  double maxx = std::max(theP1.x, theP2.x);
86  double maxy = std::max(theP1.y, theP2.y);
87 
88  ossimDrect rect(minx - delta,
89  miny - delta,
90  maxx + delta,
91  maxy + delta);
92 
93  return rect.pointWithin(point);
94  }
95 
96  return false;
97 }
ossimDpt theP1
Definition: ossimLine.h:77
double y
Definition: ossimDpt.h:165
ossimDpt theP2
Definition: ossimLine.h:78
bool isPointOnInfiniteLine(const ossimDpt &point, double delta=FLT_EPSILON) const
Definition: ossimLine.cpp:99
#define max(a, b)
Definition: auxiliary.h:76
double x
Definition: ossimDpt.h:164
#define min(a, b)
Definition: auxiliary.h:75

◆ length()

double ossimLine::length ( ) const

Definition at line 69 of file ossimLine.cpp.

Referenced by intersectSegment().

70 {
71  return (theP2-theP1).length();
72 }
ossimDpt theP1
Definition: ossimLine.h:77
ossimDpt theP2
Definition: ossimLine.h:78

◆ midPoint()

ossimDpt ossimLine::midPoint ( ) const

Definition at line 74 of file ossimLine.cpp.

75 {
76  return (theP1 + (theP2-theP1)*.5);
77 }
ossimDpt theP1
Definition: ossimLine.h:77
ossimDpt theP2
Definition: ossimLine.h:78

◆ normal()

ossimDpt ossimLine::normal ( ) const

Definition at line 135 of file ossimLine.cpp.

References FLT_EPSILON, ossimDpt::length(), ossimDpt::x, and ossimDpt::y.

Referenced by ossimPolygon::clipLineSegment().

136 {
137  ossimDpt delta = getVector();
138  ossimDpt result;
139  if(fabs(delta.x) <= FLT_EPSILON)
140  {
141  result.y = 0.0;
142  result.x = -delta.y;
143  }
144  else if(fabs(delta.y) <= FLT_EPSILON)
145  {
146  result.x = 0.0;
147  result.y = delta.x;
148  }
149  else
150  {
151  result.x = -delta.y;
152  result.y = delta.x;
153  }
154  double len = result.length();
155 
156  if(len >FLT_EPSILON)
157  {
158  result = result*(1.0/len);
159  }
160 
161  return result;
162 }
double y
Definition: ossimDpt.h:165
ossimDpt getVector() const
Definition: ossimLine.h:27
double length() const
Definition: ossimDpt.h:81
#define FLT_EPSILON
double x
Definition: ossimDpt.h:164

Friends And Related Function Documentation

◆ operator<<

OSSIM_DLL std::ostream& operator<< ( std::ostream &  out,
const ossimLine rhs 
)
friend

Definition at line 15 of file ossimLine.cpp.

16 {
17  return out << "line: " << rhs.theP1 << "," << rhs.theP2 << endl;
18 }
ossimDpt theP1
Definition: ossimLine.h:77
ossimDpt theP2
Definition: ossimLine.h:78

Member Data Documentation

◆ theP1

ossimDpt ossimLine::theP1

◆ theP2

ossimDpt ossimLine::theP2

Definition at line 78 of file ossimLine.h.

Referenced by intersectInfinite(), intersectSegment(), and operator<<().


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