LSST Applications g0b6bd0c080+a72a5dd7e6,g1182afd7b4+2a019aa3bb,g17e5ecfddb+2b8207f7de,g1d67935e3f+06cf436103,g38293774b4+ac198e9f13,g396055baef+6a2097e274,g3b44f30a73+6611e0205b,g480783c3b1+98f8679e14,g48ccf36440+89c08d0516,g4b93dc025c+98f8679e14,g5c4744a4d9+a302e8c7f0,g613e996a0d+e1c447f2e0,g6c8d09e9e7+25247a063c,g7271f0639c+98f8679e14,g7a9cd813b8+124095ede6,g9d27549199+a302e8c7f0,ga1cf026fa3+ac198e9f13,ga32aa97882+7403ac30ac,ga786bb30fb+7a139211af,gaa63f70f4e+9994eb9896,gabf319e997+ade567573c,gba47b54d5d+94dc90c3ea,gbec6a3398f+06cf436103,gc6308e37c7+07dd123edb,gc655b1545f+ade567573c,gcc9029db3c+ab229f5caf,gd01420fc67+06cf436103,gd877ba84e5+06cf436103,gdb4cecd868+6f279b5b48,ge2d134c3d5+cc4dbb2e3f,ge448b5faa6+86d1ceac1d,gecc7e12556+98f8679e14,gf3ee170dca+25247a063c,gf4ac96e456+ade567573c,gf9f5ea5b4d+ac198e9f13,gff490e6085+8c2580be5c,w.2022.27
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
39namespace lsst {
40namespace sphgeom {
41
170class Ellipse : public Region {
171public:
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
239 UnitVector3d n = UnitVector3d::fromNormalized(_S(1,0), _S(1,1), _S(1,2));
240 return getCenter().rotatedAround(n, -_gamma);
241 }
242
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
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
309private:
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
320std::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
Angle getOpeningAngle() const
getOpeningAngle returns the opening angle of this circle - that is, the angle between its center vect...
Definition: Circle.h:128
UnitVector3d const & getCenter() const
getCenter returns the center of this circle as a unit vector.
Definition: Circle.h:118
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
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
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
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
Angle getGamma() const
getGamma returns ɣ ∈ [0, π/2], half of the angle between the foci.
Definition: Ellipse.h:261
static std::unique_ptr< Ellipse > decode(std::vector< uint8_t > const &s)
Definition: Ellipse.h:303
std::unique_ptr< Region > clone() const override
clone returns a deep copy of this region.
Definition: Ellipse.h:277
bool operator!=(Ellipse const &e) const
Definition: Ellipse.h:217
bool isFull() const
Definition: Ellipse.h:221
static Ellipse empty()
Definition: Ellipse.h:174
Ellipse & complement()
complement sets this ellipse to the closure of its complement.
Definition: Ellipse.h:264
bool isEmpty() const
Definition: Ellipse.h:219
Matrix3d const & getTransformMatrix() const
getTransformMatrix returns the orthogonal matrix that maps vectors to the basis in which the quadrati...
Definition: Ellipse.h:230
Ellipse complemented() const
complemented returns the closure of the complement of this ellipse.
Definition: Ellipse.h:274
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: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)