LSST Applications g1653933729+34a971ddd9,g28da252d5a+6ecf39ab43,g2bbee38e9b+7117419c07,g2bc492864f+7117419c07,g2cdde0e794+704103fe75,g3156d2b45e+6e87dc994a,g347aa1857d+7117419c07,g35bb328faa+34a971ddd9,g3a166c0a6a+7117419c07,g3e281a1b8c+8ec26ec694,g4005a62e65+ba0306790b,g414038480c+40f8eb5d96,g569e0e2b34+d8e684fe9f,g717e5f8c0f+b9f74a9651,g76fe02a360+28e3f83f63,g80478fca09+fdb1f299e2,g82479be7b0+2fffa722b6,g858d7b2824+b9f74a9651,g8b782ad322+b9f74a9651,g8cd86fa7b1+ed49507c07,g90e5cb8612+3a7ace1691,g9125e01d80+34a971ddd9,g979bb04a14+232ddb636d,g9a700aaafa+34a971ddd9,ga5288a1d22+3504ff4bc9,gae0086650b+34a971ddd9,gae74b0b5c6+761ee125be,gb3d89ef091+14ce01cc3a,gb58c049af0+ace264a4f2,gc28159a63d+7117419c07,gcf0d15dbbd+34f38ce56c,gda6a2b7d83+34f38ce56c,gdaeeff99f8+7774323b41,ge33fd446bb+b9f74a9651,ge5cf12406b+d328917b0a,ge79ae78c31+7117419c07,gf0baf85859+890af219f9,gf5289d68f6+fe3ed47e0d,w.2024.35
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.