lsst.sphgeom gac51dbfff8+052faf71bd
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
32#include "Circle.h"
33#include "Matrix3d.h"
34#include "Region.h"
35#include "UnitVector3d.h"
36
37
38namespace lsst {
39namespace sphgeom {
40
169class Ellipse : public Region {
170public:
171 static constexpr uint8_t TYPE_CODE = 'e';
172
173 static Ellipse empty() { return Ellipse(); }
174
175 static Ellipse full() { return Ellipse().complement(); }
176
179 _S(1.0),
180 _a(-2.0),
181 _b(-2.0),
182 _gamma(0.0),
183 _tana(std::numeric_limits<double>::infinity()),
184 _tanb(std::numeric_limits<double>::infinity())
185 {}
186
188 explicit Ellipse(Circle const & c) {
189 *this = Ellipse(c.getCenter(), c.getCenter(), c.getOpeningAngle());
190 }
191
194 explicit Ellipse(UnitVector3d const & v, Angle alpha = Angle(0.0)) {
195 *this = Ellipse(v, v, alpha);
196 }
197
200 Ellipse(UnitVector3d const & f1, UnitVector3d const & f2, Angle alpha);
201
207 Ellipse(UnitVector3d const & center,
208 Angle alpha,
209 Angle beta,
210 Angle orientation);
211
212 bool operator==(Ellipse const & e) const {
213 return _S == e._S && _a == e._a && _b == e._b;
214 }
215
216 bool operator!=(Ellipse const & e) const { return !(*this == e); }
217
218 bool isEmpty() const { return Angle(0.5 * PI) + _a < _gamma; }
219
220 bool isFull() const { return Angle(0.5 * PI) - _a <= _gamma; }
221
222 bool isGreatCircle() const { return _a.asRadians() == 0.0; }
223
224 bool isCircle() const { return _a == _b; }
225
229 Matrix3d const & getTransformMatrix() const { return _S; }
230
233 return UnitVector3d::fromNormalized(_S(2,0), _S(2,1), _S(2,2));
234 }
235
238 UnitVector3d n = UnitVector3d::fromNormalized(_S(1,0), _S(1,1), _S(1,2));
239 return getCenter().rotatedAround(n, -_gamma);
240 }
241
244 UnitVector3d n = UnitVector3d::fromNormalized(_S(1,0), _S(1,1), _S(1,2));
245 return getCenter().rotatedAround(n, _gamma);
246 }
247
251 Angle getAlpha() const { return Angle(0.5 * PI) + _a; }
252
256 Angle getBeta() const { return Angle(0.5 * PI) + _b; }
257
260 Angle getGamma() const { return _gamma; }
261
264 _S = Matrix3d(-_S(0,0), -_S(0,1), -_S(0,2),
265 _S(1,0), _S(1,1), _S(1,2),
266 -_S(2,0), -_S(2,1), -_S(2,2));
267 _a = -_a;
268 _b = -_b;
269 return *this;
270 }
271
273 Ellipse complemented() const { return Ellipse(*this).complement(); }
274
275 // Region interface
276 std::unique_ptr<Region> clone() const override {
277 return std::unique_ptr<Ellipse>(new Ellipse(*this));
278 }
279
280 Box getBoundingBox() const override;
281 Box3d getBoundingBox3d() const override;
282 Circle getBoundingCircle() const override;
283
284 bool contains(UnitVector3d const &v) const override;
285
286 using Region::contains;
287
288 Relationship relate(Region const & r) const override {
289 // Dispatch on the type of r.
290 return invert(r.relate(*this));
291 }
292
293 Relationship relate(Box const &) const override;
294 Relationship relate(Circle const &) const override;
295 Relationship relate(ConvexPolygon const &) const override;
296 Relationship relate(Ellipse const &) const override;
297
298 std::vector<uint8_t> encode() const override;
299
302 static std::unique_ptr<Ellipse> decode(std::vector<uint8_t> const & s) {
303 return decode(s.data(), s.size());
304 }
305 static std::unique_ptr<Ellipse> decode(uint8_t const * buffer, size_t n);
307
308private:
309 static constexpr size_t ENCODED_SIZE = 113;
310
311 Matrix3d _S;
312 Angle _a; // α - π/2
313 Angle _b; // β - π/2
314 Angle _gamma; // Half the angle between the ellipse foci
315 double _tana; // |tan a| = |cot α|
316 double _tanb; // |tan b| = |cot β|
317};
318
319std::ostream & operator<<(std::ostream &, Ellipse const &);
320
321}} // namespace lsst::sphgeom
322
323#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.
std::bitset< 3 > Relationship
Relationship describes how two sets are related.
Definition: Relationship.h:35
Relationship invert(Relationship r)
Definition: Relationship.h:55
This file declares a class for representing unit vectors in ℝ³.
Definition: Angle.h:43
double asRadians() const
asRadians returns the value of this angle in units of radians.
Definition: Angle.h:85
Definition: Box3d.h:42
Definition: Box.h:54
Definition: Circle.h:46
Angle getOpeningAngle() const
Definition: Circle.h:128
UnitVector3d const & getCenter() const
Definition: Circle.h:118
Definition: ConvexPolygon.h:57
Definition: Ellipse.h:169
Angle getAlpha() const
Definition: Ellipse.h:251
UnitVector3d getF2() const
getF2 returns the second focal point of the ellipse.
Definition: Ellipse.h:243
Angle getBeta() const
Definition: Ellipse.h:256
Relationship relate(Region const &r) const override
Definition: Ellipse.h:288
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:188
std::vector< uint8_t > encode() const override
Definition: Ellipse.cc:339
Ellipse(UnitVector3d const &v, Angle alpha=Angle(0.0))
Definition: Ellipse.h:194
Ellipse()
This constructor creates an empty ellipse.
Definition: Ellipse.h:178
UnitVector3d getF1() const
getF1 returns the first focal point of the ellipse.
Definition: Ellipse.h:237
Angle getGamma() const
Definition: Ellipse.h:260
static std::unique_ptr< Ellipse > decode(std::vector< uint8_t > const &s)
Definition: Ellipse.h:302
std::unique_ptr< Region > clone() const override
clone returns a deep copy of this region.
Definition: Ellipse.h:276
Ellipse & complement()
complement sets this ellipse to the closure of its complement.
Definition: Ellipse.h:263
Matrix3d const & getTransformMatrix() const
Definition: Ellipse.h:229
Ellipse complemented() const
complemented returns the closure of the complement of this ellipse.
Definition: Ellipse.h:273
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:232
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
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.
Definition: UnitVector3d.h:55
static UnitVector3d fromNormalized(Vector3d const &v)
Definition: UnitVector3d.h:82
UnitVector3d rotatedAround(UnitVector3d const &k, Angle a) const
Definition: UnitVector3d.h:193