Skip to content

Instantly share code, notes, and snippets.

@rygorous
Created March 18, 2014 16:01
Embed
What would you like to do?
Quadrics / distance from planes
Okay, to make this simpler I'll write:
p = (x, y, z)^T
q_i = (x_i, y_i, z_i)^T
g_i = (grad f)(q_i)
And I'll also assume that f(x,y,z) = c not w (since I'll be using w for homogeneous coords!)
then
T_i(p)
= dot(g_i, p - q_i)
and
(c - T_i(p))^2
= (c - dot(g_i, p - q_i))^2
Okay. We can go on in that form, but it's nicer if we go to homogeneous first:
p' = (x, y, z, 1)^T
q_i' = (x_i, y_i, z_i, 0)^T
g_i' = [-g_i] (stack the "c" below "-g_i").
[ c ]
Then
(c - T_i(p))^2
= (c - dot(g_i, p - q_i))^2
= (dot(g_i', p' - q_i'))^2
= (dot(p' - q_i', g_i'))^2
= (dot(p', g_i') - dot(q_i', g_i'))^2
and that later term is just a constant offset we can bake into the constant offset term we already have in g_i', yielding:
g_i'' = [ -g_i ]
[ c - dot(q_i', g_i') ]
which means
(c - T_i(p))^2
= (dot(p', g_i''))^2
= (dot(p', g_i'')) * (dot(g_i'', p'))
= (p'^T * g_i'') * (g_i''^T * p')
= p'^T * (g_i'' * g_i''^T) * p'
which is a quadratic form in standard form (the factor in parentheses is A). Summing over several of these just sums their entries for A.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment