30#ifndef LSST_SPHGEOM_CONVEXPOLYGONIMPL_H_
31#define LSST_SPHGEOM_CONVEXPOLYGONIMPL_H_
54template <
typename VertexIterator>
64 VertexIterator j = begin;
65 for (; j !=
end; i = j, ++j) {
68 double c = (*i).dot(*j);
69 double a = (s == 0.0 && c == 0.0) ? 0.0 :
std::atan2(s, c);
75template <
typename VertexIterator>
80 VertexIterator i = begin;
82 for (; i !=
end; ++i) {
83 cl2 =
std::max(cl2, (*i - c).getSquaredNorm());
91template <
typename VertexIterator>
93 Angle const eps(5.0e-10);
96 VertexIterator j = begin;
110 for (; j !=
end; i = j, ++j) {
112 bbox.expandTo(
Box(p, eps, eps));
113 if (!haveCW || !haveCCW) {
115 haveCCW = haveCCW || (o > 0);
116 haveCW = haveCW || (o < 0);
129 n.
x() * n.
x() + n.
y() * n.
y());
134 double zni = i->y() * n.
x() - i->x() * n.
y();
135 double znj = j->y() * n.
x() - j->x() * n.
y();
137 if (zni > 0.0 && znj < 0.0) {
140 }
else if (zni < 0.0 && znj > 0.0) {
150 bbox.expandTo(northPole);
151 }
else if (!haveCCW) {
153 bbox.expandTo(southPole);
158template <
typename VertexIterator>
160 static double const maxError = 1.0e-14;
162 VertexIterator j = begin;
163 double emin[3] = { j->x(), j->y(), j->z() };
164 double emax[3] = { j->x(), j->y(), j->z() };
165 for (++j; j !=
end; ++j) {
166 for (
int i = 0; i < 3; ++i) {
167 double v = j->operator()(i);
192 VertexIterator k = begin;
193 for (; k !=
end; j = k, ++k) {
195 for (
int i = 0; i < 3; ++i) {
200 i == 1 ? -d : n.
y() * ni,
201 i == 2 ? -d : n.
z() * ni);
206 double vdj = v.
dot(*j);
207 double vdk = v.dot(*k);
208 if (vdj >= 0.0 && vdk <= 0.0) {
211 if (vdj <= 0.0 && vdk >= 0.0) {
219 bool a[3] = {
true,
true,
true };
220 bool b[3] = {
true,
true,
true };
223 for (; k !=
end; j = k, ++k) {
228 a[0] = a[0] && (ox <= 0);
229 b[0] =
b[0] && (ox >= 0);
231 a[1] = a[1] && (oy <= 0);
232 b[1] =
b[1] && (oy >= 0);
234 a[2] = a[2] && (oz <= 0);
235 b[2] =
b[2] && (oz >= 0);
240 for (
int i = 0; i < 3; ++i) {
241 emin[i] = a[i] ? -1.0 :
std::max(-1.0, emin[i] - maxError);
242 emax[i] =
b[i] ? 1.0 :
std::min(1.0, emax[i] + maxError);
249template <
typename VertexIterator>
251 VertexIterator
const end,
255 VertexIterator j = begin;
256 for (; j !=
end; i = j, ++j) {
264template <
typename VertexIterator>
266 VertexIterator
const end,
273template <
typename VertexIterator>
275 VertexIterator
const end,
279 return CONTAINS | DISJOINT;
288 for (VertexIterator v = begin; v !=
end; ++v) {
289 double d = (*v - c.
getCenter()).getSquaredNorm();
298 }
else if (inside !=
b) {
341template <
typename VertexIterator1,
342 typename VertexIterator2>
344 VertexIterator1
const end1,
345 VertexIterator2
const begin2,
346 VertexIterator2
const end2)
361 for (VertexIterator1 i = begin1; i != end1; ++i) {
366 for (VertexIterator2 j = begin2; j != end2; ++j) {
373 return (all1 ? WITHIN : INTERSECTS) | (all2 ? CONTAINS : INTERSECTS);
381 for (VertexIterator1 a =
std::prev(end1),
b = begin1;
382 b != end1; a =
b, ++
b) {
383 for (VertexIterator2 c =
std::prev(end2), d = begin2;
384 d != end2; c = d, ++d) {
387 if (acd == bdc && acd != 0) {
390 if (cba == dab && cba == acd) {
400template <
typename VertexIterator>
402 VertexIterator
const end,
408template <
typename VertexIterator>
410 VertexIterator
const end,
This file declares a class for representing axis-aligned bounding boxes in ℝ³.
This file declares a class for representing circular regions on the unit sphere.
Angle represents an angle in radians.
AngleInterval represents closed intervals of arbitrary angles.
Box3d represents a box in ℝ³.
Box represents a rectangle in spherical coordinate space that contains its boundary.
Relationship relate(LonLat const &p) const
static NormalizedAngleInterval allLongitudes()
allLongitudes returns a normalized angle interval containing all valid longitude angles.
Circle is a circular region on the unit sphere that contains its boundary.
double getSquaredChordLength() const
getSquaredChordLength returns the squared length of chords between the circle center and points on th...
UnitVector3d const & getCenter() const
getCenter returns the center of this circle as a unit vector.
ConvexPolygon is a closed convex polygon on the unit sphere.
std::vector< UnitVector3d > const & getVertices() const
Ellipse is an elliptical region on the sphere.
Circle getBoundingCircle() const override
getBoundingCircle returns a bounding-circle for this region.
Interval1d represents closed intervals of ℝ.
LonLat represents a spherical coordinate (longitude/latitude angle) pair.
static Angle latitudeOf(Vector3d const &v)
latitudeOf returns the latitude of the point on the unit sphere corresponding to the direction of v.
UnitVector3d is a unit vector in ℝ³ with components stored in double precision.
Vector3d is a vector in ℝ³ with components stored in double precision.
double dot(Vector3d const &v) const
dot returns the inner product of this vector and v.
double normalize()
normalize scales this vector to have unit norm and returns its norm prior to scaling.
Vector3d cross(Vector3d const &v) const
cross returns the cross product of this vector and v.
bool contains(VertexIterator const begin, VertexIterator const end, UnitVector3d const &v)
Circle boundingCircle(VertexIterator const begin, VertexIterator const end)
Box3d boundingBox3d(VertexIterator const begin, VertexIterator const end)
UnitVector3d centroid(VertexIterator const begin, VertexIterator const end)
Relationship relate(VertexIterator const begin, VertexIterator const end, Box const &b)
Box boundingBox(VertexIterator const begin, VertexIterator const end)
int orientationZ(UnitVector3d const &b, UnitVector3d const &c)
orientationZ(b, c) is equivalent to orientation(UnitVector3d::Z(), b, c).
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...
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...
constexpr double MAX_SQUARED_CHORD_LENGTH_ERROR
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.
int orientationX(UnitVector3d const &b, UnitVector3d const &c)
orientationX(b, c) is equivalent to orientation(UnitVector3d::X(), b, c).
int orientationY(UnitVector3d const &b, UnitVector3d const &c)
orientationY(b, c) is equivalent to orientation(UnitVector3d::Y(), b, c).
This file declares a class for representing longitude/latitude angle boxes on the unit sphere.
This file declares a class for representing elliptical regions on the unit sphere.
This file declares functions for orienting points on the sphere.
This file declares miscellaneous utility functions.