23 #ifndef LSST_SPHGEOM_CONVEXPOLYGONIMPL_H_ 24 #define LSST_SPHGEOM_CONVEXPOLYGONIMPL_H_ 47 template <
typename VertexIterator>
57 VertexIterator j = begin;
58 for (; j !=
end; i = j, ++j) {
61 double c = (*i).dot(*j);
62 double a = (s == 0.0 && c == 0.0) ? 0.0 :
std::atan2(s, c);
68 template <
typename VertexIterator>
73 VertexIterator i = begin;
75 for (; i !=
end; ++i) {
76 cl2 =
std::max(cl2, (*i - c).getSquaredNorm());
84 template <
typename VertexIterator>
86 Angle const eps(5.0e-10);
89 VertexIterator j = begin;
103 for (; j !=
end; i = j, ++j) {
106 if (!haveCW || !haveCCW) {
108 haveCCW = haveCCW || (o > 0);
109 haveCW = haveCW || (o < 0);
122 n.
x() * n.
x() + n.
y() * n.
y());
127 double zni = i->
y() * n.
x() - i->x() * n.
y();
128 double znj = j->y() * n.
x() - j->x() * n.
y();
130 if (zni > 0.0 && znj < 0.0) {
133 }
else if (zni < 0.0 && znj > 0.0) {
144 }
else if (!haveCCW) {
151 template <
typename VertexIterator>
153 static double const maxError = 1.0e-14;
155 VertexIterator j = begin;
156 double emin[3] = { j->
x(), j->y(), j->z() };
157 double emax[3] = { j->x(), j->y(), j->z() };
158 for (++j; j !=
end; ++j) {
159 for (
int i = 0; i < 3; ++i) {
160 double v = j->operator()(i);
185 VertexIterator k = begin;
186 for (; k !=
end; j = k, ++k) {
188 for (
int i = 0; i < 3; ++i) {
193 i == 1 ? -d :
n.y() * ni,
194 i == 2 ? -d :
n.z() * ni);
199 double vdj = v.
dot(*j);
200 double vdk = v.dot(*k);
201 if (vdj >= 0.0 && vdk <= 0.0) {
204 if (vdj <= 0.0 && vdk >= 0.0) {
212 bool a[3] = {
true,
true,
true };
213 bool b[3] = {
true,
true,
true };
216 for (; k !=
end; j = k, ++k) {
221 a[0] = a[0] && (ox <= 0);
222 b[0] = b[0] && (ox >= 0);
224 a[1] = a[1] && (oy <= 0);
225 b[1] = b[1] && (oy >= 0);
227 a[2] = a[2] && (oz <= 0);
228 b[2] = b[2] && (oz >= 0);
233 for (
int i = 0; i < 3; ++i) {
234 emin[i] = a[i] ? -1.0 :
std::max(-1.0, emin[i] - maxError);
235 emax[i] = b[i] ? 1.0 :
std::min(1.0, emax[i] + maxError);
242 template <
typename VertexIterator>
244 VertexIterator
const end,
248 VertexIterator j = begin;
249 for (; j !=
end; i = j, ++j) {
257 template <
typename VertexIterator>
259 VertexIterator
const end,
266 template <
typename VertexIterator>
268 VertexIterator
const end,
272 return CONTAINS | DISJOINT;
281 for (VertexIterator v = begin; v !=
end; ++v) {
282 double d = (*v - c.
getCenter()).getSquaredNorm();
291 }
else if (inside != b) {
334 template <
typename VertexIterator1,
335 typename VertexIterator2>
337 VertexIterator1
const end1,
338 VertexIterator2
const begin2,
339 VertexIterator2
const end2)
354 for (VertexIterator1 i = begin1; i != end1; ++i) {
359 for (VertexIterator2 j = begin2; j != end2; ++j) {
366 return (all1 ? WITHIN : INTERSECTS) | (all2 ? CONTAINS : INTERSECTS);
374 for (VertexIterator1
a =
std::prev(end1),
b = begin1;
375 b != end1;
a =
b, ++
b) {
376 for (VertexIterator2 c =
std::prev(end2), d = begin2;
377 d != end2; c = d, ++d) {
380 if (acd == bdc && acd != 0) {
383 if (cba == dab && cba == acd) {
393 template <
typename VertexIterator>
395 VertexIterator
const end,
401 template <
typename VertexIterator>
403 VertexIterator
const end,
411 #endif // LSST_SPHGEOM_CONVEXPOLYGONIMPL_H_
double normalize()
normalize scales this vector to have unit norm and returns its norm prior to scaling.
This file declares a class for representing circular regions on the unit sphere.
Box & expandTo(LonLat const &x)
static NormalizedAngleInterval allLongitudes()
allLongitudes returns a normalized angle interval containing all valid longitude angles.
bool contains(VertexIterator const begin, VertexIterator const end, UnitVector3d const &v)
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.
Box boundingBox(VertexIterator const begin, VertexIterator const end)
double getSquaredChordLength() const
getSquaredChordLength returns the squared length of chords between the circle center and points on th...
AngleInterval represents closed intervals of arbitrary angles.
constexpr double MAX_SQUARED_CHORD_LENGTH_ERROR
int orientationZ(UnitVector3d const &b, UnitVector3d const &c)
orientationZ(b, c) is equivalent to orientation(UnitVector3d::Z(), b, c).
Interval1d represents closed intervals of ℝ.
This file declares a class for representing axis-aligned bounding boxes in ℝ³.
This file declares a class for representing elliptical regions on the unit sphere.
Vector3d is a vector in ℝ³ with components stored in double precision.
Box represents a rectangle in spherical coordinate space that contains its boundary.
This file declares miscellaneous utility functions.
Relationship relate(LonLat const &p) const
double getMinSquaredChordLength(Vector3d const &v, Vector3d const &a, Vector3d const &b, Vector3d const &n)
Let p be the unit vector closest to v that lies on the plane with normal n in the direction of the cr...
Ellipse is an elliptical region on the sphere.
A base class for image defects.
std::vector< UnitVector3d > const & getVertices() const
UnitVector3d centroid(VertexIterator const begin, VertexIterator const end)
This file declares a class for representing longitude/latitude angle boxes on the unit sphere...
NormalizedAngleInterval const & getLon() const
getLon returns the longitude interval of this box.
Relationship relate(VertexIterator const begin, VertexIterator const end, Box const &b)
static Angle latitudeOf(Vector3d const &v)
latitudeOf returns the latitude of the point on the unit sphere corresponding to the direction of v...
Derived expandedTo(Scalar x) const
double getMaxSquaredChordLength(Vector3d const &v, Vector3d const &a, Vector3d const &b, Vector3d const &n)
Let p be the unit vector furthest from v that lies on the plane with normal n in the direction of the...
int orientationY(UnitVector3d const &b, UnitVector3d const &c)
orientationY(b, c) is equivalent to orientation(UnitVector3d::Y(), b, c).
Circle is a circular region on the unit sphere that contains its boundary.
ConvexPolygon is a closed convex polygon on the unit sphere.
Circle getBoundingCircle() const override
getBoundingCircle returns a bounding-circle for this region.
Angle represents an angle in radians.
AngleInterval const & getLat() const
getLat returns the latitude interval of this box.
UnitVector3d const & getCenter() const
getCenter returns the center of this circle as a unit vector.
This file declares functions for orienting points on the sphere.
LonLat represents a spherical coordinate (longitude/latitude angle) pair.
Vector3d cross(Vector3d const &v) const
cross returns the cross product of this vector and v.
Box3d represents a box in ℝ³.
UnitVector3d is a unit vector in ℝ³ with components stored in double precision.
Interval1d const & x() const
Box3d boundingBox3d(VertexIterator const begin, VertexIterator const end)
int orientationX(UnitVector3d const &b, UnitVector3d const &c)
orientationX(b, c) is equivalent to orientation(UnitVector3d::X(), b, c).
Circle boundingCircle(VertexIterator const begin, VertexIterator const end)
double dot(Vector3d const &v) const
dot returns the inner product of this vector and v.