LSST Applications  21.0.0+c4f5df5339,21.0.0+e70536a077,21.0.0-1-ga51b5d4+7c60f8a6ea,21.0.0-10-g2408eff+b1a641d84b,21.0.0-10-g560fb7b+92b8ef9dd1,21.0.0-10-gcf60f90+43207ce272,21.0.0-14-gb69b93b5+4d76db0002,21.0.0-19-g1706eef1c+e734d31160,21.0.0-2-g103fe59+22a7c7c8af,21.0.0-2-g1367e85+7da664439d,21.0.0-2-g45278ab+e70536a077,21.0.0-2-g5242d73+7da664439d,21.0.0-2-g7f82c8f+6d2855f563,21.0.0-2-g8f08a60+9c9a9cfcc8,21.0.0-2-ga326454+6d2855f563,21.0.0-2-gde069b7+bedfc5e1fb,21.0.0-2-gecfae73+a861af6170,21.0.0-2-gfc62afb+7da664439d,21.0.0-3-g357aad2+c828dac3d2,21.0.0-3-g4be5c26+7da664439d,21.0.0-3-g65f322c+d4023cc212,21.0.0-3-g7d9da8d+c4f5df5339,21.0.0-3-gaa929c8+92b8ef9dd1,21.0.0-3-ge02ed75+0deb8c0c58,21.0.0-4-g3af6bfd+b012c929b5,21.0.0-4-g591bb35+0deb8c0c58,21.0.0-4-g88306b8+46a2861271,21.0.0-4-gc004bbf+238ceb0735,21.0.0-4-gccdca77+a5c54364a0,21.0.0-4-ge8a399c+58522bebd9,21.0.0-40-gd3a68701+eacd05cfb3,21.0.0-5-g7ebb681+ddcb963ef6,21.0.0-6-g2d4f3f3+e70536a077,21.0.0-6-g4e60332+0deb8c0c58,21.0.0-6-gf32990f+87b8d260e6,21.0.0-7-g6531d7b+988fabe502,21.0.0-8-ga5967ee+f92c332e12,master-gac4afde19b+0deb8c0c58,w.2021.08
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  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 
317 std::ostream & operator<<(std::ostream &, Ellipse const &);
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.
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:300
Relationship relate(Region const &r) const override
Definition: Ellipse.h:286
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
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
bool contains(UnitVector3d const &v) const override
contains tests whether the given unit vector is inside this region.
Definition: Ellipse.cc:160
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
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)