1 /*=============================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkGeoMath.cxx
5 
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notice for more information.
13 
14 =============================================================================*/
15 
16 /*-------------------------------------------------------------------------
17   Copyright 2008 Sandia Corporation.
18   Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
19   the U.S. Government retains certain rights in this software.
20 -------------------------------------------------------------------------*/
21 
22 #include "vtkObjectFactory.h"
23 #include "vtkGeoMath.h"
24 #include "vtkMath.h"
25 
26 vtkStandardNewMacro(vtkGeoMath);
27 
28 
29 //----------------------------------------------------------------------------
vtkGeoMath()30 vtkGeoMath::vtkGeoMath()
31 {
32 }
33 
34 //-----------------------------------------------------------------------------
~vtkGeoMath()35 vtkGeoMath::~vtkGeoMath()
36 {
37 }
38 
39 //-----------------------------------------------------------------------------
PrintSelf(ostream & os,vtkIndent indent)40 void vtkGeoMath::PrintSelf(ostream& os, vtkIndent indent)
41 {
42   this->Superclass::PrintSelf(os,indent);
43 }
44 
45 
46 //-----------------------------------------------------------------------------
DistanceSquared(double pt0[3],double pt1[3])47 double vtkGeoMath::DistanceSquared(double pt0[3], double pt1[3])
48 {
49   double tmp;
50   double d2;
51 
52   tmp = pt1[0] - pt0[0];
53   d2 = tmp * tmp;
54   tmp = pt1[1] - pt0[1];
55   d2 += tmp * tmp;
56   tmp = pt1[2] - pt0[2];
57   d2 += tmp * tmp;
58 
59   return d2;
60 }
61 
62 //-----------------------------------------------------------------------------
LongLatAltToRect(double longLatAlt[3],double rect[3])63 void vtkGeoMath::LongLatAltToRect(double longLatAlt[3], double rect[3])
64 {
65   double theta = vtkMath::RadiansFromDegrees( longLatAlt[0] );
66   double phi   = vtkMath::RadiansFromDegrees( longLatAlt[1] );
67   double cosPhi = cos(phi);
68   double radius = vtkGeoMath::EarthRadiusMeters()+ longLatAlt[2];
69 
70   rect[2] = sin(phi) * radius;
71   rect[1] = cos(theta) * cosPhi * radius;
72   rect[0] = -sin(theta) * cosPhi * radius;
73 }
74 
75