GeoTessCPP  2.0.0
Software to facilitate storage and retrieval of 3D information about the Earth.
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros
GreatCircle.h
Go to the documentation of this file.
1 //- ****************************************************************************
2 //-
3 //- Copyright 2009 Sandia Corporation. Under the terms of Contract
4 //- DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
5 //- 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 //- * Redistributions of source code must retain the above copyright notice,
14 //- this list of conditions and the following disclaimer.
15 //- * Redistributions in binary form must reproduce the above copyright
16 //- notice, this list of conditions and the following disclaimer in the
17 //- documentation and/or other materials provided with the distribution.
18 //- * Neither the name of Sandia National Laboratories nor the names of its
19 //- contributors may be used to endorse or promote products derived from
20 //- this software without specific prior written permission.
21 //-
22 //- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 //- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 //- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 //- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
26 //- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 //- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 //- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 //- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 //- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 //- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 //- POSSIBILITY OF SUCH DAMAGE.
33 //-
34 //- ****************************************************************************
35 
36 #ifndef GREATCIRCLE_H_
37 #define GREATCIRCLE_H_
38 
39 // **** _SYSTEM INCLUDES_ ******************************************************
40 
41 //#include <cstdio>
42 #include <iostream>
43 #include <string>
44 
45 // use standard library objects
46 using namespace std;
47 
48 // **** _LOCAL INCLUDES_ *******************************************************
49 
50 #include "CPPUtils.h"
51 #include "GeoTessUtils.h"
52 
53 // **** _BEGIN GEOTESS NAMESPACE_ **********************************************
54 
55 namespace geotess {
56 
57 // **** _FORWARD REFERENCES_ ***************************************************
58 
59 // **** _CLASS DEFINITION_ *****************************************************
60 
167 {
168  private:
169 
176  double distance;
177 
181  double* firstPoint;
182 
186  double* lastPoint;
187 
192  double normal[3];
193 
199  double moveDirection[3];
200 
204  bool deleteFirst;
205 
209  bool deleteLast;
210 
220  double** trnsfrm;
221 
222  void initialize(const double* intermediatePoint, const bool &shortestPath);
223 
224  void clear();
225 
226  public:
227 
228  virtual ~GreatCircle();
229 
233  GreatCircle() : firstPoint(NULL), lastPoint(NULL), deleteFirst(true), deleteLast(true), trnsfrm(NULL)
234  {}
235 
248  GreatCircle(const double* firstPoint, const double& distance, const double& direction);
249 
281  GreatCircle(const double* firstPoint, const double* intermediatePoint, const double* lastPoint,
282  const bool &shortestPath=true);
283 
300  GreatCircle(const double* firstPoint, const double* lastPoint, const bool &shortestPath=true);
301 
306  GreatCircle(GreatCircle& other);
307 
308  void operator = (GreatCircle& other);
309 
313  bool operator == (const GreatCircle& other) const
314  {
315  return firstPoint[0] == other.firstPoint[0]
316  && firstPoint[1] == other.firstPoint[1]
317  && firstPoint[2] == other.firstPoint[2]
318  && lastPoint[0] == other.lastPoint[0]
319  && lastPoint[1] == other.lastPoint[1]
320  && lastPoint[2] == other.lastPoint[2]
321  && normal[0] == other.normal[0]
322  && normal[1] == other.normal[1]
323  && normal[2] == other.normal[2];
324  };
325 
326 
327  void set(double* firstPoint, double* intermediatePoint, double* lastPoint,
328  const bool& shortestPath=true, const bool& deleteWhenDone=true);
329 
330  void set(double* frstPoint, double* lstPoint,
331  const bool& shortestPath=true, const bool& deleteWhenDone=true)
332  { set (frstPoint, NULL, lstPoint, shortestPath, deleteWhenDone); }
333 
334  void set(double* firstPoint, const double& distance, const double& azimuth,
335  const bool& deleteWhenDone=true);
336 
342  double getDistance()
343  {
344  if (distance < 0.)
345  {
346  distance = GeoTessUtils::angle(firstPoint, lastPoint);
347  if (GeoTessUtils::scalarTripleProduct(firstPoint, lastPoint, normal) < 0.)
348  distance = 2*PI - distance;
349  }
350  return distance;
351  }
352 
358  double getDistanceDegrees()
359  {
360  return CPPUtils::toDegrees(getDistance());
361  }
362 
372  double getDistance(const double *position)
373  {
374  // find the shortest distance from firstPoint to unit vector
375  double d = GeoTessUtils::angle(firstPoint, position);
376 
377  if (GeoTessUtils::scalarTripleProduct(firstPoint, position, normal) < 0.)
378  d = 2 * PI - d;
379 
380  return d;
381  }
382 
393  double getDistanceDegrees(const double *position)
394  {
395  return CPPUtils::toDegrees(getDistance(position));
396  }
397 
405  double* getFirst()
406  {
407  return firstPoint;
408  }
409 
417  double* getLast()
418  {
419  return lastPoint;
420  }
421 
431  const double* getNormal()
432  {
433  return normal;
434  }
435 
447  double* getPoint(const double &dist)
448  {
449  double* location = new double[3];
450  GeoTessUtils::move(firstPoint, moveDirection, dist, location);
451  return location;
452  }
453 
463  void getPoint(const double &dist, double* location)
464  {
465  GeoTessUtils::move(firstPoint, moveDirection, dist, location);
466  }
467 
493  bool getIntersection(GreatCircle& other, const bool& inRange, double* intersection)
494  {
495  if (GeoTessUtils::crossNormal(normal, other.normal, intersection) == 0.)
496  {
497  intersection[0] = intersection[1] = intersection[2] = NaN_DOUBLE;
498  return false;
499  }
500 
501  if (GeoTessUtils::scalarTripleProduct(firstPoint, intersection, normal) < 0.)
502  {
503  intersection[0] = -intersection[0];
504  intersection[1] = -intersection[1];
505  intersection[2] = -intersection[2];
506  }
507 
508  if (inRange && (getDistance(intersection) >= getDistance()
509  || other.getDistance(intersection) >= other.getDistance()))
510  {
511  intersection[0] = intersection[1] = intersection[2] = NaN_DOUBLE;
512  return false;
513  }
514 
515  return true;
516  }
517 
532  double** getTransform();
533 
554  void transform(const double* x, double* v)
555  {
556  // make sure that trnsfrm has been calculated
557  getTransform();
558  v[0] = x[0] * trnsfrm[0][0] + x[1] * trnsfrm[0][1] + x[2]
559  * trnsfrm[0][2];
560  v[1] = x[0] * trnsfrm[1][0] + x[1] * trnsfrm[1][1] + x[2]
561  * trnsfrm[1][2];
562  v[2] = x[0] * trnsfrm[2][0] + x[1] * trnsfrm[2][1] + x[2]
563  * trnsfrm[2][2];
564  }
565 
587  double* transform(const double* x)
588  {
589  double* v = new double[3];
590  transform(x, v);
591  return v;
592  }
593 
594  string toString();
595 
596 }; // end class GreatCircle
597 
598 } // end namespace geotess
599 
600 #endif /* GREATCIRCLE_H_ */