LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
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 #include <limits>
32 
33 #include "Circle.h"
34 #include "Matrix3d.h"
35 #include "Region.h"
36 #include "UnitVector3d.h"
37 
38 
39 namespace lsst {
40 namespace sphgeom {
41 
170 class Ellipse : public Region {
171 public:
172  static constexpr uint8_t TYPE_CODE = 'e';
173 
174  static Ellipse empty() { return Ellipse(); }
175 
176  static Ellipse full() { return Ellipse().complement(); }
177 
180  _S(1.0),
181  _a(-2.0),
182  _b(-2.0),
183  _gamma(0.0),
184  _tana(std::numeric_limits<double>::infinity()),
185  _tanb(std::numeric_limits<double>::infinity())
186  {}
187 
189  explicit Ellipse(Circle const & c) {
190  *this = Ellipse(c.getCenter(), c.getCenter(), c.getOpeningAngle());
191  }
192 
195  explicit Ellipse(UnitVector3d const & v, Angle alpha = Angle(0.0)) {
196  *this = Ellipse(v, v, alpha);
197  }
198 
201  Ellipse(UnitVector3d const & f1, UnitVector3d const & f2, Angle alpha);
202 
208  Ellipse(UnitVector3d const & center,
209  Angle alpha,
210  Angle beta,
212 
213  bool operator==(Ellipse const & e) const {
214  return _S == e._S && _a == e._a && _b == e._b;
215  }
216 
217  bool operator!=(Ellipse const & e) const { return !(*this == e); }
218 
219  bool isEmpty() const { return Angle(0.5 * PI) + _a < _gamma; }
220 
221  bool isFull() const { return Angle(0.5 * PI) - _a <= _gamma; }
222 
223  bool isGreatCircle() const { return _a.asRadians() == 0.0; }
224 
225  bool isCircle() const { return _a == _b; }
226 
230  Matrix3d const & getTransformMatrix() const { return _S; }
231 
234  return UnitVector3d::fromNormalized(_S(2,0), _S(2,1), _S(2,2));
235  }
236 
238  UnitVector3d getF1() const {
239  UnitVector3d n = UnitVector3d::fromNormalized(_S(1,0), _S(1,1), _S(1,2));
240  return getCenter().rotatedAround(n, -_gamma);
241  }
242 
244  UnitVector3d getF2() const {
245  UnitVector3d n = UnitVector3d::fromNormalized(_S(1,0), _S(1,1), _S(1,2));
246  return getCenter().rotatedAround(n, _gamma);
247  }
248 
252  Angle getAlpha() const { return Angle(0.5 * PI) + _a; }
253 
257  Angle getBeta() const { return Angle(0.5 * PI) + _b; }
258 
261  Angle getGamma() const { return _gamma; }
262 
265  _S = Matrix3d(-_S(0,0), -_S(0,1), -_S(0,2),
266  _S(1,0), _S(1,1), _S(1,2),
267  -_S(2,0), -_S(2,1), -_S(2,2));
268  _a = -_a;
269  _b = -_b;
270  return *this;
271  }
272 
274  Ellipse complemented() const { return Ellipse(*this).complement(); }
275 
276  // Region interface
277  std::unique_ptr<Region> clone() const override {
278  return std::unique_ptr<Ellipse>(new Ellipse(*this));
279  }
280 
281  Box getBoundingBox() const override;
282  Box3d getBoundingBox3d() const override;
283  Circle getBoundingCircle() const override;
284 
285  bool contains(UnitVector3d const &v) const override;
286 
287  using Region::contains;
288 
289  Relationship relate(Region const & r) const override {
290  // Dispatch on the type of r.
291  return invert(r.relate(*this));
292  }
293 
294  Relationship relate(Box const &) const override;
295  Relationship relate(Circle const &) const override;
296  Relationship relate(ConvexPolygon const &) const override;
297  Relationship relate(Ellipse const &) const override;
298 
299  std::vector<uint8_t> encode() const override;
300 
304  return decode(s.data(), s.size());
305  }
306  static std::unique_ptr<Ellipse> decode(uint8_t const * buffer, size_t n);
308 
309 private:
310  static constexpr size_t ENCODED_SIZE = 113;
311 
312  Matrix3d _S;
313  Angle _a; // α - π/2
314  Angle _b; // β - π/2
315  Angle _gamma; // Half the angle between the ellipse foci
316  double _tana; // |tan a| = |cot α|
317  double _tanb; // |tan b| = |cot β|
318 };
319 
320 std::ostream & operator<<(std::ostream &, Ellipse const &);
321 
322 }} // namespace lsst::sphgeom
323 
324 #endif // LSST_SPHGEOM_ELLIPSE_H_
This file declares a class for representing circular regions on the unit sphere.
This file contains a class representing 3x3 real matrices.
This file defines an interface for spherical regions.
This file declares a class for representing unit vectors in ℝ³.
Angle represents an angle in radians.
Definition: Angle.h:43
double asRadians() const
asRadians returns the value of this angle in units of radians.
Definition: Angle.h:85
Box3d represents a box in ℝ³.
Definition: Box3d.h:42
Box represents a rectangle in spherical coordinate space that contains its boundary.
Definition: Box.h:54
Circle is a circular region on the unit sphere that contains its boundary.
Definition: Circle.h:46
UnitVector3d const & getCenter() const
getCenter returns the center of this circle as a unit vector.
Definition: Circle.h:118
Angle getOpeningAngle() const
getOpeningAngle returns the opening angle of this circle - that is, the angle between its center vect...
Definition: Circle.h:128
ConvexPolygon is a closed convex polygon on the unit sphere.
Definition: ConvexPolygon.h:57
Ellipse is an elliptical region on the sphere.
Definition: Ellipse.h:170
Matrix3d const & getTransformMatrix() const
getTransformMatrix returns the orthogonal matrix that maps vectors to the basis in which the quadrati...
Definition: Ellipse.h:230
static constexpr uint8_t TYPE_CODE
Definition: Ellipse.h:172
bool isCircle() const
Definition: Ellipse.h:225
Angle getAlpha() const
getAlpha returns α, the first semi-axis length of the ellipse.
Definition: Ellipse.h:252
UnitVector3d getF2() const
getF2 returns the second focal point of the ellipse.
Definition: Ellipse.h:244
bool isGreatCircle() const
Definition: Ellipse.h:223
static Ellipse full()
Definition: Ellipse.h:176
Angle getBeta() const
getBeta returns β, the second semi-axis length of the ellipse.
Definition: Ellipse.h:257
static std::unique_ptr< Ellipse > decode(std::vector< uint8_t > const &s)
Definition: Ellipse.h:303
Relationship relate(Region const &r) const override
Definition: Ellipse.h:289
Circle getBoundingCircle() const override
getBoundingCircle returns a bounding-circle for this region.
Definition: Ellipse.cc:241
Box getBoundingBox() const override
getBoundingBox returns a bounding-box for this region.
Definition: Ellipse.cc:190
Ellipse(Circle const &c)
This constructor creates an ellipse corresponding to the given circle.
Definition: Ellipse.h:189
std::vector< uint8_t > encode() const override
encode serializes this region into an opaque byte string.
Definition: Ellipse.cc:339
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:195
Ellipse()
This constructor creates an empty ellipse.
Definition: Ellipse.h:179
Ellipse & complement()
complement sets this ellipse to the closure of its complement.
Definition: Ellipse.h:264
bool operator==(Ellipse const &e) const
Definition: Ellipse.h:213
UnitVector3d getF1() const
getF1 returns the first focal point of the ellipse.
Definition: Ellipse.h:238
virtual bool contains(UnitVector3d const &) const=0
contains tests whether the given unit vector is inside this region.
Angle getGamma() const
getGamma returns ɣ ∈ [0, π/2], half of the angle between the foci.
Definition: Ellipse.h:261
bool operator!=(Ellipse const &e) const
Definition: Ellipse.h:217
std::unique_ptr< Region > clone() const override
clone returns a deep copy of this region.
Definition: Ellipse.h:277
bool isFull() const
Definition: Ellipse.h:221
static Ellipse empty()
Definition: Ellipse.h:174
bool isEmpty() const
Definition: Ellipse.h:219
Ellipse complemented() const
complemented returns the closure of the complement of this ellipse.
Definition: Ellipse.h:274
UnitVector3d getCenter() const
getCenter returns the center of the ellipse as a unit vector.
Definition: Ellipse.h:233
Box3d getBoundingBox3d() const override
getBoundingBox3d returns a 3-dimensional bounding-box for this region.
Definition: Ellipse.cc:237
A 3x3 matrix with real entries stored in double precision.
Definition: Matrix3d.h:38
Region is a minimal interface for 2-dimensional regions on the unit sphere.
Definition: Region.h:79
virtual Relationship relate(Region const &) const =0
virtual bool contains(UnitVector3d const &) const =0
contains tests whether the given unit vector is inside this region.
UnitVector3d is a unit vector in ℝ³ with components stored in double precision.
Definition: UnitVector3d.h:55
static UnitVector3d fromNormalized(Vector3d const &v)
fromNormalized returns the unit vector equal to v, which is assumed to be normalized.
Definition: UnitVector3d.h:82
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
T data(T... args)
lsst::geom::Angle Angle
Definition: misc.h:33
std::ostream & operator<<(std::ostream &, Angle const &)
Definition: Angle.cc:34
int orientation(UnitVector3d const &a, UnitVector3d const &b, UnitVector3d const &c)
orientation computes and returns the orientations of 3 unit vectors a, b and c.
Definition: orientation.cc:135
constexpr double PI
Definition: constants.h:36
Relationship invert(Relationship r)
Given the relationship between two sets A and B (i.e.
Definition: Relationship.h:55
A base class for image defects.
STL namespace.
T size(T... args)