[ 
https://issues.apache.org/jira/browse/LUCENE-6776?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14729991#comment-14729991
 ] 

Karl Wright commented on LUCENE-6776:
-------------------------------------

Ok, here's the math.  This is for the bounds in x.  I had to go with the full 
treatment using lagrange multipliers.  Haven't yet debugged it either, but 
clearly it's doable; you get a quadratic in a parameterization variable, which 
can then be applied to produce a pair of (x,y,z) values:

{code}
Another approach: Lagrange multipliers

For this, we need grad(F(x,y,z)) = (dF/dx, dF/dy, dF/dz).

Minimize and maximize f(x,y,z) = x, with respect to g(x,y,z) = Ax + By + Cz - D 
and h(x,y,z) = x^2/ab^2 + y^2/ab^2 + z^2/c^2 - 1

grad(f(x,y,z)) = (1,0,0)
grad(g(x,y,z)) = (A,B,C)
grad(h(x,y,z)) = (2x/ab^2,2y/ab^2,2z/c^2)

Equations we need to simultaneously solve:

grad(f(x,y,z)) = l * grad(g(x,y,z)) + m * grad(h(x,y,z))
g(x,y,z) = 0
h(x,y,z) = 0

Equations:
1 = l*A + m*2x/ab^2
0 = l*B + m*2y/ab^2
0 = l*C + m*2z/c^2
Ax + By + Cz + D = 0
x^2/ab^2 + y^2/ab^2 + z^2/c^2 - 1 = 0

Solve for x in terms of (l, m):

x = ((1 - l*A) * ab^2 ) / (2 * m)
y = (-l*B * ab^2) / ( 2 * m)
z = (-l*C * c^2)/ (2 * m)

Two equations, two unknowns:

A * (((1 - l*A) * ab^2 ) / (2 * m)) + B * ((-l*B * ab^2) / ( 2 * m)) + C * 
((-l*C * c^2)/ (2 * m)) + D = 0

and

(((1 - l*A) * ab^2 ) / (2 * m))^2/ab^2 + ((-l*B * ab^2) / ( 2 * m))^2/ab^2 + 
((-l*C * c^2)/ (2 * m))^2/c^2 - 1 = 0

Simple: solve for l and m, then find x from it.

(a) Use first equation to find l in terms of m.

A * (((1 - l*A) * ab^2 ) / (2 * m)) + B * ((-l*B * ab^2) / ( 2 * m)) + C * 
((-l*C * c^2)/ (2 * m)) + D = 0
A * ((1 - l*A) * ab^2 ) + B * (-l*B * ab^2) + C * (-l*C * c^2) + D * 2 * m = 0
A * ab^2 - l*A^2* ab^2 - B^2 * l * ab^2 - C^2 * l * c^2 + D * 2 * m = 0
- l *(A^2* ab^2 + B^2 * ab^2 + C^2 * c^2) + (A * ab^2 + D * 2 * m) = 0
l = (A * ab^2 + D * 2 * m) / (A^2* ab^2 + B^2 * ab^2 + C^2 * c^2)
l = m * 2 * (A * ab^2 + D) / (A^2* ab^2 + B^2 * ab^2 + C^2 * c^2)

For convenience:

k = (A^2* ab^2 + B^2 * ab^2 + C^2 * c^2) / (2 * (A * ab^2 + D))

Then:

m = l * k


(b) Simplify the second equation before substitution

(((1 - l*A) * ab^2 ) / (2 * m))^2/ab^2 + ((-l*B * ab^2) / ( 2 * m))^2/ab^2 + 
((-l*C * c^2)/ (2 * m))^2/c^2 - 1 = 0
((1 - l*A) * ab^2 )^2/ab^2 + (-l*B * ab^2)^2/ab^2 + (-l*C * c^2)^2/c^2 = 4 * m^2
(1 - l*A)^2 * ab^2 + (-l*B)^2 * ab^2 + (-l*C)^2 * c^2 = 4 * m^2
(1 - 2*l*A + l^2*A^2) * ab^2 + l^2*B^2 * ab^2 + l^2*C^2 * c^2 = 4 * m^2
ab^2 - 2*l*A*ab^2 + l^2*A^2*ab^2 + l^2*B^2*ab^2 + l^2*C^2*c^2 = 4 * l^2 * k^2

l^2 * (A^2*ab^2 + B^2*ab^2 + C^2*c^2 - 4 * k^2) - l * (2*A*ab^2) + ab^2 = 0

{code}

There will be similar code for the y min and max.

Stay tuned for debugging and eventually a patch.


> Randomized planet model shows up additional XYZBounds errors
> ------------------------------------------------------------
>
>                 Key: LUCENE-6776
>                 URL: https://issues.apache.org/jira/browse/LUCENE-6776
>             Project: Lucene - Core
>          Issue Type: Bug
>          Components: modules/spatial
>            Reporter: Karl Wright
>         Attachments: LUCENE-6776.patch
>
>
> Adding randomized PlanetModel construction causes points to be generated 
> inside a shape that are outside XYZBounds.  [~mikemccand] please take note.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to