LSST Applications g063fba187b+cac8b7c890,g0f08755f38+6aee506743,g1653933729+a8ce1bb630,g168dd56ebc+a8ce1bb630,g1a2382251a+b4475c5878,g1dcb35cd9c+8f9bc1652e,g20f6ffc8e0+6aee506743,g217e2c1bcf+73dee94bd0,g28da252d5a+1f19c529b9,g2bbee38e9b+3f2625acfc,g2bc492864f+3f2625acfc,g3156d2b45e+6e55a43351,g32e5bea42b+1bb94961c2,g347aa1857d+3f2625acfc,g35bb328faa+a8ce1bb630,g3a166c0a6a+3f2625acfc,g3e281a1b8c+c5dd892a6c,g3e8969e208+a8ce1bb630,g414038480c+5927e1bc1e,g41af890bb2+8a9e676b2a,g7af13505b9+809c143d88,g80478fca09+6ef8b1810f,g82479be7b0+f568feb641,g858d7b2824+6aee506743,g89c8672015+f4add4ffd5,g9125e01d80+a8ce1bb630,ga5288a1d22+2903d499ea,gb58c049af0+d64f4d3760,gc28159a63d+3f2625acfc,gcab2d0539d+b12535109e,gcf0d15dbbd+46a3f46ba9,gda6a2b7d83+46a3f46ba9,gdaeeff99f8+1711a396fd,ge79ae78c31+3f2625acfc,gef2f8181fd+0a71e47438,gf0baf85859+c1f95f4921,gfa517265be+6aee506743,gfa999e8aa5+17cd334064,w.2024.51
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 override { 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 TriState overlaps(Region const& other) const override {
307 return other.overlaps(*this);
308 }
309 TriState overlaps(Box const &) const override;
310 TriState overlaps(Circle const &) const override;
311 TriState overlaps(ConvexPolygon const &) const override;
312 TriState overlaps(Ellipse const &) const override;
313
314 std::vector<std::uint8_t> encode() const override;
315
319 return decode(s.data(), s.size());
320 }
321 static std::unique_ptr<Ellipse> decode(std::uint8_t const * buffer, size_t n);
323
324private:
325 static constexpr size_t ENCODED_SIZE = 113;
326
327 Matrix3d _S;
328 Angle _a; // α - π/2
329 Angle _b; // β - π/2
330 Angle _gamma; // Half the angle between the ellipse foci
331 double _tana; // |tan a| = |cot α|
332 double _tanb; // |tan b| = |cot β|
333};
334
335std::ostream & operator<<(std::ostream &, Ellipse const &);
336
337}} // namespace lsst::sphgeom
338
339#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:318
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:370
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
TriState overlaps(Region const &other) const override
Definition Ellipse.h:306
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
Matrix3d const & getTransformMatrix() const
getTransformMatrix returns the orthogonal matrix that maps vectors to the basis in which the quadrati...
Definition Ellipse.h:237
bool isEmpty() const override
isEmpty returns true when a region does not contain any points.
Definition Ellipse.h:226
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:89
virtual bool contains(UnitVector3d const &) const =0
contains tests whether the given unit vector is inside this region.
virtual TriState overlaps(Region const &other) const =0
Definition Region.cc:59
TriState represents a boolean value with additional unknown state.
Definition TriState.h:46
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.