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
|
Ellipse
is an elliptical region on the sphere.
More...
#include <Ellipse.h>
Public Member Functions | |
Ellipse () | |
This constructor creates an empty ellipse. | |
Ellipse (Circle const &c) | |
This constructor creates an ellipse corresponding to the given circle. | |
Ellipse (UnitVector3d const &v, Angle alpha=Angle(0.0)) | |
This constructor creates an ellipse corresponding to the circle with the given center and opening angle. | |
Ellipse (UnitVector3d const &f1, UnitVector3d const &f2, Angle alpha) | |
This constructor creates an ellipse with the given foci and semi-axis angle. | |
Ellipse (UnitVector3d const ¢er, Angle alpha, Angle beta, Angle orientation) | |
This constructor creates an ellipse with the given center, semi-axis angles, and orientation. | |
bool | operator== (Ellipse const &e) const |
bool | operator!= (Ellipse const &e) const |
bool | isEmpty () const override |
isEmpty returns true when a region does not contain any points. | |
bool | isFull () const |
bool | isGreatCircle () const |
bool | isCircle () const |
Matrix3d const & | getTransformMatrix () const |
getTransformMatrix returns the orthogonal matrix that maps vectors to the basis in which the quadratic form corresponding to this ellipse is diagonal. | |
UnitVector3d | getCenter () const |
getCenter returns the center of the ellipse as a unit vector. | |
UnitVector3d | getF1 () const |
getF1 returns the first focal point of the ellipse. | |
UnitVector3d | getF2 () const |
getF2 returns the second focal point of the ellipse. | |
Angle | getAlpha () const |
getAlpha returns α, the first semi-axis length of the ellipse. | |
Angle | getBeta () const |
getBeta returns β, the second semi-axis length of the ellipse. | |
Angle | getGamma () const |
getGamma returns ɣ ∈ [0, π/2], half of the angle between the foci. | |
Ellipse & | complement () |
complement sets this ellipse to the closure of its complement. | |
Ellipse | complemented () const |
complemented returns the closure of the complement of this ellipse. | |
std::unique_ptr< Region > | clone () const override |
clone returns a deep copy of this region. | |
Box | getBoundingBox () const override |
getBoundingBox returns a bounding-box for this region. | |
Box3d | getBoundingBox3d () const override |
getBoundingBox3d returns a 3-dimensional bounding-box for this region. | |
Circle | getBoundingCircle () const override |
getBoundingCircle returns a bounding-circle for this region. | |
bool | contains (UnitVector3d const &v) const override |
contains tests whether the given unit vector is inside this region. | |
Relationship | relate (Region const &r) const override |
Relationship | relate (Box const &) const override |
Relationship | relate (Circle const &) const override |
Relationship | relate (ConvexPolygon const &) const override |
Relationship | relate (Ellipse const &) const override |
TriState | overlaps (Region const &other) const override |
TriState | overlaps (Box const &) const override |
TriState | overlaps (Circle const &) const override |
TriState | overlaps (ConvexPolygon const &) const override |
TriState | overlaps (Ellipse const &) const override |
std::vector< std::uint8_t > | encode () const override |
encode serializes this region into an opaque byte string. | |
virtual bool | contains (UnitVector3d const &) const=0 |
contains tests whether the given unit vector is inside this region. | |
bool | contains (double x, double y, double z) const |
contains tests whether the unit vector defined by the given (not necessarily normalized) coordinates is inside this region. | |
bool | contains (double lon, double lat) const |
contains tests whether the unit vector defined by the given longitude and latitude coordinates (in radians) is inside this region. | |
Static Public Member Functions | |
static Ellipse | empty () |
static Ellipse | full () |
static std::vector< std::unique_ptr< Region > > | getRegions (Region const ®ion) |
getRegions returns a vector of Region. | |
static std::unique_ptr< Ellipse > | decode (std::vector< std::uint8_t > const &s) |
static std::unique_ptr< Ellipse > | decode (std::uint8_t const *buffer, size_t n) |
static std::unique_ptr< Region > | decodeBase64 (std::string const &s) |
static std::unique_ptr< Region > | decodeBase64 (std::string_view const &s) |
static TriState | decodeOverlapsBase64 (std::string const &s) |
static TriState | decodeOverlapsBase64 (std::string_view const &s) |
Static Public Attributes | |
static constexpr std::uint8_t | TYPE_CODE = 'e' |
Static Protected Member Functions | |
static TriState | _relationship_to_overlaps (Relationship r) |
Ellipse
is an elliptical region on the sphere.
A spherical ellipse is defined as the set of unit vectors v such that:
d(v,f₁) + d(v,f₂) ≤ 2α (Eq. 1)
where f₁ and f₂ are unit vectors corresponding to the foci of the ellipse, d is the function that returns the angle between its two input vectors, and α is a constant.
If 2α < d(f₁,f₂), no point in S² satisfies the inequality, and the ellipse is empty. If f₁ = f₂, the ellipse is a circle with opening angle α. The ellipse defined by foci -f₁ and -f₂, and angle π - α satisfies:
d(v,-f₁) + d(v,-f₂) ≤ 2(π - α) → π - d(v,f₁) + π - d(v,f₂) ≤ 2π - 2α → d(v,f₁) + d(v,f₂) ≥ 2α
In other words, it is the closure of the complement of the ellipse defined by f₁, f₂ and α. Therefore if 2π - 2α ≤ d(f₁,f₂), all points in S² satisfy Eq 1. and we say that the ellipse is full.
Consider now the equation d(v,f₁) + d(v,f₂) = 2α for v ∈ ℝ³. We know that
cos(d(v,fᵢ)) = (v·fᵢ)/(‖v‖‖fᵢ‖) = (v·fᵢ)/‖v‖ (since ‖fᵢ‖ = 1)
and, because sin²θ + cos²θ = 1 and ‖v‖² = v·v,
sin(d(v,fᵢ)) = √(v·v - (v·fᵢ)²)/‖v‖
Starting with:
d(v,f₁) + d(v,f₂) = 2α
we take the cosine of both sides, apply the angle sum identity for cosine, and substitute the expressions above to obtain:
cos(d(v,f₁) + d(v,f₂)) = cos 2α → cos(d(v,f₁)) cos(d(v,f₂)) - sin(d(v,f₁)) sin(d(v,f₂)) = cos 2α → (v·f₁) (v·f₂) - √(v·v - (v·f₁)²) √(v·v - (v·f₂)²) = cos 2α (v·v)
Rearranging to place the square roots on the RHS, squaring both sides, and simplifying:
((v·f₁) (v·f₂) - cos 2α (v·v))² = (v·v - (v·f₁)²) (v·v - (v·f₂)²) → cos²2α (v·v) - 2 cos 2α (v·f₁) (v·f₂) = (v·v) - (v·f₁)² - (v·f₂)² → sin²2α (v·v) + 2 cos 2α (v·f₁) (v·f₂) - (v·f₁)² - (v·f₂)² = 0 (Eq. 2)
Note in particular that if α = π/2, the above simplifies to:
(v·f₁ + v·f₂)² = 0 ↔ v·(f₁ + f₂) = 0
That is, the equation describes the great circle obtained by intersecting S² with the plane having normal vector f₁ + f₂.
Writing v = (x, y, z) and substituting into Eq. 2, we see that the LHS is a homogeneous polynomial of degree two in 3 variables, or a ternary quadratic form. The matrix representation of this quadratic form is the symmetric 3 by 3 matrix Q such that:
vᵀ Q v = 0
is equivalent to Eq. 2. Consider now the orthonormal basis vectors:
b₀ = (f₁ - f₂)/‖f₁ - f₂‖ b₁ = (f₁ × f₂)/‖f₁ × f₂‖ b₂ = (f₁ + f₂)/‖f₁ + f₂‖
where x denotes the vector cross product. Let S be the matrix with these basis vectors as rows. Given coordinates u in this basis, we have v = Sᵀ u, and:
(Sᵀ u)ᵀ Q (Sᵀ u) = 0 ↔ uᵀ (S Q Sᵀ) u = 0
We now show that D = S Q Sᵀ is diagonal. Let d(f₁,f₂) = 2ɣ. The coordinates of f₁ and f₂ in this new basis are f₁ = (sin ɣ, 0, cos ɣ) and f₂ = (-sin ɣ, 0, cos ɣ). Writing u = (x, y, z) and substituting into Eq. 2:
sin²2α (u·u) + 2 cos 2α (u·f₁) (u·f₂) - (u·f₁)² - (u·f₂)² = 0
we obtain:
(sin²2α - 2 cos 2α sin²ɣ - 2 sin²ɣ) x² + (sin²2α) y² + (sin²2α + 2 cos 2α cos²ɣ - 2 cos²ɣ) z² = 0
Now sin²2α = 4 sin²α cos²α, cos 2α = cos²α - sin²α, so that:
(cos²α (sin²α - sin²ɣ)) x² + (sin²α cos²α) y² + (sin²α (cos²α - cos²ɣ)) z² = 0
Dividing by sin²α (cos²ɣ - cos²α), and letting cos β = cos α / cos ɣ:
x² cot²α + y² cot²β - z² = 0 (Eq. 3)
This says that the non-zero elements of S Q Sᵀ are on the diagonal and equal to (cot²α, cot²β, -1) up to scale. In other words, the boundary of a spherical ellipse is given by the intersection of S² and an elliptical cone in ℝ³ passing through the origin. Because z = 0 → x,y = 0 it is evident that the boundary of a spherical ellipse is hemispherical.
If 0 < α < π/2, then β ≤ α, and α is the semi-major axis angle of the ellipse while β is the semi-minor axis angle.
If α = π/2, then the spherical ellipse corresponds to a hemisphere.
If π/2 < α < π, then β ≥ α, and α is the semi-minor axis angle of the ellipse, while β is the semi-major axis angle.
Internal state consists of the orthogonal transformation matrix S that maps the ellipse center to (0, 0, 1), as well as |cot α| and |cot β| (enough to reconstruct D, and hence Q), and α, β, ɣ.
In fact, a = α - π/2, b = β - π/2 are stored instead of α and β. This is for two reasons. The first is that when taking the complement of an ellipse, α is mapped to π - α but a is mapped to -a (and b → -b). As a result, taking the complement can be implemented using only changes of sign, and is therefore exact. The other reason is that |cot(α)| = |tan(a)|, and tan is more convenient numerically. In particular, cot(0) is undefined, but tan is finite since a is rational and cannot be exactly equal to ±π/2.
|
inline |
This constructor creates an empty ellipse.
Definition at line 186 of file Ellipse.h.
|
inlineexplicit |
This constructor creates an ellipse corresponding to the given circle.
|
inlineexplicit |
lsst::sphgeom::Ellipse::Ellipse | ( | UnitVector3d const & | f1, |
UnitVector3d const & | f2, | ||
Angle | alpha ) |
This constructor creates an ellipse with the given foci and semi-axis angle.
Definition at line 49 of file Ellipse.cc.
lsst::sphgeom::Ellipse::Ellipse | ( | UnitVector3d const & | center, |
Angle | alpha, | ||
Angle | beta, | ||
Angle | orientation ) |
This constructor creates an ellipse with the given center, semi-axis angles, and orientation.
The orientation is defined as the position angle (east of north) of the first axis with respect to the north pole. Note that both alpha and beta must be less than, greater than, or equal to PI/2.
Definition at line 109 of file Ellipse.cc.
|
inlinestaticprotectedinherited |
Definition at line 206 of file Region.h.
|
inlineoverridevirtual |
clone
returns a deep copy of this region.
Implements lsst::sphgeom::Region.
|
inline |
|
inline |
bool lsst::sphgeom::Region::contains | ( | double | lon, |
double | lat ) const |
contains
tests whether the unit vector defined by the given longitude and latitude coordinates (in radians) is inside this region.
Definition at line 117 of file Region.cc.
bool lsst::sphgeom::Region::contains | ( | double | x, |
double | y, | ||
double | z ) const |
|
virtual |
contains
tests whether the given unit vector is inside this region.
Implements lsst::sphgeom::Region.
|
overridevirtual |
contains
tests whether the given unit vector is inside this region.
Implements lsst::sphgeom::Region.
Definition at line 167 of file Ellipse.cc.
|
static |
decode
deserializes an Ellipse from a byte string produced by encode.
Definition at line 388 of file Ellipse.cc.
|
inlinestatic |
decode
deserializes an Ellipse from a byte string produced by encode.
Definition at line 318 of file Ellipse.h.
|
inlinestaticinherited |
decodeBase64
deserializes a Region from an ASCII string produced by encode and then base64-encoding that result.
This method also interprets ':' as a delimiter for the elements of a UnionRegion, to support cases where a union of region is constructed server-side in a database as a concatenation with that delimiter.
Definition at line 176 of file Region.h.
|
staticinherited |
decodeBase64
deserializes a Region from an ASCII string produced by encode and then base64-encoding that result.
This method also interprets ':' as a delimiter for the elements of a UnionRegion, to support cases where a union of region is constructed server-side in a database as a concatenation with that delimiter.
Definition at line 93 of file Region.cc.
|
inlinestaticinherited |
decodeOverlapsBase64
evaluates an encoded overlap expression.
A single overlap expression is formed by concatenating a pair of base64-encoded regions (Region::encode
then base64 encoding) with '&' as the delimiter. Multiple such pairwise overlap expressions can then be concatenated with '|' as the delimiter to form the logical OR.
|
staticinherited |
decodeOverlapsBase64
evaluates an encoded overlap expression.
A single overlap expression is formed by concatenating a pair of base64-encoded regions (Region::encode
then base64 encoding) with '&' as the delimiter. Multiple such pairwise overlap expressions can then be concatenated with '|' as the delimiter to form the logical OR.
Definition at line 117 of file Region.cc.
|
inlinestatic |
|
overridevirtual |
encode
serializes this region into an opaque byte string.
Byte strings emitted by encode can be deserialized with decode.
Implements lsst::sphgeom::Region.
Definition at line 370 of file Ellipse.cc.
|
inlinestatic |
|
inline |
|
inline |
|
overridevirtual |
getBoundingBox
returns a bounding-box for this region.
Implements lsst::sphgeom::Region.
Definition at line 197 of file Ellipse.cc.
|
overridevirtual |
getBoundingBox3d
returns a 3-dimensional bounding-box for this region.
Implements lsst::sphgeom::Region.
Definition at line 244 of file Ellipse.cc.
|
overridevirtual |
getBoundingCircle
returns a bounding-circle for this region.
Implements lsst::sphgeom::Region.
Definition at line 248 of file Ellipse.cc.
|
inline |
getCenter
returns the center of the ellipse as a unit vector.
Definition at line 240 of file Ellipse.h.
|
inline |
getF1
returns the first focal point of the ellipse.
|
inline |
getF2
returns the second focal point of the ellipse.
|
inline |
|
staticinherited |
getRegions
returns a vector of Region.
Definition at line 145 of file Region.cc.
|
inline |
|
inline |
|
inlineoverridevirtual |
isEmpty
returns true when a region does not contain any points.
Implements lsst::sphgeom::Region.
Definition at line 226 of file Ellipse.h.
|
inline |
|
inline |
|
inline |
|
inline |
overlaps
tests whether two regions overlap. This method returns a TriState
object, when the value is true
it means that regions definitely overlap, false
means they are definitely disjont, and unknown state means that they may or may not overlap.
Implements lsst::sphgeom::Region.
Definition at line 346 of file Ellipse.cc.
overlaps
tests whether two regions overlap. This method returns a TriState
object, when the value is true
it means that regions definitely overlap, false
means they are definitely disjont, and unknown state means that they may or may not overlap.
Implements lsst::sphgeom::Region.
Definition at line 352 of file Ellipse.cc.
|
overridevirtual |
overlaps
tests whether two regions overlap. This method returns a TriState
object, when the value is true
it means that regions definitely overlap, false
means they are definitely disjont, and unknown state means that they may or may not overlap.
Implements lsst::sphgeom::Region.
Definition at line 358 of file Ellipse.cc.
overlaps
tests whether two regions overlap. This method returns a TriState
object, when the value is true
it means that regions definitely overlap, false
means they are definitely disjont, and unknown state means that they may or may not overlap.
Implements lsst::sphgeom::Region.
Definition at line 364 of file Ellipse.cc.
overlaps
tests whether two regions overlap. This method returns a TriState
object, when the value is true
it means that regions definitely overlap, false
means they are definitely disjont, and unknown state means that they may or may not overlap.
Implements lsst::sphgeom::Region.
Definition at line 306 of file Ellipse.h.
|
overridevirtual |
relate
computes the spatial relationships between this region A and another region B. The return value S is a bitset with the following properties:
S & DISJOINT
is set only if A and B do not have any points in common.S & CONTAINS
is set only if A contains all points in B.S & WITHIN
is set only if B contains all points in A.Said another way: if the CONTAINS, WITHIN or DISJOINT bit is set, then the corresponding spatial relationship between the two regions holds conclusively. If it is not set, the relationship may or may not hold.
These semantics allow for conservative relationship computations. In particular, a Region may choose to implement relate
by replacing itself and/or the argument with a simplified bounding region.
Implements lsst::sphgeom::Region.
Definition at line 253 of file Ellipse.cc.
|
overridevirtual |
relate
computes the spatial relationships between this region A and another region B. The return value S is a bitset with the following properties:
S & DISJOINT
is set only if A and B do not have any points in common.S & CONTAINS
is set only if A contains all points in B.S & WITHIN
is set only if B contains all points in A.Said another way: if the CONTAINS, WITHIN or DISJOINT bit is set, then the corresponding spatial relationship between the two regions holds conclusively. If it is not set, the relationship may or may not hold.
These semantics allow for conservative relationship computations. In particular, a Region may choose to implement relate
by replacing itself and/or the argument with a simplified bounding region.
Implements lsst::sphgeom::Region.
Definition at line 334 of file Ellipse.cc.
|
overridevirtual |
relate
computes the spatial relationships between this region A and another region B. The return value S is a bitset with the following properties:
S & DISJOINT
is set only if A and B do not have any points in common.S & CONTAINS
is set only if A contains all points in B.S & WITHIN
is set only if B contains all points in A.Said another way: if the CONTAINS, WITHIN or DISJOINT bit is set, then the corresponding spatial relationship between the two regions holds conclusively. If it is not set, the relationship may or may not hold.
These semantics allow for conservative relationship computations. In particular, a Region may choose to implement relate
by replacing itself and/or the argument with a simplified bounding region.
Implements lsst::sphgeom::Region.
Definition at line 338 of file Ellipse.cc.
|
overridevirtual |
relate
computes the spatial relationships between this region A and another region B. The return value S is a bitset with the following properties:
S & DISJOINT
is set only if A and B do not have any points in common.S & CONTAINS
is set only if A contains all points in B.S & WITHIN
is set only if B contains all points in A.Said another way: if the CONTAINS, WITHIN or DISJOINT bit is set, then the corresponding spatial relationship between the two regions holds conclusively. If it is not set, the relationship may or may not hold.
These semantics allow for conservative relationship computations. In particular, a Region may choose to implement relate
by replacing itself and/or the argument with a simplified bounding region.
Implements lsst::sphgeom::Region.
Definition at line 342 of file Ellipse.cc.
|
inlineoverridevirtual |
relate
computes the spatial relationships between this region A and another region B. The return value S is a bitset with the following properties:
S & DISJOINT
is set only if A and B do not have any points in common.S & CONTAINS
is set only if A contains all points in B.S & WITHIN
is set only if B contains all points in A.Said another way: if the CONTAINS, WITHIN or DISJOINT bit is set, then the corresponding spatial relationship between the two regions holds conclusively. If it is not set, the relationship may or may not hold.
These semantics allow for conservative relationship computations. In particular, a Region may choose to implement relate
by replacing itself and/or the argument with a simplified bounding region.
Implements lsst::sphgeom::Region.
Definition at line 296 of file Ellipse.h.
|
staticconstexpr |