LSST Applications  21.0.0-147-g0e635eb1+1acddb5be5,22.0.0+052faf71bd,22.0.0+1ea9a8b2b2,22.0.0+6312710a6c,22.0.0+729191ecac,22.0.0+7589c3a021,22.0.0+9f079a9461,22.0.1-1-g7d6de66+b8044ec9de,22.0.1-1-g87000a6+536b1ee016,22.0.1-1-g8e32f31+6312710a6c,22.0.1-10-gd060f87+016f7cdc03,22.0.1-12-g9c3108e+df145f6f68,22.0.1-16-g314fa6d+c825727ab8,22.0.1-19-g93a5c75+d23f2fb6d8,22.0.1-19-gb93eaa13+aab3ef7709,22.0.1-2-g8ef0a89+b8044ec9de,22.0.1-2-g92698f7+9f079a9461,22.0.1-2-ga9b0f51+052faf71bd,22.0.1-2-gac51dbf+052faf71bd,22.0.1-2-gb66926d+6312710a6c,22.0.1-2-gcb770ba+09e3807989,22.0.1-20-g32debb5+b8044ec9de,22.0.1-23-gc2439a9a+fb0756638e,22.0.1-3-g496fd5d+09117f784f,22.0.1-3-g59f966b+1e6ba2c031,22.0.1-3-g849a1b8+f8b568069f,22.0.1-3-gaaec9c0+c5c846a8b1,22.0.1-32-g5ddfab5d3+60ce4897b0,22.0.1-4-g037fbe1+64e601228d,22.0.1-4-g8623105+b8044ec9de,22.0.1-5-g096abc9+d18c45d440,22.0.1-5-g15c806e+57f5c03693,22.0.1-7-gba73697+57f5c03693,master-g6e05de7fdc+c1283a92b8,master-g72cdda8301+729191ecac,w.2021.39
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 
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  using Region::contains;
287 
288  Relationship relate(Region const & r) const override {
289  // Dispatch on the type of r.
290  return invert(r.relate(*this));
291  }
292 
293  Relationship relate(Box const &) const override;
294  Relationship relate(Circle const &) const override;
295  Relationship relate(ConvexPolygon const &) const override;
296  Relationship relate(Ellipse const &) const override;
297 
298  std::vector<uint8_t> encode() const override;
299 
303  return decode(s.data(), s.size());
304  }
305  static std::unique_ptr<Ellipse> decode(uint8_t const * buffer, size_t n);
307 
308 private:
309  static constexpr size_t ENCODED_SIZE = 113;
310 
311  Matrix3d _S;
312  Angle _a; // α - π/2
313  Angle _b; // β - π/2
314  Angle _gamma; // Half the angle between the ellipse foci
315  double _tana; // |tan a| = |cot α|
316  double _tanb; // |tan b| = |cot β|
317 };
318 
319 std::ostream & operator<<(std::ostream &, Ellipse const &);
320 
321 }} // namespace lsst::sphgeom
322 
323 #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:169
Matrix3d const & getTransformMatrix() const
getTransformMatrix returns the orthogonal matrix that maps vectors to the basis in which the quadrati...
Definition: Ellipse.h:229
static constexpr uint8_t TYPE_CODE
Definition: Ellipse.h:171
bool isCircle() const
Definition: Ellipse.h:224
Angle getAlpha() const
getAlpha returns α, the first semi-axis length of the ellipse.
Definition: Ellipse.h:251
UnitVector3d getF2() const
getF2 returns the second focal point of the ellipse.
Definition: Ellipse.h:243
bool isGreatCircle() const
Definition: Ellipse.h:222
static Ellipse full()
Definition: Ellipse.h:175
Angle getBeta() const
getBeta returns β, the second semi-axis length of the ellipse.
Definition: Ellipse.h:256
static std::unique_ptr< Ellipse > decode(std::vector< uint8_t > const &s)
Definition: Ellipse.h:302
Relationship relate(Region const &r) const override
Definition: Ellipse.h:288
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:188
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:194
Ellipse()
This constructor creates an empty ellipse.
Definition: Ellipse.h:178
Ellipse & complement()
complement sets this ellipse to the closure of its complement.
Definition: Ellipse.h:263
bool operator==(Ellipse const &e) const
Definition: Ellipse.h:212
UnitVector3d getF1() const
getF1 returns the first focal point of the ellipse.
Definition: Ellipse.h:237
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:260
bool operator!=(Ellipse const &e) const
Definition: Ellipse.h:216
std::unique_ptr< Region > clone() const override
clone returns a deep copy of this region.
Definition: Ellipse.h:276
bool isFull() const
Definition: Ellipse.h:220
static Ellipse empty()
Definition: Ellipse.h:173
bool isEmpty() const
Definition: Ellipse.h:218
Ellipse complemented() const
complemented returns the closure of the complement of this ellipse.
Definition: Ellipse.h:273
UnitVector3d getCenter() const
getCenter returns the center of the ellipse as a unit vector.
Definition: Ellipse.h:232
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)