LSST Applications g0dd1f4853b+000f002471,g1635faa6d4+54714fab34,g1653933729+a8ce1bb630,g28da252d5a+640a8c72f3,g2bbee38e9b+c2093a7170,g2bc492864f+c2093a7170,g2cdde0e794+6a4d5c7d0d,g3156d2b45e+07302053f8,g347aa1857d+c2093a7170,g35bb328faa+a8ce1bb630,g3a166c0a6a+c2093a7170,g3e281a1b8c+f03ad10ea9,g4005a62e65+17cd334064,g414038480c+137065b082,g41af890bb2+0645dabe59,g531c6476d5+deede3a0e4,g57cf332d5c+a9d52f23c2,g781aacb6e4+a8ce1bb630,g80478fca09+80d930fbca,g82479be7b0+c2cd99eb83,g858d7b2824+deede3a0e4,g9125e01d80+a8ce1bb630,ga5288a1d22+bfa28a6548,gae0086650b+a8ce1bb630,gb58c049af0+d64f4d3760,gc28159a63d+c2093a7170,gca434f2906+4dfa4c7e5b,gcf0d15dbbd+4cd0bd49fc,gcfacc2a72f+8eff0b70f0,gda3e153d99+deede3a0e4,gda6a2b7d83+4cd0bd49fc,gdaeeff99f8+1711a396fd,gdd07d4df61+5730f16813,ge2409df99d+ccdeb281c7,ge33fd446bb+deede3a0e4,ge79ae78c31+c2093a7170,gf0baf85859+147a0692ba,gf3967379c6+1be82fceb0,v28.0.0.rc1
LSST Data Management Base Package
Loading...
Searching...
No Matches
Ellipse.h
Go to the documentation of this file.
1/*
2 * This file is part of sphgeom.
3 *
4 * Developed for the LSST Data Management System.
5 * This product includes software developed by the LSST Project
6 * (http://www.lsst.org).
7 * See the COPYRIGHT file at the top-level directory of this distribution
8 * for details of code ownership.
9 *
10 * This software is dual licensed under the GNU General Public License and also
11 * under a 3-clause BSD license. Recipients may choose which of these licenses
12 * to use; please see the files gpl-3.0.txt and/or bsd_license.txt,
13 * respectively. If you choose the GPL option then the following text applies
14 * (but note that there is still no warranty even if you opt for BSD instead):
15 *
16 * This program is free software: you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation, either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program. If not, see <http://www.gnu.org/licenses/>.
28 */
29
30#ifndef LSST_SPHGEOM_ELLIPSE_H_
31#define LSST_SPHGEOM_ELLIPSE_H_
32
36
37#include <iosfwd>
38#include <limits>
39
40#include "Circle.h"
41#include "Matrix3d.h"
42#include "Region.h"
43#include "UnitVector3d.h"
44
45
46namespace lsst {
47namespace sphgeom {
48
177class Ellipse : public Region {
178public:
179 static constexpr std::uint8_t TYPE_CODE = 'e';
180
181 static Ellipse empty() { return Ellipse(); }
182
183 static Ellipse full() { return Ellipse().complement(); }
184
187 _S(1.0),
188 _a(-2.0),
189 _b(-2.0),
190 _gamma(0.0),
191 _tana(std::numeric_limits<double>::infinity()),
192 _tanb(std::numeric_limits<double>::infinity())
193 {}
194
196 explicit Ellipse(Circle const & c) {
197 *this = Ellipse(c.getCenter(), c.getCenter(), c.getOpeningAngle());
198 }
199
202 explicit Ellipse(UnitVector3d const & v, Angle alpha = Angle(0.0)) {
203 *this = Ellipse(v, v, alpha);
204 }
205
208 Ellipse(UnitVector3d const & f1, UnitVector3d const & f2, Angle alpha);
209
215 Ellipse(UnitVector3d const & center,
216 Angle alpha,
217 Angle beta,
219
220 bool operator==(Ellipse const & e) const {
221 return _S == e._S && _a == e._a && _b == e._b;
222 }
223
224 bool operator!=(Ellipse const & e) const { return !(*this == e); }
225
226 bool isEmpty() const { return Angle(0.5 * PI) + _a < _gamma; }
227
228 bool isFull() const { return Angle(0.5 * PI) - _a <= _gamma; }
229
230 bool isGreatCircle() const { return _a.asRadians() == 0.0; }
231
232 bool isCircle() const { return _a == _b; }
233
237 Matrix3d const & getTransformMatrix() const { return _S; }
238
241 return UnitVector3d::fromNormalized(_S(2,0), _S(2,1), _S(2,2));
242 }
243
246 UnitVector3d n = UnitVector3d::fromNormalized(_S(1,0), _S(1,1), _S(1,2));
247 return getCenter().rotatedAround(n, -_gamma);
248 }
249
252 UnitVector3d n = UnitVector3d::fromNormalized(_S(1,0), _S(1,1), _S(1,2));
253 return getCenter().rotatedAround(n, _gamma);
254 }
255
259 Angle getAlpha() const { return Angle(0.5 * PI) + _a; }
260
264 Angle getBeta() const { return Angle(0.5 * PI) + _b; }
265
268 Angle getGamma() const { return _gamma; }
269
272 _S = Matrix3d(-_S(0,0), -_S(0,1), -_S(0,2),
273 _S(1,0), _S(1,1), _S(1,2),
274 -_S(2,0), -_S(2,1), -_S(2,2));
275 _a = -_a;
276 _b = -_b;
277 return *this;
278 }
279
281 Ellipse complemented() const { return Ellipse(*this).complement(); }
282
283 // Region interface
285 return std::unique_ptr<Ellipse>(new Ellipse(*this));
286 }
287
288 Box getBoundingBox() const override;
289 Box3d getBoundingBox3d() const override;
290 Circle getBoundingCircle() const override;
291
292 bool contains(UnitVector3d const &v) const override;
293
294 using Region::contains;
295
296 Relationship relate(Region const & r) const override {
297 // Dispatch on the type of r.
298 return invert(r.relate(*this));
299 }
300
301 Relationship relate(Box const &) const override;
302 Relationship relate(Circle const &) const override;
303 Relationship relate(ConvexPolygon const &) const override;
304 Relationship relate(Ellipse const &) const override;
305
306 std::vector<std::uint8_t> encode() const override;
307
311 return decode(s.data(), s.size());
312 }
313 static std::unique_ptr<Ellipse> decode(std::uint8_t const * buffer, size_t n);
315
316private:
317 static constexpr size_t ENCODED_SIZE = 113;
318
319 Matrix3d _S;
320 Angle _a; // α - π/2
321 Angle _b; // β - π/2
322 Angle _gamma; // Half the angle between the ellipse foci
323 double _tana; // |tan a| = |cot α|
324 double _tanb; // |tan b| = |cot β|
325};
326
327std::ostream & operator<<(std::ostream &, Ellipse const &);
328
329}} // namespace lsst::sphgeom
330
331#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:50
double asRadians() const
asRadians returns the value of this angle in units of radians.
Definition Angle.h:92
Box3d represents a box in ℝ³.
Definition Box3d.h:49
Box represents a rectangle in spherical coordinate space that contains its boundary.
Definition Box.h:62
Circle is a circular region on the unit sphere that contains its boundary.
Definition Circle.h:54
Angle getOpeningAngle() const
getOpeningAngle returns the opening angle of this circle - that is, the angle between its center vect...
Definition Circle.h:136
UnitVector3d const & getCenter() const
getCenter returns the center of this circle as a unit vector.
Definition Circle.h:126
ConvexPolygon is a closed convex polygon on the unit sphere.
Ellipse is an elliptical region on the sphere.
Definition Ellipse.h:177
static constexpr std::uint8_t TYPE_CODE
Definition Ellipse.h:179
static std::unique_ptr< Ellipse > decode(std::vector< std::uint8_t > const &s)
Definition Ellipse.h:310
bool isCircle() const
Definition Ellipse.h:232
Angle getAlpha() const
getAlpha returns α, the first semi-axis length of the ellipse.
Definition Ellipse.h:259
UnitVector3d getF2() const
getF2 returns the second focal point of the ellipse.
Definition Ellipse.h:251
bool isGreatCircle() const
Definition Ellipse.h:230
static Ellipse full()
Definition Ellipse.h:183
std::vector< std::uint8_t > encode() const override
encode serializes this region into an opaque byte string.
Definition Ellipse.cc:346
Angle getBeta() const
getBeta returns β, the second semi-axis length of the ellipse.
Definition Ellipse.h:264
Relationship relate(Region const &r) const override
Definition Ellipse.h:296
Circle getBoundingCircle() const override
getBoundingCircle returns a bounding-circle for this region.
Definition Ellipse.cc:248
Box getBoundingBox() const override
getBoundingBox returns a bounding-box for this region.
Definition Ellipse.cc:197
Ellipse(Circle const &c)
This constructor creates an ellipse corresponding to the given circle.
Definition Ellipse.h:196
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:202
Ellipse()
This constructor creates an empty ellipse.
Definition Ellipse.h:186
bool operator==(Ellipse const &e) const
Definition Ellipse.h:220
UnitVector3d getF1() const
getF1 returns the first focal point of the ellipse.
Definition Ellipse.h:245
Angle getGamma() const
getGamma returns ɣ ∈ [0, π/2], half of the angle between the foci.
Definition Ellipse.h:268
std::unique_ptr< Region > clone() const override
clone returns a deep copy of this region.
Definition Ellipse.h:284
bool operator!=(Ellipse const &e) const
Definition Ellipse.h:224
bool isFull() const
Definition Ellipse.h:228
static Ellipse empty()
Definition Ellipse.h:181
Ellipse & complement()
complement sets this ellipse to the closure of its complement.
Definition Ellipse.h:271
bool isEmpty() const
Definition Ellipse.h:226
Matrix3d const & getTransformMatrix() const
getTransformMatrix returns the orthogonal matrix that maps vectors to the basis in which the quadrati...
Definition Ellipse.h:237
Ellipse complemented() const
complemented returns the closure of the complement of this ellipse.
Definition Ellipse.h:281
bool contains(UnitVector3d const &v) const override
contains tests whether the given unit vector is inside this region.
Definition Ellipse.cc:167
UnitVector3d getCenter() const
getCenter returns the center of the ellipse as a unit vector.
Definition Ellipse.h:240
Box3d getBoundingBox3d() const override
getBoundingBox3d returns a 3-dimensional bounding-box for this region.
Definition Ellipse.cc:244
A 3x3 matrix with real entries stored in double precision.
Definition Matrix3d.h:45
Region is a minimal interface for 2-dimensional regions on the unit sphere.
Definition Region.h:87
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.
static UnitVector3d fromNormalized(Vector3d const &v)
fromNormalized returns the unit vector equal to v, which is assumed to be normalized.
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...
std::ostream & operator<<(std::ostream &, Angle const &)
Definition Angle.cc:41
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.
constexpr double PI
Definition constants.h:43
Relationship invert(Relationship r)
Given the relationship between two sets A and B (i.e.
STL namespace.