LSSTApplications  15.0+21,16.0+1,16.0+10,16.0+3,16.0+4,16.0-1-g2115a9e+4,16.0-1-g4515a79+8,16.0-1-g7bb14cc,16.0-1-g80120d7+6,16.0-1-g98efed3+6,16.0-1-gb7f560d+3,16.0-18-g7a076d417,16.0-2-g2ed7261+3,16.0-2-g311bfd2,16.0-2-g568a347+5,16.0-2-g7adb079,16.0-2-gd4c87cb+5,16.0-3-g099ede0,16.0-3-g150e024+5,16.0-3-g1f513a6+2,16.0-3-g958ce35,16.0-3-gc6a11d1,16.0-4-g84f75fb+7,16.0-4-gcfd1396+6,16.0-4-gde8cee2,16.0-5-g7bc0afb+5,16.0-5-g81851deb,16.0-5-g82b7855+1,16.0-5-gd32631f,16.0-5-gf14cb0b,16.0-6-g2dd73041+6,16.0-6-gcf12234+1,16.0-7-g95fb7bf+2,16.0-7-gc37dbc2+6,w.2018.28
LSSTDataManagementBasePackage
Ellipse.h
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  * Copyright 2014-2015 AURA/LSST.
4  *
5  * This product includes software developed by the
6  * LSST Project (http://www.lsst.org/).
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the LSST License Statement and
19  * the GNU General Public License along with this program. If not,
20  * see <https://www.lsstcorp.org/LegalNotices/>.
21  */
22 
23 #ifndef LSST_SPHGEOM_ELLIPSE_H_
24 #define LSST_SPHGEOM_ELLIPSE_H_
25 
29 
30 #include <iosfwd>
31 
32 #include "Circle.h"
33 #include "Matrix3d.h"
34 #include "Region.h"
35 #include "UnitVector3d.h"
36 
37 
38 namespace lsst {
39 namespace sphgeom {
40 
169 class Ellipse : public Region {
170 public:
171  static constexpr uint8_t TYPE_CODE = 'e';
172 
173  static Ellipse empty() { return Ellipse(); }
174 
175  static Ellipse full() { return Ellipse().complement(); }
176 
179  _S(1.0),
180  _a(-2.0),
181  _b(-2.0),
182  _gamma(0.0),
183  _tana(std::numeric_limits<double>::infinity()),
184  _tanb(std::numeric_limits<double>::infinity())
185  {}
186 
188  explicit Ellipse(Circle const & c) {
189  *this = Ellipse(c.getCenter(), c.getCenter(), c.getOpeningAngle());
190  }
191 
194  explicit Ellipse(UnitVector3d const & v, Angle alpha = Angle(0.0)) {
195  *this = Ellipse(v, v, alpha);
196  }
197 
200  Ellipse(UnitVector3d const & f1, UnitVector3d const & f2, Angle alpha);
201 
207  Ellipse(UnitVector3d const & center,
208  Angle alpha,
209  Angle beta,
211 
212  bool operator==(Ellipse const & e) const {
213  return _S == e._S && _a == e._a && _b == e._b;
214  }
215 
216  bool operator!=(Ellipse const & e) const { return !(*this == e); }
217 
218  bool isEmpty() const { return Angle(0.5 * PI) + _a < _gamma; }
219 
220  bool isFull() const { return Angle(0.5 * PI) - _a <= _gamma; }
221 
222  bool isGreatCircle() const { return _a.asRadians() == 0.0; }
223 
224  bool isCircle() const { return _a == _b; }
225 
229  Matrix3d const & getTransformMatrix() const { return _S; }
230 
233  return UnitVector3d::fromNormalized(_S(2,0), _S(2,1), _S(2,2));
234  }
235 
237  UnitVector3d getF1() const {
238  UnitVector3d n = UnitVector3d::fromNormalized(_S(1,0), _S(1,1), _S(1,2));
239  return getCenter().rotatedAround(n, -_gamma);
240  }
241 
243  UnitVector3d getF2() const {
244  UnitVector3d n = UnitVector3d::fromNormalized(_S(1,0), _S(1,1), _S(1,2));
245  return getCenter().rotatedAround(n, _gamma);
246  }
247 
251  Angle getAlpha() const { return Angle(0.5 * PI) + _a; }
252 
256  Angle getBeta() const { return Angle(0.5 * PI) + _b; }
257 
260  Angle getGamma() const { return _gamma; }
261 
264  _S = Matrix3d(-_S(0,0), -_S(0,1), -_S(0,2),
265  _S(1,0), _S(1,1), _S(1,2),
266  -_S(2,0), -_S(2,1), -_S(2,2));
267  _a = -_a;
268  _b = -_b;
269  return *this;
270  }
271 
273  Ellipse complemented() const { return Ellipse(*this).complement(); }
274 
275  // Region interface
276  std::unique_ptr<Region> clone() const override {
277  return std::unique_ptr<Ellipse>(new Ellipse(*this));
278  }
279 
280  Box getBoundingBox() const override;
281  Box3d getBoundingBox3d() const override;
282  Circle getBoundingCircle() const override;
283 
284  bool contains(UnitVector3d const &v) const override;
285 
286  Relationship relate(Region const & r) const override {
287  // Dispatch on the type of r.
288  return invert(r.relate(*this));
289  }
290 
291  Relationship relate(Box const &) const override;
292  Relationship relate(Circle const &) const override;
293  Relationship relate(ConvexPolygon const &) const override;
294  Relationship relate(Ellipse const &) const override;
295 
296  std::vector<uint8_t> encode() const override;
297 
301  return decode(s.data(), s.size());
302  }
303  static std::unique_ptr<Ellipse> decode(uint8_t const * buffer, size_t n);
305 
306 private:
307  static constexpr size_t ENCODED_SIZE = 113;
308 
309  Matrix3d _S;
310  Angle _a; // α - π/2
311  Angle _b; // β - π/2
312  Angle _gamma; // Half the angle between the ellipse foci
313  double _tana; // |tan a| = |cot α|
314  double _tanb; // |tan b| = |cot β|
315 };
316 
318 
319 }} // namespace lsst::sphgeom
320 
321 #endif // LSST_SPHGEOM_ELLIPSE_H_
This file declares a class for representing circular regions on the unit sphere.
static std::unique_ptr< Ellipse > decode(std::vector< uint8_t > const &s)
Definition: Ellipse.h:300
bool isGreatCircle() const
Definition: Ellipse.h:222
Ellipse()
This constructor creates an empty ellipse.
Definition: Ellipse.h:178
UnitVector3d getCenter() const
getCenter returns the center of the ellipse as a unit vector.
Definition: Ellipse.h:232
bool operator==(Ellipse const &e) const
Definition: Ellipse.h:212
Ellipse(Circle const &c)
This constructor creates an ellipse corresponding to the given circle.
Definition: Ellipse.h:188
Ellipse complemented() const
complemented returns the closure of the complement of this ellipse.
Definition: Ellipse.h:273
UnitVector3d rotatedAround(UnitVector3d const &k, Angle a) const
rotatedAround returns a copy of this unit vector, rotated around the unit vector k by angle a accordi...
Definition: UnitVector3d.h:193
static Ellipse full()
Definition: Ellipse.h:175
Angle getOpeningAngle() const
getOpeningAngle returns the opening angle of this circle - that is, the angle between its center vect...
Definition: Circle.h:128
std::unique_ptr< Region > clone() const override
clone returns a deep copy of this region.
Definition: Ellipse.h:276
STL namespace.
std::ostream & operator<<(std::ostream &, Angle const &)
Definition: Angle.cc:34
Relationship invert(Relationship r)
Given the relationship between two sets A and B (i.e.
Definition: Relationship.h:55
bool isEmpty() const
Definition: Ellipse.h:218
Box represents a rectangle in spherical coordinate space that contains its boundary.
Definition: Box.h:54
static Ellipse empty()
Definition: Ellipse.h:173
A 3x3 matrix with real entries stored in double precision.
Definition: Matrix3d.h:38
std::vector< uint8_t > encode() const override
encode serializes this region into an opaque byte string.
Definition: Ellipse.cc:339
Matrix3d const & getTransformMatrix() const
getTransformMatrix returns the orthogonal matrix that maps vectors to the basis in which the quadrati...
Definition: Ellipse.h:229
This file declares a class for representing unit vectors in ℝ³.
bool isFull() const
Definition: Ellipse.h:220
Ellipse is an elliptical region on the sphere.
Definition: Ellipse.h:169
T data(T... args)
A base class for image defects.
Definition: cameraGeom.dox:3
double asRadians() const
asRadians returns the value of this angle in units of radians.
Definition: Angle.h:85
This file defines an interface for spherical regions.
Region is a minimal interface for 2-dimensional regions on the unit sphere.
Definition: Region.h:79
constexpr double PI
Definition: constants.h:36
virtual Relationship relate(Region const &) const =0
Box3d getBoundingBox3d() const override
getBoundingBox3d returns a 3-dimensional bounding-box for this region.
Definition: Ellipse.cc:237
Box getBoundingBox() const override
getBoundingBox returns a bounding-box for this region.
Definition: Ellipse.cc:190
solver_t * s
Angle getBeta() const
getBeta returns β, the second semi-axis length of the ellipse.
Definition: Ellipse.h:256
Circle is a circular region on the unit sphere that contains its boundary.
Definition: Circle.h:46
ConvexPolygon is a closed convex polygon on the unit sphere.
Definition: ConvexPolygon.h:57
Angle getAlpha() const
getAlpha returns α, the first semi-axis length of the ellipse.
Definition: Ellipse.h:251
Relationship relate(Region const &r) const override
Definition: Ellipse.h:286
T size(T... args)
Circle getBoundingCircle() const override
getBoundingCircle returns a bounding-circle for this region.
Definition: Ellipse.cc:241
STL class.
STL class.
Angle represents an angle in radians.
Definition: Angle.h:43
bool operator!=(Ellipse const &e) const
Definition: Ellipse.h:216
UnitVector3d const & getCenter() const
getCenter returns the center of this circle as a unit vector.
Definition: Circle.h:118
Box3d represents a box in ℝ³.
Definition: Box3d.h:42
Ellipse & complement()
complement sets this ellipse to the closure of its complement.
Definition: Ellipse.h:263
Ellipse(UnitVector3d const &v, Angle alpha=Angle(0.0))
This constructor creates an ellipse corresponding to the circle with the given center and opening ang...
Definition: Ellipse.h:194
Angle getGamma() const
getGamma returns ɣ ∈ [0, π/2], half of the angle between the foci.
Definition: Ellipse.h:260
UnitVector3d getF2() const
getF2 returns the second focal point of the ellipse.
Definition: Ellipse.h:243
lsst::geom::Angle Angle
Definition: misc.h:33
UnitVector3d is a unit vector in ℝ³ with components stored in double precision.
Definition: UnitVector3d.h:55
static constexpr uint8_t TYPE_CODE
Definition: Ellipse.h:171
bool isCircle() const
Definition: Ellipse.h:224
STL class.
static UnitVector3d fromNormalized(Vector3d const &v)
fromNormalized returns the unit vector equal to v, which is assumed to be normalized.
Definition: UnitVector3d.h:82
STL class.
This file contains a class representing 3x3 real matrices.
UnitVector3d getF1() const
getF1 returns the first focal point of the ellipse.
Definition: Ellipse.h:237
bool contains(UnitVector3d const &v) const override
contains tests whether the given unit vector is inside this region.
Definition: Ellipse.cc:160