@@ -7,29 +7,29 @@ function infbounds(x,y)
77 return (typeinf, typeinf)
88end
99
10- function loose_distance_bounds (x:: SVector{3,<:Number} , y:: SVector{3,<:Number} , σᵣ:: Number , σₜ:: Number )
10+ function loose_distance_bounds (x:: SVector{3,<:Number} , y:: SVector{3,<:Number} , σᵣ:: Number , σₜ:: Number , maximize :: Bool = false )
1111 ubdist = norm (x - y)
1212 γₜ = sqrt3 * σₜ
1313 γᵣ = 2 * sin (min (sqrt3 * σᵣ, π) / 2 ) * norm (x)
14- lb, ub = max (ubdist - γₜ - γᵣ, 0 ), ubdist
14+ lb, ub = maximize ? ( max (ubdist - γₜ - γᵣ, 0 ), ubdist) : (ubddist + γₜ + γᵣ, ubdist)
1515 numtype = promote_type (typeof (lb), typeof (ub))
1616 return numtype (lb), numtype (ub)
1717end
18- loose_distance_bounds (x:: SVector{3} , y:: SVector{3} , R:: RotationVec , T:: SVector{3} , σᵣ, σₜ
19- ) = (R. sx^ 2 + R. sy^ 2 + R. sz^ 2 ) > pisq ? infbounds (x,y) : loose_distance_bounds (R* x, y- T, σᵣ, σₜ) # loose_distance_bounds(R*x, y-T, σᵣ, σₜ)
20- loose_distance_bounds (x:: SVector{3} , y:: SVector{3} , block:: UncertaintyRegion ) = loose_distance_bounds (x, y, block. R, block. T, block. σᵣ, block. σₜ)
21- loose_distance_bounds (x:: SVector{3} , y:: SVector{3} , block:: SearchRegion ) = loose_distance_bounds (x, y, UncertaintyRegion (block))
18+ loose_distance_bounds (x:: SVector{3} , y:: SVector{3} , R:: RotationVec , T:: SVector{3} , σᵣ, σₜ, maximize :: Bool = false ,
19+ ) = (R. sx^ 2 + R. sy^ 2 + R. sz^ 2 ) > pisq ? infbounds (x,y) : loose_distance_bounds (R* x, y- T, σᵣ, σₜ, maximize ) # loose_distance_bounds(R*x, y-T, σᵣ, σₜ)
20+ loose_distance_bounds (x:: SVector{3} , y:: SVector{3} , block:: UncertaintyRegion , maximize :: Bool = false ) = loose_distance_bounds (x, y, block. R, block. T, block. σᵣ, block. σₜ, maximize )
21+ loose_distance_bounds (x:: SVector{3} , y:: SVector{3} , block:: SearchRegion , maximize :: Bool = false ) = loose_distance_bounds (x, y, UncertaintyRegion (block), maximize )
2222
2323
2424"""
2525 lb, ub = tight_distance_bounds(x::SVector{3,<:Number}, y::SVector{3,<:Number}, σᵣ::Number, σₜ::Number)
2626 lb, ub = tight_distance_bounds(x::SVector{3,<:Number}, y::SVector{3,<:Number}, R::RotationVec, T<:SVector{3}, σᵣ::Number, σₜ::Number)
2727
28- Within an uncertainty region, find the bounds on distance between two points x and y.
28+ Within an uncertainty region, find the bounds on distance between two points x and y.
2929
3030See [Campbell & Peterson, 2016](https://arxiv.org/abs/1603.00150)
3131"""
32- function tight_distance_bounds (x:: SVector{3,<:Number} , y:: SVector{3,<:Number} , σᵣ:: Number , σₜ:: Number )
32+ function tight_distance_bounds (x:: SVector{3,<:Number} , y:: SVector{3,<:Number} , σᵣ:: Number , σₜ:: Number , maximize :: Bool = false )
3333 # prepare positions and angles
3434 xnorm, ynorm = norm (x), norm (y)
3535 if xnorm* ynorm == 0
@@ -42,13 +42,23 @@ function tight_distance_bounds(x::SVector{3,<:Number}, y::SVector{3,<:Number},
4242 # upper bound distance at hypercube center
4343 ubdist = norm (x - y)
4444
45- # lower bound distance from the nearest point on the "spherical cap"
46- if cosα >= cosβ
47- lbdist = max (abs (xnorm- ynorm) - sqrt3* σₜ, 0 )
45+ if maximize
46+ # this case is intended for situations where the objective function scales negatively with distance\
47+ # lbdist, which will be the further point on the spherical cap, will be larger than ubdist
48+ if cosα + cosβ >= π
49+ lbdist = xnorm + ynorm + sqrt3* σₜ
50+ else
51+ lbdist = √ (xnorm^ 2 + ynorm^ 2 - 2 * xnorm* ynorm* (cosα* cosβ-√ ((1 - cosα^ 2 )* (1 - cosβ^ 2 )))) + sqrt3* σₜ
52+ end
4853 else
49- lbdist = try max (√ (xnorm^ 2 + ynorm^ 2 - 2 * xnorm* ynorm* (cosα* cosβ+√ ((1 - cosα^ 2 )* (1 - cosβ^ 2 )))) - sqrt3* σₜ, 0 ) # law of cosines
50- catch e # when the argument for the square root is negative (within machine precision of 0, usually)
51- 0
54+ # lower bound distance from the nearest point on the "spherical cap"
55+ if cosα >= cosβ
56+ lbdist = max (abs (xnorm- ynorm) - sqrt3* σₜ, 0 )
57+ else
58+ lbdist = try max (√ (xnorm^ 2 + ynorm^ 2 - 2 * xnorm* ynorm* (cosα* cosβ+√ ((1 - cosα^ 2 )* (1 - cosβ^ 2 )))) - sqrt3* σₜ, 0 ) # law of cosines
59+ catch e # when the argument for the square root is negative (within machine precision of 0, usually)
60+ 0
61+ end
5262 end
5363 end
5464
@@ -57,7 +67,7 @@ function tight_distance_bounds(x::SVector{3,<:Number}, y::SVector{3,<:Number},
5767 return (numtype (lbdist), numtype (ubdist))
5868end
5969
60- tight_distance_bounds (x:: SVector{3,<:Number} , y:: SVector{3,<:Number} , R:: RotationVec , T:: SVector{3} , σᵣ:: Number , σₜ:: Number
61- ) = (R. sx^ 2 + R. sy^ 2 + R. sz^ 2 ) > pisq ? infbounds (x,y) : tight_distance_bounds (R* x, y- T, σᵣ, σₜ) # tight_distance_bounds(R*x, y-T, σᵣ, σₜ)
62- tight_distance_bounds (x:: SVector{3} , y:: SVector{3} , block:: UncertaintyRegion ) = tight_distance_bounds (x, y, block. R, block. T, block. σᵣ, block. σₜ)
63- tight_distance_bounds (x:: SVector{3} , y:: SVector{3} , block:: Union{RotationRegion, TranslationRegion} ) = tight_distance_bounds (x, y, UncertaintyRegion (block))
70+ tight_distance_bounds (x:: SVector{3,<:Number} , y:: SVector{3,<:Number} , R:: RotationVec , T:: SVector{3} , σᵣ:: Number , σₜ:: Number , maximize :: Bool = false ,
71+ ) = (R. sx^ 2 + R. sy^ 2 + R. sz^ 2 ) > pisq ? infbounds (x,y) : tight_distance_bounds (R* x, y- T, σᵣ, σₜ, maximize ) # tight_distance_bounds(R*x, y-T, σᵣ, σₜ)
72+ tight_distance_bounds (x:: SVector{3} , y:: SVector{3} , block:: UncertaintyRegion , maximize :: Bool = false ) = tight_distance_bounds (x, y, block. R, block. T, block. σᵣ, block. σₜ, maximize )
73+ tight_distance_bounds (x:: SVector{3} , y:: SVector{3} , block:: Union{RotationRegion, TranslationRegion} , maximize :: Bool = false ) = tight_distance_bounds (x, y, UncertaintyRegion (block), maximize )
0 commit comments