Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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






$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?

share|cite|improve this question
Your first equation, $ax + by + cz = d$, is not equivalent to $z=dx + (-b/c)y - (a/c)$. I'm assuming => was meant to be an implication arrow... – Arturo Magidin Nov 13 '11 at 8:50
@Arturo Magidin Yeah sorry, I was trying to go off of an example I had seen. – SDuke Nov 13 '11 at 16:05
up vote 1 down vote accepted

I'll assume that Joriki's interpretation is right and you want to find the point on the plane $ax+by+cz=d$ that is closed to $(q,r,s)$. You can do that by minimizing the (squared) distance using calculus, but it is much easier to apply a little geometry.

The line between your target point and $(q,r,s)$ must be perpendicular to the plane; otherwise you could move the target point closer. Therefore what you want to do is draw the line through $(q,r,s)$ that is normal to the plane, and find its intersection with the plane. The equation for the plane directly gives us the direction of the normal, namely $(a,b,c)$. So we can write a parametric equation of the line: $$t\mapsto (q,r,s)+t(a,b,c) = (q+ta, r+tb, s+tc)$$ Finding the intersection is then just a matter of inserting into the plane's equation: $$(q+ta)a + (r+tb)b + (s+tc)c = d$$ and solve for $t$, which easily gives $t=\frac{d-qa-rb-sc}{a^2+b^2+c^2}$. Plug that into your parametric equation, and you have your target point.

share|cite|improve this answer
thanks for that, it makes since up until the plugging into the parametric. Once again, algebra II sorry. I understand what a parametric equation is, but that looks like I would only get one number out of it? – SDuke Nov 13 '11 at 16:38
No, you get $(q+ta, r+tb, s+tc)$, which is a point. (There's nothing left to do except arithmetic because you now know the value of $t$). – Henning Makholm Nov 13 '11 at 16:42
Ok thank you, I thought that could be it but I wasn't entirely certain. – SDuke Nov 13 '11 at 16:45

You're not attempting to find the local minimum of a plane; there's no such thing. It seems that you're trying to find the point on a plane at least distance from the player position. You made an error at the very beginning in solving the plane equation for $z$; the result is $z=(d-ax-by)/c$. I suggest you try again using that, and if you don't succeed, present your work in a more systematic form, not just writing lots of equations but explaining what you did, and using $\TeX$ to make the equations more readable (by enclosing them in dollar signs).

share|cite|improve this answer
+1 on "not just writing lots of equations but explaining what you did". The TeXing can reasonably be left to editors if the question is otherwise clear; I'd rather see ASCII equations than TeXed math that use $*$ as a multiplication sign. – Henning Makholm Nov 13 '11 at 15:13
@joriki Thank you, I'm sorry I couldn't get it to look that way, I was trying to but couldn't figure it out. I changed it for you. Also I was going off of some example I had seen, they did it with all numbers and that's what it appeared to be, so that's what I went with. Thank you for the correction. – SDuke Nov 13 '11 at 16:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.