Take the 2-minute tour ×

I am trying to calculate point on a line. I got the points of the edges and one distance between one edge to the point I want to find (which is B).


The distance between A to B is 5.

How can I calculate Bx and By? using the following equations:

d = Math.Sqr((Bx-Ax)^2 + (By-Ay)^2)
d = Math.Sqr((Cx-Bx)^2 + (Cy-By)^2)

and than compare the equations above.

Here is the equations with the points placed:

5 = Math.Sqr((Bx-2)^2 + (By-4)^2)
23.0713366 = Math.Sqr((4-Bx)^2 + (32-By)^2)


Math.Sqr((Bx-2)^2 + (By-4)^2) - 5 = Math.Sqr((4-Bx)^2 + (32-By)^2) - 23.0713377

How can I solve this using VBA?

Thank you!

share|improve this question
Your math and your text don't match up, please clarify. If you are looking for the point on A->B that is 5 distance from A, your equations have nothing to do with the problem. –  themel Sep 28 '11 at 14:32
How would you solve these equations using pen and paper? There's your answer. –  Jean-François Corbett Sep 28 '11 at 18:21
@Jean-FrançoisCorbett, I tried to solve it using pen and paper right after I posted it here, and to be honest I couldnt. But there's another reason I couldnt solve it > I didnt use math for long time and I kinda forgot even the basic > Example: I calculated (x-2)^ as x^2+4 which should be x^2+4x+4... –  Ron Sep 28 '11 at 19:38
I see... Do you know this site? math.stackexchange.com/ That's where math questions should be posted. –  Jean-François Corbett Sep 29 '11 at 6:52

2 Answers 2

up vote 2 down vote accepted

I won't solve your equations above because they are an unnecessarily complex way to state the problem (and the existence of a solution is questionable in the presence of rounding), but all the points on the line A=(Ax,Ay) to C=(Cx,Cy) can be described as B=(Ax,Ay) + t*(Cx-Ax,Cy-Ay) with t between 0 and 1.

The distance between B and A is then given by d=t*Sqrt((Cx-Ax)^2+(Cy-Ay)^2), which you can invert to get the proper t for a given d - t=d/Sqrt((Cx-Ax)^2+(Cy-Ay)^2)

In your case, B(t) = (2,4) + t*(2,28), t=5/Sqrt(2^2+28^2) ~ 0.178 -> B ~ (2,4) + 0.178 * (2,28) ~ (2.356, 8.987).

share|improve this answer
+1 for not bothering with spoon-feeding a VBA solution! –  Jean-François Corbett Sep 28 '11 at 18:23

VBA has no Symbolic Language capability. To solve this problem, there are different approach :

  1. Transform the equations to isolate one of the unknowns, most likely to use substitution, and compute it (I recommend this for your problem.)
  2. Transform your functions and derive them to use Newton's methods (don't do this, it's overkill.)
  3. Use a "brute force" convergence methods : Fix a min/max for each variable and use bisection methods to find what you want (I don't recommend this because you'll most likely "fall" into a local minimum/maximum in your case.)

So basically, I'd say you go with the first way. It requires 15mins of tinkering with mathematical equations, then you're set to go.

share|improve this answer

Your Answer


