LSST Applications g05325017a3+be04ab5bc8,g2079a07aa2+3e9fd84d81,g20cdd03214+600de29eb2,g2305ad1205+5e1b0c67c7,g2bbee38e9b+69e041a28d,g337abbeb29+69e041a28d,g3a166c0a6a+69e041a28d,g4322eb9e3a+9670871960,g4e26c3aaff+9125fe5495,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+608c162c81,g5c3423f6d4+600de29eb2,g607f77f49a+600de29eb2,g69c4c69b53+69e041a28d,g858d7b2824+600de29eb2,g99cad8db69+a7f8c65a2d,g9ddcbc5298+9a081db1e4,ga1e77700b3+2cbb763275,ga8d6e2f9c9+7a336fa28a,gae0086650b+585e252eca,gb0e22166c9+0e73c8378f,gb7c702c636+aec2f3b930,gbb8dafda3b+7d1409958d,gc120e1dc64+acd995d0d8,gc28159a63d+69e041a28d,gcdd4ae20e8+5ef4c697da,gcf0d15dbbd+5ef4c697da,gd1535ee943+1ef0950dc9,gdaeeff99f8+f9a426f77a,gddc38dedce+585e252eca,ge79ae78c31+69e041a28d,gf905fbdb4b+471d9f2c03,gf907d663e3+01e3c6626b,gfbcc870c63+b310236976,w.2024.25
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 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<uint8_t> encode() const override;
307
311 return decode(s.data(), s.size());
312 }
313 static std::unique_ptr<Ellipse> decode(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:61
Circle is a circular region on the unit sphere that contains its boundary.
Definition Circle.h:53
Angle getOpeningAngle() const
getOpeningAngle returns the opening angle of this circle - that is, the angle between its center vect...
Definition Circle.h:135
UnitVector3d const & getCenter() const
getCenter returns the center of this circle as a unit vector.
Definition Circle.h:125
ConvexPolygon is a closed convex polygon on the unit sphere.
Ellipse is an elliptical region on the sphere.
Definition Ellipse.h:177
static constexpr uint8_t TYPE_CODE
Definition Ellipse.h:179
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
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
std::vector< uint8_t > encode() const override
encode serializes this region into an opaque byte string.
Definition Ellipse.cc:346
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
static std::unique_ptr< Ellipse > decode(std::vector< uint8_t > const &s)
Definition Ellipse.h:310
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:86
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.