LSSTApplications  19.0.0-14-gb0260a2+f7b33f63ed,20.0.0+028ca7aeb5,20.0.0+578ca8d785,20.0.0+95fe209e70,20.0.0+d1f8484762,20.0.0+ec0eb203f4,20.0.0-1-g253301a+95fe209e70,20.0.0-1-g2b7511a+ce6f728470,20.0.0-1-g5b95a8c+36cabaa438,20.0.0-1-gedffbd8+08e3982e2f,20.0.0-11-gd9dafd18+ee11e5b92d,20.0.0-16-gfab17e72e+f119078cbc,20.0.0-19-gb3c8180+76b8b4580d,20.0.0-2-g4dae9ad+b9c65d2db1,20.0.0-2-g61b8584+62d102034e,20.0.0-2-gb780d76+f45b7d88f4,20.0.0-2-ged6426c+c16e0e6c56,20.0.0-2-gf072044+95fe209e70,20.0.0-2-gf1f7952+b9c65d2db1,20.0.0-22-gdf434b7+b9c65d2db1,20.0.0-23-g10eeb28+266feae6ef,20.0.0-25-g3dcad98+7edba9c73c,20.0.0-3-g1653f94+62d102034e,20.0.0-3-g4cc78c6+1c0c6df15e,20.0.0-3-g8f21e14+cae0a2a29f,20.0.0-3-gbd60e8c+eb59cfae10,20.0.0-3-gbecbe05+a2681a7a86,20.0.0-36-g96d5af2b+330d9ff9b7,20.0.0-4-g97dc21a+7edba9c73c,20.0.0-4-gb4befbc+0084b8bcb8,20.0.0-4-gfea843c+f45b7d88f4,20.0.0-5-gdfe0fee+88049eac2d,20.0.0-6-g64f541c+f45b7d88f4,20.0.0-6-g9a5b7a1+db91213b54,20.0.0-67-g32d6278+0d86c2e7cd,20.0.0-9-g4aef684+e9f4309ef0,w.2020.44
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 
317 std::ostream & operator<<(std::ostream &, Ellipse const &);
318 
319 }} // namespace lsst::sphgeom
320 
321 #endif // LSST_SPHGEOM_ELLIPSE_H_
Region.h
This file defines an interface for spherical regions.
std::bitset
STL class.
lsst::sphgeom::Ellipse::operator==
bool operator==(Ellipse const &e) const
Definition: Ellipse.h:212
lsst::sphgeom::Ellipse::TYPE_CODE
static constexpr uint8_t TYPE_CODE
Definition: Ellipse.h:171
lsst::sphgeom::Region::relate
virtual Relationship relate(Region const &) const =0
lsst::sphgeom::PI
constexpr double PI
Definition: constants.h:36
lsst::sphgeom::Region
Region is a minimal interface for 2-dimensional regions on the unit sphere.
Definition: Region.h:79
lsst::sphgeom::Ellipse::getBeta
Angle getBeta() const
getBeta returns β, the second semi-axis length of the ellipse.
Definition: Ellipse.h:256
lsst::sphgeom::Ellipse::isCircle
bool isCircle() const
Definition: Ellipse.h:224
lsst::sphgeom::Angle::asRadians
double asRadians() const
asRadians returns the value of this angle in units of radians.
Definition: Angle.h:85
UnitVector3d.h
This file declares a class for representing unit vectors in ℝ³.
lsst::sphgeom::Ellipse::getTransformMatrix
Matrix3d const & getTransformMatrix() const
getTransformMatrix returns the orthogonal matrix that maps vectors to the basis in which the quadrati...
Definition: Ellipse.h:229
lsst::sphgeom::orientation
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
std::vector
STL class.
lsst::sphgeom::Ellipse::getF1
UnitVector3d getF1() const
getF1 returns the first focal point of the ellipse.
Definition: Ellipse.h:237
std::vector::size
T size(T... args)
lsst::sphgeom::Box
Box represents a rectangle in spherical coordinate space that contains its boundary.
Definition: Box.h:54
lsst::sphgeom::Ellipse::Ellipse
Ellipse(Circle const &c)
This constructor creates an ellipse corresponding to the given circle.
Definition: Ellipse.h:188
lsst::sphgeom::Ellipse::getBoundingBox3d
Box3d getBoundingBox3d() const override
getBoundingBox3d returns a 3-dimensional bounding-box for this region.
Definition: Ellipse.cc:237
lsst::sphgeom::Ellipse::empty
static Ellipse empty()
Definition: Ellipse.h:173
Circle.h
This file declares a class for representing circular regions on the unit sphere.
lsst::sphgeom::Box3d
Box3d represents a box in ℝ³.
Definition: Box3d.h:42
lsst::sphgeom::Ellipse::isFull
bool isFull() const
Definition: Ellipse.h:220
lsst::afw::table::Angle
lsst::geom::Angle Angle
Definition: misc.h:33
lsst::sphgeom::UnitVector3d
UnitVector3d is a unit vector in ℝ³ with components stored in double precision.
Definition: UnitVector3d.h:55
lsst::sphgeom::Circle::getOpeningAngle
Angle getOpeningAngle() const
getOpeningAngle returns the opening angle of this circle - that is, the angle between its center vect...
Definition: Circle.h:128
lsst::sphgeom::ConvexPolygon
ConvexPolygon is a closed convex polygon on the unit sphere.
Definition: ConvexPolygon.h:57
lsst::sphgeom::Ellipse::Ellipse
Ellipse()
This constructor creates an empty ellipse.
Definition: Ellipse.h:178
std::ostream
STL class.
lsst::sphgeom::Ellipse
Ellipse is an elliptical region on the sphere.
Definition: Ellipse.h:169
lsst::sphgeom::Ellipse::decode
static std::unique_ptr< Ellipse > decode(std::vector< uint8_t > const &s)
Definition: Ellipse.h:300
lsst::sphgeom::Ellipse::isEmpty
bool isEmpty() const
Definition: Ellipse.h:218
lsst::sphgeom::Ellipse::getBoundingBox
Box getBoundingBox() const override
getBoundingBox returns a bounding-box for this region.
Definition: Ellipse.cc:190
lsst::sphgeom::Ellipse::getAlpha
Angle getAlpha() const
getAlpha returns α, the first semi-axis length of the ellipse.
Definition: Ellipse.h:251
lsst::sphgeom::Ellipse::complemented
Ellipse complemented() const
complemented returns the closure of the complement of this ellipse.
Definition: Ellipse.h:273
lsst::sphgeom::Ellipse::complement
Ellipse & complement()
complement sets this ellipse to the closure of its complement.
Definition: Ellipse.h:263
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
lsst::sphgeom::Ellipse::operator!=
bool operator!=(Ellipse const &e) const
Definition: Ellipse.h:216
lsst::sphgeom::Matrix3d
A 3x3 matrix with real entries stored in double precision.
Definition: Matrix3d.h:38
std
STL namespace.
lsst::sphgeom::UnitVector3d::rotatedAround
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
lsst::sphgeom::Ellipse::isGreatCircle
bool isGreatCircle() const
Definition: Ellipse.h:222
lsst::sphgeom::Ellipse::getGamma
Angle getGamma() const
getGamma returns ɣ ∈ [0, π/2], half of the angle between the foci.
Definition: Ellipse.h:260
lsst::sphgeom::Ellipse::getF2
UnitVector3d getF2() const
getF2 returns the second focal point of the ellipse.
Definition: Ellipse.h:243
lsst::sphgeom::Ellipse::contains
bool contains(UnitVector3d const &v) const override
contains tests whether the given unit vector is inside this region.
Definition: Ellipse.cc:160
lsst::sphgeom::Angle
Angle represents an angle in radians.
Definition: Angle.h:43
lsst::sphgeom::Ellipse::relate
Relationship relate(Region const &r) const override
Definition: Ellipse.h:286
lsst::sphgeom::operator<<
std::ostream & operator<<(std::ostream &, Angle const &)
Definition: Angle.cc:34
Matrix3d.h
This file contains a class representing 3x3 real matrices.
lsst::sphgeom::Circle::getCenter
UnitVector3d const & getCenter() const
getCenter returns the center of this circle as a unit vector.
Definition: Circle.h:118
lsst::sphgeom::Ellipse::getBoundingCircle
Circle getBoundingCircle() const override
getBoundingCircle returns a bounding-circle for this region.
Definition: Ellipse.cc:241
lsst::sphgeom::Ellipse::getCenter
UnitVector3d getCenter() const
getCenter returns the center of the ellipse as a unit vector.
Definition: Ellipse.h:232
lsst::sphgeom::Circle
Circle is a circular region on the unit sphere that contains its boundary.
Definition: Circle.h:46
std::unique_ptr
STL class.
lsst::sphgeom::UnitVector3d::fromNormalized
static UnitVector3d fromNormalized(Vector3d const &v)
fromNormalized returns the unit vector equal to v, which is assumed to be normalized.
Definition: UnitVector3d.h:82
std::vector::data
T data(T... args)
lsst::sphgeom::invert
Relationship invert(Relationship r)
Given the relationship between two sets A and B (i.e.
Definition: Relationship.h:55
lsst::sphgeom::Ellipse::full
static Ellipse full()
Definition: Ellipse.h:175
lsst::sphgeom::Ellipse::Ellipse
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
lsst::sphgeom::Ellipse::clone
std::unique_ptr< Region > clone() const override
clone returns a deep copy of this region.
Definition: Ellipse.h:276
lsst::sphgeom::Ellipse::encode
std::vector< uint8_t > encode() const override
encode serializes this region into an opaque byte string.
Definition: Ellipse.cc:339