[英]Minimum distance between coordinate cluster and a point along unit vector i
I have a set of 3D coordinates Q clustered into a crude sphere about an origin O, a unit vector i, and length d. 我有一组3D坐标Q,这些坐标Q围绕原点O,单位矢量i和长度d聚集到一个粗球形中。 Let p = c * i where c is a positive real number.
令p = c * i,其中c是一个正实数。 Let M denote the set of distances between p and every q in Q. I need a robust way to compute the minimum value of c subject to the constraint that the minimum valve of M be bigger than d.
令M表示p与Q中每个q之间的距离的集合。在M的最小阀大于d的约束下,我需要一种可靠的方法来计算c的最小值。 Is there an elegant way to do this in python with scipy/numpy?
有没有一种优雅的方法可以在python中使用scipy / numpy做到这一点? I suspect that scipy.spatial.KDTree will be useful but it is unclear how I would efficiently find my constrained minimum.
我怀疑scipy.spatial.KDTree会很有用,但目前尚不清楚如何有效地找到我的约束最小值。
You can solve the problem like this: 您可以解决以下问题:
For a point q in Q, define: 对于Q中的一个点q,定义:
C(q) = set of values of c >= 0 s.t. |q - c*i| >= d
and then define 然后定义
C = intersection { q in Q } C(q)
and then the desired value c is: 然后期望值c为:
c = inf C = minimum element of C
The sets C(q) are just the solution to a quadratic inequality and so will have one of the forms: 集C(q)只是二次不等式的解决方案,因此将具有以下形式之一:
1) C(q) = [0, +infinity)
2) C(q) = [0, b] union [ e, +infinity ) (for some e > b)
3) C(q) = [e, +infinity )
You can safely discard sets of the first form. 您可以安全地丢弃第一种形式的集合。
If all of the remaining C(q) sets have form #2, then c = 0. 如果所有其余的C(q)集都具有形式#2,则c = 0。
If instead they all have form #3, c is: 相反,如果它们都具有#3形式,则c为:
c = maximum { q in Q } e(q)
Otherwise things get more complicated. 否则情况会变得更加复杂。
For a given q, to compute C(q) note that: 对于给定的q,要计算C(q),请注意:
|q - c*i| >= d
<=> (q - c*i)^2 >= d*d
<=> (q - c*i).(q - c*i) >= d*d
<=> q.q + c*c - 2*c*(q.i) >= d*d
<=> c*c - c*2*(q.i) + q.q - d*d >= 0
If the discriminant of this quadratic equation is < 0, then C(q) = [0, +infinity). 如果此二次方程的判别式<0,则C(q)= [0,+无限大]。
Otherwise let b and e be the roots, b <= e, and check these cases: 否则,让b和e为根,b <= e,并检查以下情况:
e < 0 --> C(q) = [0, +infinity)
b < 0 --> C(q) = [e, +infinity)
b >= 0 --> C(q) = [0, b] union [e, +infinity)
An example in 2-d which demonstrates the more complicated case: 2-d中的示例演示了更复杂的情况:
Q = { q1, q2, q3, q4 }
= { (1,0), (0,1), (4,4), (0,10) }
i = (1/sqrt 5, 2/sqrt 5)
d = 2
C(q1) = [ 2.236, +infinity )
C(q2) = [ 2.843, +infinity )
C(q3) = [ 0, 4.472 ] union [ 6.261, +infinity )
C(q4) = [ 0, +infinity )
The smallest element of the intersection of C(q1), C(q2) and C(q3) is 2.843. C(q1),C(q2)和C(q3)的交点的最小元素为2.843。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.