@@ -17,11 +17,25 @@ SphericalCap(geom) = SphericalCap(GI.trait(geom), geom)
17
17
SphericalCap (t:: GI.PointTrait , geom) = SphericalCap (t, geom, 0 )
18
18
# TODO : add implementations for line string and polygon traits
19
19
# TODO : add implementations to merge two spherical caps
20
+ function _merge (x:: SphericalCap , y:: SphericalCap )
21
+ d = spherical_distance (x. point, y. point)
22
+ newradius = (x. radius + y. radius + d) / 2
23
+ if newradius < x. radius
24
+ # x contains y
25
+ x
26
+ elseif newradius < y. radius
27
+ # y contains x
28
+ y
29
+ else
30
+ excenter = 0.5 * (1 + (y. radius - x. radius) / d)
31
+ newcenter = x. point + slerp (x. point, y. point, excenter)
32
+ SphericalCap (newcenter, d)
33
+ end
34
+ end
20
35
# TODO : add implementations for multitraits based on this
21
36
22
37
# TODO : this returns an approximately antipodal point...
23
38
24
-
25
39
# TODO : exact-predicate intersection
26
40
# This is all inexact and thus subject to floating point error
27
41
function _intersects (x:: SphericalCap , y:: SphericalCap )
@@ -35,6 +49,10 @@ function _contains(big::SphericalCap, small::SphericalCap)
35
49
# small circle fits in big circle
36
50
return dist + small. radius < big. radius
37
51
end
52
+ function _contains (cap:: SphericalCap , point:: UnitSphericalPoint )
53
+ spherical_distance (cap. point, point) <= cap. radius
54
+ end
55
+
38
56
39
57
function circumcenter_on_unit_sphere (a:: UnitSphericalPoint , b:: UnitSphericalPoint , c:: UnitSphericalPoint )
40
58
LinearAlgebra. normalize (a × b + b × c + c × a)
0 commit comments