GeoTessCPP  2.2.3
Software to facilitate storage and retrieval of 3D information about the Earth.
GeoTessGreatCircle.h
Go to the documentation of this file.
1 //- ****************************************************************************
2 //-
3 //- Copyright 2009 National Technology & Engineering Solutions of Sandia, LLC
4 //- (NTESS). Under the terms of Contract DE-NA0003525 with NTESS, the U.S.
5 //- Government retains certain rights in this software.
6 //-
7 //- BSD Open Source License
8 //- All rights reserved.
9 //-
10 //- Redistribution and use in source and binary forms, with or without
11 //- modification, are permitted provided that the following conditions are met:
12 //-
13 //- 1. Redistributions of source code must retain the above copyright notice,
14 //- this list of conditions and the following disclaimer.
15 //-
16 //- 2. Redistributions in binary form must reproduce the above copyright
17 //- notice, this list of conditions and the following disclaimer in the
18 //- documentation and/or other materials provided with the distribution.
19 //-
20 //- 3. Neither the name of the copyright holder nor the names of its
21 //- contributors may be used to endorse or promote products derived from
22 //- this software without specific prior written permission.
23 //-
24 //- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 //- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 //- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 //- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
28 //- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 //- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 //- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 //- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 //- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 //- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 //- POSSIBILITY OF SUCH DAMAGE.
35 //-
36 //- ****************************************************************************
37 
38 #ifndef GREATCIRCLE_H_
39 #define GREATCIRCLE_H_
40 
41 // **** _SYSTEM INCLUDES_ ******************************************************
42 
43 //#include <cstdio>
44 #include <iostream>
45 #include <string>
46 
47 // use standard library objects
48 using namespace std;
49 
50 // **** _LOCAL INCLUDES_ *******************************************************
51 
52 #include "CPPUtils.h"
53 #include "GeoTessUtils.h"
54 
55 // **** _BEGIN GEOTESS NAMESPACE_ **********************************************
56 
57 namespace geotess {
58 
59 // **** _FORWARD REFERENCES_ ***************************************************
60 
61 // **** _CLASS DEFINITION_ *****************************************************
62 
171 {
172  private:
173 
180  double distance;
181 
185  double* firstPoint;
186 
190  double* lastPoint;
191 
196  double normal[3];
197 
203  double moveDirection[3];
204 
208  bool deleteFirst;
209 
213  bool deleteLast;
214 
224  double** trnsfrm;
225 
226  void initialize(const double* intermediatePoint, const bool &shortestPath);
227 
228  void clear();
229 
230  public:
231 
233 
237  GeoTessGreatCircle() : firstPoint(NULL), lastPoint(NULL), deleteFirst(true), deleteLast(true), trnsfrm(NULL)
238  {}
239 
252  GeoTessGreatCircle(const double* firstPoint, const double& distance, const double& direction);
253 
285  GeoTessGreatCircle(const double* firstPoint, const double* intermediatePoint, const double* lastPoint,
286  const bool &shortestPath=true);
287 
304  GeoTessGreatCircle(const double* firstPoint, const double* lastPoint, const bool &shortestPath=true);
305 
311 
316  void operator= (GeoTessGreatCircle& other);
317 
322  bool operator == (const GeoTessGreatCircle& other) const
323  {
324  return firstPoint[0] == other.firstPoint[0]
325  && firstPoint[1] == other.firstPoint[1]
326  && firstPoint[2] == other.firstPoint[2]
327  && lastPoint[0] == other.lastPoint[0]
328  && lastPoint[1] == other.lastPoint[1]
329  && lastPoint[2] == other.lastPoint[2]
330  && normal[0] == other.normal[0]
331  && normal[1] == other.normal[1]
332  && normal[2] == other.normal[2];
333  };
334 
335 
370  void set(double* firstPoint, double* intermediatePoint, double* lastPoint,
371  const bool& shortestPath=true, const bool& deleteWhenDone=false);
372 
394  void set(double* frstPoint, double* lstPoint,
395  const bool& shortestPath=true, const bool& deleteWhenDone=false)
396  { set (frstPoint, NULL, lstPoint, shortestPath, deleteWhenDone); }
397 
413  void set(double* firstPoint, const double& distance, const double& azimuth,
414  const bool& deleteWhenDone=false);
415 
421  double getDistance()
422  {
423  if (distance < 0.)
424  {
425  distance = GeoTessUtils::angle(firstPoint, lastPoint);
426  if (GeoTessUtils::scalarTripleProduct(firstPoint, lastPoint, normal) < 0.)
427  distance = 2*PI - distance;
428  }
429  return distance;
430  }
431 
438  {
439  return CPPUtils::toDegrees(getDistance());
440  }
441 
451  double getDistance(const double *position)
452  {
453  // find the shortest distance from firstPoint to unit vector
454  double d = GeoTessUtils::angle(firstPoint, position);
455 
456  if (GeoTessUtils::scalarTripleProduct(firstPoint, position, normal) < 0.)
457  d = 2 * PI - d;
458 
459  return d;
460  }
461 
472  double getDistanceDegrees(const double *position)
473  {
474  return CPPUtils::toDegrees(getDistance(position));
475  }
476 
484  double* getFirst()
485  {
486  return firstPoint;
487  }
488 
496  double* getLast()
497  {
498  return lastPoint;
499  }
500 
510  const double* getNormal()
511  {
512  return normal;
513  }
514 
526  double* getPoint(const double &dist)
527  {
528  double* location = new double[3];
529  GeoTessUtils::move(firstPoint, moveDirection, dist, location);
530  return location;
531  }
532 
542  void getPoint(const double &dist, double* location)
543  {
544  GeoTessUtils::move(firstPoint, moveDirection, dist, location);
545  }
546 
561  static int getNPoints(const double& dist, const double& spacing, const bool& onCenters=false)
562  {
563  if (dist <= 0.) return onCenters ? 1 : 2;
564  return onCenters ? (int)ceil(dist/spacing) : ((int)ceil(dist/spacing))+1;
565  }
566 
580  int getNPoints(const double& spacing, const bool& onCenters=false)
581  {
582  return getNPoints(getDistance(), spacing, onCenters);
583  }
584 
603  double getPoints(double** points, const int &npoints, const bool& onCenters=false)
604  {
605  double dx;
606  if (onCenters)
607  {
608  dx = getDistance()/npoints;
609  for (int i=0; i<npoints; ++i) getPoint((i+0.5)*dx, points[i]);
610  }
611  else
612  {
613  dx = getDistance()/(npoints-1);
614  for (int i=0; i<npoints; ++i) getPoint(i*dx, points[i]);
615  }
616  return dx;
617  }
618 
640  double getPoints(const double &spacing, double** points, int &npoints, const bool& onCenters=false)
641  {
642  npoints = getNPoints(spacing, onCenters);
643 
644  double dx;
645  if (onCenters)
646  {
647  dx = getDistance()/npoints;
648  for (int i=0; i<npoints; ++i) getPoint((i+0.5)*dx, points[i]);
649  }
650  else
651  {
652  dx = getDistance()/(npoints-1);
653  for (int i=0; i<npoints; ++i) getPoint(i*dx, points[i]);
654  }
655  return dx;
656  }
657 
683  bool getIntersection(GeoTessGreatCircle& other, const bool& inRange, double* intersection)
684  {
685  if (GeoTessUtils::crossNormal(normal, other.normal, intersection) == 0.)
686  {
687  intersection[0] = intersection[1] = intersection[2] = NaN_DOUBLE;
688  return false;
689  }
690 
691  if (GeoTessUtils::scalarTripleProduct(firstPoint, intersection, normal) < 0.)
692  {
693  intersection[0] = -intersection[0];
694  intersection[1] = -intersection[1];
695  intersection[2] = -intersection[2];
696  }
697 
698  if (inRange && (getDistance(intersection) >= getDistance()
699  || other.getDistance(intersection) >= other.getDistance()))
700  {
701  intersection[0] = intersection[1] = intersection[2] = NaN_DOUBLE;
702  return false;
703  }
704 
705  return true;
706  }
707 
722  double** getTransform();
723 
744  void transform(const double* x, double* v)
745  {
746  // make sure that trnsfrm has been calculated
747  getTransform();
748  v[0] = x[0] * trnsfrm[0][0] + x[1] * trnsfrm[0][1] + x[2]
749  * trnsfrm[0][2];
750  v[1] = x[0] * trnsfrm[1][0] + x[1] * trnsfrm[1][1] + x[2]
751  * trnsfrm[1][2];
752  v[2] = x[0] * trnsfrm[2][0] + x[1] * trnsfrm[2][1] + x[2]
753  * trnsfrm[2][2];
754  }
755 
777  double* transform(const double* x)
778  {
779  double* v = new double[3];
780  transform(x, v);
781  return v;
782  }
783 
784  string toString();
785 
786 }; // end class GreatCircle
787 
788 } // end namespace geotess
789 
790 #endif /* GREATCIRCLE_H_ */
geotess::GeoTessGreatCircle::getFirst
double * getFirst()
Definition: GeoTessGreatCircle.h:484
geotess::GeoTessGreatCircle::getPoints
double getPoints(const double &spacing, double **points, int &npoints, const bool &onCenters=false)
Definition: GeoTessGreatCircle.h:640
geotess
Definition: ArrayReuse.h:57
geotess::GeoTessGreatCircle::getLast
double * getLast()
Definition: GeoTessGreatCircle.h:496
geotess::GeoTessGreatCircle::set
void set(double *frstPoint, double *lstPoint, const bool &shortestPath=true, const bool &deleteWhenDone=false)
Definition: GeoTessGreatCircle.h:394
geotess::GeoTessGreatCircle::getTransform
double ** getTransform()
geotess::GeoTessGreatCircle::getPoint
void getPoint(const double &dist, double *location)
Definition: GeoTessGreatCircle.h:542
geotess::GeoTessGreatCircle::getPoint
double * getPoint(const double &dist)
Definition: GeoTessGreatCircle.h:526
geotess::GeoTessGreatCircle::getNormal
const double * getNormal()
Definition: GeoTessGreatCircle.h:510
geotess::GeoTessGreatCircle::getPoints
double getPoints(double **points, const int &npoints, const bool &onCenters=false)
Definition: GeoTessGreatCircle.h:603
geotess::GeoTessGreatCircle::getDistance
double getDistance()
Definition: GeoTessGreatCircle.h:421
geotess::GeoTessGreatCircle::set
void set(double *firstPoint, double *intermediatePoint, double *lastPoint, const bool &shortestPath=true, const bool &deleteWhenDone=false)
geotess::GeoTessGreatCircle::set
void set(double *firstPoint, const double &distance, const double &azimuth, const bool &deleteWhenDone=false)
geotess::GeoTessGreatCircle::getDistance
double getDistance(const double *position)
Definition: GeoTessGreatCircle.h:451
geotess::GeoTessGreatCircle::~GeoTessGreatCircle
virtual ~GeoTessGreatCircle()
geotess::GeoTessGreatCircle::getDistanceDegrees
double getDistanceDegrees()
Definition: GeoTessGreatCircle.h:437
geotess::GeoTessGreatCircle::getNPoints
int getNPoints(const double &spacing, const bool &onCenters=false)
Definition: GeoTessGreatCircle.h:580
GeoTessUtils.h
geotess::GeoTessGreatCircle
Manages information about a great circle path that extends from one point to another point,...
Definition: GeoTessGreatCircle.h:171
geotess::GeoTessGreatCircle::getNPoints
static int getNPoints(const double &dist, const double &spacing, const bool &onCenters=false)
Definition: GeoTessGreatCircle.h:561
geotess::GeoTessGreatCircle::transform
void transform(const double *x, double *v)
Definition: GeoTessGreatCircle.h:744
geotess::GeoTessGreatCircle::transform
double * transform(const double *x)
Definition: GeoTessGreatCircle.h:777
geotess::GeoTessGreatCircle::GeoTessGreatCircle
GeoTessGreatCircle(const double *firstPoint, const double *intermediatePoint, const double *lastPoint, const bool &shortestPath=true)
GEOTESS_EXP_IMP
#define GEOTESS_EXP_IMP
Definition: CPPGlobals.h:73
geotess::GeoTessGreatCircle::toString
string toString()
geotess::GeoTessGreatCircle::GeoTessGreatCircle
GeoTessGreatCircle(const double *firstPoint, const double &distance, const double &direction)
geotess::GeoTessGreatCircle::getDistanceDegrees
double getDistanceDegrees(const double *position)
Definition: GeoTessGreatCircle.h:472
geotess::GeoTessGreatCircle::GeoTessGreatCircle
GeoTessGreatCircle(const double *firstPoint, const double *lastPoint, const bool &shortestPath=true)
geotess::GeoTessGreatCircle::getIntersection
bool getIntersection(GeoTessGreatCircle &other, const bool &inRange, double *intersection)
Definition: GeoTessGreatCircle.h:683
CPPUtils.h
geotess::GeoTessGreatCircle::GeoTessGreatCircle
GeoTessGreatCircle()
Definition: GeoTessGreatCircle.h:237
geotess::GeoTessGreatCircle::GeoTessGreatCircle
GeoTessGreatCircle(GeoTessGreatCircle &other)