Isis 3 Programmer Reference
PlaneShape.cpp
1
6/* SPDX-License-Identifier: CC0-1.0 */
7#include <algorithm>
8#include <cfloat>
9#include <string>
10#include <vector>
11
12#include <cmath>
13#include <iomanip>
14
15#include "PlaneShape.h"
16
17#include "Distance.h"
18#include "IException.h"
19#include "Latitude.h"
20#include "Longitude.h"
21#include "NaifStatus.h"
22#include "ShapeModel.h"
23#include "SurfacePoint.h"
24
25namespace Isis {
31 PlaneShape::PlaneShape(Target *target, Pvl &pvl) : ShapeModel (target) {
32 setName("Plane");
33
34 // set surface normal
35 // setNormal(0.0, 0.0, 1.0);
36 }
37
38
45 setName("Plane");
46
47 // set normal vector
48 // setNormal(0.0, 0.0, 1.0);
49 }
50
51
58 setName("Plane");
59 }
60
61
67
68
77 bool PlaneShape::intersectSurface (std::vector<double> observerPos,
78 std::vector<double> lookDirection) {
80 SpiceDouble zvec[3];
81 SpicePlane plane;
82 SpiceInt nxpts;
83 SpiceDouble xpt[3];
84
85// std::vector<double> n = normal();
86
87// zvec[0] = n[0];
88// zvec[1] = n[1];
89// zvec[2] = n[2];
90 zvec[0] = 0.0;
91 zvec[1] = 0.0;
92 zvec[2] = 1.0;
93
94 if (observerPos[2] < 0.0)
95 zvec[2] = -zvec[2];
96
97 // NAIF routine to "Make a CSPICE plane from a normal vector and a constant"
98 // see http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/nvc2pl_c.html
99 nvc2pl_c(zvec, 0.0, &plane);
100
101 SpiceDouble position[3];
102 SpiceDouble lookvector[3];
103
104 position[0] = observerPos[0];
105 position[1] = observerPos[1];
106 position[2] = observerPos[2];
107
108 lookvector[0] = lookDirection[0];
109 lookvector[1] = lookDirection[1];
110 lookvector[2] = lookDirection[2];
111
112 // NAIF routine to "find the intersection of a ray and a plane"
113 // see http://naif.jpl.nasa.gov/pub/naif/toolkit_docs/C/cspice/inrypl_c.html
114 inrypl_c(&position, &lookvector, &plane, &nxpts, xpt);
115
116 if (nxpts != 1 ) {
117 setHasIntersection(false);
118 return false;
119 }
120
121 setHasIntersection(true);
122 setNormal(0.0,0.0,1.0);
123 surfaceIntersection()->FromNaifArray(xpt);
125
126 return true;
127 }
128
129
137 bool PlaneShape::isDEM() const {
138 return false;
139 }
140
141
147
148
154
155
159 void PlaneShape::calculateLocalNormal(QVector<double *> cornerNeighborPoints) {
160 }
161
162
178 double PlaneShape::emissionAngle(const std::vector<double> & sB) {
179
180 SpiceDouble pB[3]; // surface intersection in body-fixed coordinates
181 SpiceDouble psB[3]; // vector from spacecraft to surface intersection
182 SpiceDouble upsB[3]; // unit vector from spacecraft to surface intersection
183 SpiceDouble dist; // vector magnitude
184
185 // Get vector from center of body to surface point
186 pB[0] = surfaceIntersection()->GetX().kilometers();
187 pB[1] = surfaceIntersection()->GetY().kilometers();
188 pB[2] = surfaceIntersection()->GetZ().kilometers();
189
190 // Get vector from surface intersect point to observer and normalize it
191 vsub_c((ConstSpiceDouble *) &sB[0], pB, psB);
192 unorm_c(psB, upsB, &dist);
193
194 // temporary normal vector
195 SpiceDouble n[3];
196 n[0] = 0.0;
197 n[1] = 0.0;
198 n[2] = 1.0;
199
200 // flip normal if observer is "below" the plane, assuming that the target
201 // body north pole defines the "up" direction
202 if (sB[2] < 0.0)
203 n[2] = -n[2];
204
205 // dot product of surface normal and observer-surface intersection vector
206 double angle = vdot_c(n, upsB);
207
208 if (angle > 1.0)
209 return 0.0;
210
211 if (angle < -1.0)
212 return 180.0;
213
214 return acos(angle) * RAD2DEG;
215 }
216
217
235 double PlaneShape::incidenceAngle(const std::vector<double> &uB) {
236
237 SpiceDouble pB[3]; // surface intersection in body-fixed coordinates
238 SpiceDouble puB[3]; // vector from sun to surface intersection
239 SpiceDouble upuB[3]; // unit vector from sun to surface intersection
240 SpiceDouble dist; // vector magnitude
241
242 // Get vector from center of body to surface point
243 pB[0] = surfaceIntersection()->GetX().kilometers();
244 pB[1] = surfaceIntersection()->GetY().kilometers();
245 pB[2] = surfaceIntersection()->GetZ().kilometers();
246
247 // Get vector from surface intersect point to sun and normalize it
248 vsub_c((SpiceDouble *) &uB[0], pB, puB);
249 unorm_c(puB, upuB, &dist);
250
251 // temporary normal vector
252 SpiceDouble n[3];
253 n[0] = 0.0;
254 n[1] = 0.0;
255 n[2] = 1.0;
256
257 // flip normal if sun is "below" the plane, assuming that the target
258 // body north pole defines the "up" direction
259 if (uB[2] < 0.0)
260 n[2] = -n[2];
261
262 double angle = vdot_c((SpiceDouble *) &n[0], upuB);
263
264 if (angle > 1.0)
265 return 0.0;
266
267 if(angle < -1.0)
268 return 180.0;
269
270 return acos(angle) * RAD2DEG;
271 }
272
273
283 // TODO: what should this do in the case of a ring plane (or any other plane
284 // for that matter)?
286
287 SpiceDouble pB[3]; // surface intersection in body-fixed coordinates
288
289 // Get vector from center of body to surface point
290 pB[0] = surfaceIntersection()->GetX().kilometers();
291 pB[1] = surfaceIntersection()->GetY().kilometers();
292 pB[2] = surfaceIntersection()->GetZ().kilometers();
293
294 double radius = sqrt(pB[0]*pB[0] + pB[1]*pB[1] + pB[2]*pB[2]);
295
296 return Distance(radius, Distance::Kilometers);
297 }
298}
Distance measurement, usually in meters.
Definition Distance.h:34
@ Kilometers
The distance is being specified in kilometers.
Definition Distance.h:45
This class is designed to encapsulate the concept of a Latitude.
Definition Latitude.h:51
This class is designed to encapsulate the concept of a Longitude.
Definition Longitude.h:40
static void CheckErrors(bool resetNaif=true)
This method looks for any naif errors that might have occurred.
void calculateSurfaceNormal()
There is no implementation for this method.
void calculateDefaultNormal()
There is no implementation for this method.
Distance localRadius(const Latitude &lat, const Longitude &lon)
Gets the local radius for the given latitude/longitude coordinate.
bool intersectSurface(std::vector< double > observerPos, std::vector< double > lookDirection)
Find the intersection point.
void calculateLocalNormal(QVector< double * > cornerNeighborPoints)
There is no implementation for this method.
PlaneShape()
Initialize the PlaneShape.
~PlaneShape()
Destructor.
bool isDEM() const
Indicates that this shape model is not from a DEM.
double emissionAngle(const std::vector< double > &sB)
Computes and returns emission angle in degrees given the observer position.
double incidenceAngle(const std::vector< double > &uB)
Computes and returns incidence angle in degrees given the sun position.
Container for cube-like labels.
Definition Pvl.h:119
Define shapes and provide utilities for Isis targets.
Definition ShapeModel.h:66
void setHasIntersection(bool b)
Sets the flag to indicate whether this ShapeModel has an intersection.
void setNormal(const std::vector< double >)
Sets the surface normal for the currect intersection point.
virtual SurfacePoint * surfaceIntersection() const
Returns the surface intersection for this ShapeModel.
void setName(QString name)
Sets the shape name.
This class is used to create and store valid Isis targets.
Definition Target.h:63
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16
const double RAD2DEG
Multiplier for converting from radians to degrees.
Definition Constants.h:44