I'm trying to find the local minimum of a plane. This is being done algebraically because I'm doing it in a computer program for a game I'm making. Sadly, I suck at math and am only in algebra II so I probably screwed a lot up with my minimal knowledge of calculus. When testing, it got a completely random spot and here is the math I used to get there :
$(x,y,z)$=point finding
$(q,r,s)$=player position
$(a,b,c,d)$=plane stuff
$ax+by+cz=d \Longrightarrow z=dx+\frac{-b}{c}y-\frac{a}{c}$
$dist = \sqrt{(x-q)^2+(y-r)^2+(z-s)^2}$
$dist^2 = f(x,y) = (x-q)^2+(y-r)^2+\Bigl((dx+\frac{-b}{c}y+(\frac{a}{c}-s)\Bigr)^2$
$x = 2(x-q)+r^2(dx+\frac{-b}{c}y+(\frac{a}{c}-s))=2x-2q+r^2dx+r^2\frac{-b}{c}y+r^2(\frac{a}{c}-s)$
$x = (2x+r^2dx+r^2\frac{-b}{c}y) + 2q+r^2(\frac{a}{c}-s)$
$x = (2+r^2d)x+(r^2\frac{-b}{c})y + 2q+r^2(\frac{a}{c}-s)$
$x = \frac{r^2\frac{-b}{c}}{-((2+r^2d)-1)}y+2q+r^2\frac{\frac{a}{c}-s}{-((2+r^2d)-1)}$
$y = (x-q)^2+(y-r)^2+(dx+\frac{-b}{c}y+(\frac{a}{c}-s))^2$
$y = 2(y-r)+q^2(dx+\frac{-b}{c}y+(\frac{a}{c}-s))$
$y = 2y-2r+q^2dx+\frac{-b}{c}q^2y+(\frac{a}{2}-s)q^2$
$y = (2y+q^2dx+\frac{-b}{c}q^2y) + 2r+(\frac{a}{2}-s)q^2$
$y = (2+\frac{-b}{c}q^2)y + q^2dx + 2r+(\frac{a}{2}-s)q^2$
$y = \frac{q^2d}{1+\frac{-b}{c}q^2}x + \frac{2r+(\frac{a}{2}-s)q^2}{1+\frac{-b}{c}q^2}$
--new variables for simplification
$m=2q+r^2\frac{\frac{a}{c}-s}{-((2+r^2d)-1)}$
$g=\frac{r^2\frac{-b}{c}}{-((2+r^2d)-1)}$
$n=\frac{2r+(\frac{a}{2}-s)q^2}{1+\frac{-b}{c}q^2}$
$h=\frac{q^2d}{1+\frac{-b}{c}q^2}$
--substitute
$y = h(gy+m)+n$
$y = hgy+hm+n$
$y = \frac{hm+n}{-(hg-1)}$
$x = gy+m$
Again, sorry for my bad math. And please, help?