• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kstars

  • sources
  • kde-4.12
  • kdeedu
  • kstars
  • kstars
  • htmesh
SpatialVector.cpp
Go to the documentation of this file.
1 
2 //# Filename: SpatialVector.cpp
3 //#
4 //# The SpatialVector class is defined here.
5 //#
6 //# Author: Peter Z. Kunszt based on A. Szalay's code
7 //#
8 //# Date: October 15, 1998
9 //#
10 //# Copyright (C) 2000 Peter Z. Kunszt, Alex S. Szalay, Aniruddha R. Thakar
11 //# The Johns Hopkins University
12 //# Modification History:
13 //#
14 //# Oct 18, 2001 : Dennis C. Dinge -- Replaced ValVec with std::vector
15 //#
16 
17 #include "SpatialVector.h"
18 #include "SpatialException.h"
19 
20 //==============================================================
21 //
22 // This 3D vector lives on the surface of the sphere.
23 // Its length is always 1.
24 //
25 //==============================================================
26 
28 //
29 SpatialVector::SpatialVector() :
30  x_(1), y_(0), z_(0), ra_(0), dec_(0), okRaDec_(true) {
31 }
32 
33 
34 SpatialVector::SpatialVector(float64 x, float64 y, float64 z) :
35  x_(x), y_(y), z_(z), okRaDec_(false) {
36 }
37 
39 //
40 SpatialVector::SpatialVector(float64 ra, float64 dec) :
41  ra_(ra), dec_(dec), okRaDec_(true) {
42  updateXYZ();
43  updateRaDec();
44 }
45 
47 //
48 void
49 SpatialVector::set(const float64 &x, const float64 &y, const float64 &z )
50 {
51  x_ = x;
52  y_ = y;
53  z_ = z;
54  normalize();
55  updateRaDec();
56 }
58 //
59 void
60 SpatialVector::set(const float64 &ra, const float64 &dec)
61 {
62  ra_ = ra;
63  dec_ = dec;
64  updateXYZ();
65 }
66 
68 //
69 void
70 SpatialVector::get(float64 &x,float64 &y,float64 &z ) const
71 {
72  x = x_;
73  y = y_;
74  z = z_;
75 }
76 
78 //
79 void
80 SpatialVector::get(float64 &ra,float64 &dec )
81 {
82  if(!okRaDec_) {
83  normalize();
84  updateRaDec();
85  }
86  ra = ra_;
87  dec = dec_;
88 }
89 
90 float64 SpatialVector::ra() {
91  if(!okRaDec_) {
92  normalize();
93  updateRaDec();
94  }
95  return ra_;
96 }
97 
98 float64 SpatialVector::dec() {
99  if(!okRaDec_) {
100  normalize();
101  updateRaDec();
102  }
103  return dec_;
104 }
105 
106 
108 //
109 void
110 SpatialVector::normalize()
111 {
112 float64 sum;
113  sum = x_*x_ + y_*y_ + z_*z_;
114  sum = sqrt(sum);
115  x_ /= sum;
116  y_ /= sum;
117  z_ /= sum;
118 }
119 
121 //
122 float64
123 SpatialVector::length() const
124 {
125 float64 sum;
126  sum = x_*x_ + y_*y_ + z_*z_;
127  return sum > gEpsilon ? sqrt(sum) : 0.0;
128 }
129 
131 //
132 void
133 SpatialVector::updateRaDec() {
134  dec_ = asin(z_)/gPr; // easy.
135  float64 cd = cos(dec_*gPr);
136  if(cd>gEpsilon || cd<-gEpsilon)
137  if(y_>gEpsilon || y_<-gEpsilon)
138  if (y_ < 0.0)
139  ra_ = 360 - acos(x_/cd)/gPr;
140  else
141  ra_ = acos(x_/cd)/gPr;
142  else
143  ra_ = (x_ < 0.0 ? 180.0 : 0.0);
144  else
145  ra_=0.0;
146  okRaDec_ = true;
147 }
148 
150 //
151 void
152 SpatialVector::updateXYZ() {
153  float64 cd = cos(dec_*gPr);
154  x_ = cos(ra_*gPr) * cd;
155  y_ = sin(ra_*gPr) * cd;
156  z_ = sin(dec_*gPr);
157 }
159 //
160 SpatialVector&
161 SpatialVector::operator *=(float64 a)
162 {
163  x_ = a*x_;
164  y_ = a*y_;
165  z_ = a*z_;
166  okRaDec_ = false;
167  return *this;
168 }
169 
171 //
172 SpatialVector&
173 SpatialVector::operator *=(int a)
174 {
175  x_ = a*x_;
176  y_ = a*y_;
177  z_ = a*z_;
178  okRaDec_ = false;
179  return *this;
180 }
181 
183 // Multiply with a number
184 //
185 SpatialVector
186 operator *(float64 a, const SpatialVector& v)
187 {
188  return SpatialVector(a*v.x_, a*v.y_, a*v.z_);
189 }
190 
192 // Multiply with a number
193 //
194 SpatialVector
195 operator *(const SpatialVector& v, float64 a)
196 {
197  return SpatialVector(a*v.x_, a*v.y_, a*v.z_);
198 }
199 
201 // Multiply with a number
202 //
203 SpatialVector
204 operator *(int a, const SpatialVector& v)
205 {
206  return SpatialVector(a*v.x_, a*v.y_, a*v.z_);
207 }
208 
210 // Multiply with a number
211 //
212 SpatialVector
213 operator *(const SpatialVector& v, int a)
214 {
215  return SpatialVector(a*v.x_, a*v.y_, a*v.z_);
216 }
217 
218 
220 // dot product
221 //
222 float64
223 SpatialVector::operator *(const SpatialVector & v) const
224 {
225  return (x_*v.x_)+(y_*v.y_)+(z_*v.z_);
226 }
227 
229 //
230 SpatialVector
231 SpatialVector::operator +(const SpatialVector & v) const
232 {
233  return SpatialVector(x_+v.x_, y_+v.y_, z_+v.z_);
234 }
235 
237 //
238 SpatialVector
239 SpatialVector::operator -(const SpatialVector & v) const
240 {
241  return SpatialVector(x_-v.x_, y_-v.y_, z_-v.z_);
242 }
243 
245 // cross product
246 //
247 SpatialVector
248 SpatialVector::operator ^(const SpatialVector &v) const
249 {
250  return SpatialVector(y_ * v.z_ - v.y_ * z_,
251  z_ * v.x_ - v.z_ * x_,
252  x_ * v.y_ - v.x_ * y_);
253 }
254 
256 //
257 int
258 SpatialVector::operator ==(const SpatialVector & v) const
259 {
260  return ( (x_ == v.x_ && y_ == v.y_ && z_ == v.z_) ? 1 : 0 );
261 }
SpatialVector::operator==
int operator==(const SpatialVector &) const
Comparison.
Definition: SpatialVector.cpp:258
SpatialVector::length
float64 length() const
return length of vector
Definition: SpatialVector.cpp:123
SpatialVector::operator+
SpatialVector operator+(const SpatialVector &) const
addition
Definition: SpatialVector.cpp:231
SpatialVector::SpatialVector
SpatialVector()
constructs (1,0,0), ra=0, dec=0.
Definition: SpatialVector.cpp:29
SpatialVector.h
SpatialVector::dec
float64 dec()
return dec - this norms the vector to 1 if not already done so
Definition: SpatialVector.cpp:98
operator*
SpatialVector operator*(float64 a, const SpatialVector &v)
Definition: SpatialVector.cpp:186
SpatialVector::operator*=
SpatialVector & operator*=(float64)
Definition: SpatialVector.cpp:161
SpatialVector::operator^
SpatialVector operator^(const SpatialVector &) const
cross product
Definition: SpatialVector.cpp:248
SpatialVector::ra
float64 ra()
return ra - this norms the vector to 1 if not already done so
Definition: SpatialVector.cpp:90
gEpsilon
const float64 gEpsilon
Definition: SpatialGeneral.h:88
SpatialVector::x
float64 x() const
return x (only as rvalue)
Definition: SpatialVector.h:68
SpatialVector::y
float64 y() const
return y
Definition: SpatialVector.h:71
SpatialVector
The SpatialVector is a 3D vector usually living on the surface of the sphere.
Definition: SpatialVector.h:32
SpatialVector::set
void set(const float64 &x, const float64 &y, const float64 &z)
Set member function: set values - always normed to 1.
Definition: SpatialVector.cpp:49
SpatialVector::operator*
float64 operator*(const SpatialVector &) const
dot product
Definition: SpatialVector.cpp:223
SpatialVector::z
float64 z() const
return z
Definition: SpatialVector.h:74
SpatialVector::operator-
SpatialVector operator-(const SpatialVector &) const
subtraction
Definition: SpatialVector.cpp:239
gPr
const float64 gPr
Definition: SpatialGeneral.h:87
SpatialException.h
float64
double float64
Definition: SpatialGeneral.h:58
SpatialVector::get
void get(float64 &x, float64 &y, float64 &z) const
Get x,y,z.
Definition: SpatialVector.cpp:70
SpatialVector::normalize
void normalize()
Normalize vector length to 1.
Definition: SpatialVector.cpp:110
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:21 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kstars

Skip menu "kstars"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal