: : : Hi everyone,
: : :
: : : Sorry i was out for a couple of days.
: : : You guys really lost me here. I'm not very good with maths and geometry so i need to read all this carefully. To answer Richard's question it's only part of a circle so the center will not be in the middle of the two points.
: : : Thanks a lot for the inputs.
: : :
: : : Regards
: : : JohnBug
: : :
: : :
: : Yeah really sorry to complicate matters like this, but it's just not an easy question ;)
: : I'm affraid you're stuck with my original post.
: : Basically, what you need to do is this:
: : You'll get the start and end points along with the radius from the user.
: : The coordinates will look like this:
: : Begin point B(a, b)
: : End point E(f, g)
: : Radius r
: : (When programming the code, it's advisable to give them names like startX, startY, endX, endY and Radius, but for now, let's use these simple letters.)
: : Then calculate the following values using the given formula's:
: : A = 1 + (a-f)/(g-b)
: : B = 0.5(a-f) - 0.5(a+f)(a-f)/(g-b)
: : C = 0.25 - radius + a + b + 0.25(b+g) + 0.25(a+f)(a-f)/(g-b) - 0.5b(b+g)
: : (Here also, I advise you to use names like formuA, formuB and formuC for the capital A, B and C. I'd make the variables Doubles.)
: : For example, in code A would look like this (using the suggested variable names):
: : formuA = 1 + ((beginX - endX) / (endY - beginY))^2
: : Continue with calculating D:
: : D = B - 4AC
: : formuD = formuB^2 - 4*formuA*formuC
: : 'You should check here if D yields a usable value
: : If (formuD < 0) Then
: : MsgBox "The inputted values are not part of a circle with " & _
: : "the specified radius"
: : 'Stop the process here, for instance by exiting the function
: : Exit Sub
: : End If
: : Now you can calculate the x and y values of the circle's center:
: : x1 = (-B + Sqr(D)) / 2A
: : y1 = (a-f)/(g-b) * x1 + (b+g)/2 - (a-f)(a+f)/2(g-b)
: : x2 = (-B - Sqr(D)) / 2A
: : y2 = (a-f)/(g-b) * x2 + (b+g)/2 - (a-f)(a+f)/2(g-b)
: : A part of it in code (too lazy to translate it all ;) )
: : circle1_x = (Sqr(formuD) - formuB)) / (2*formuA)
: : circle1_y = ((beginX - endX) / (endY - beginY)) * circle1_x + ...
: : And so on for the rest of the formula.
: : Now you have an x and y value of the circle's center to use with the other formula's.
: : You can use either of the circle centers' x and y. I suggest that in code you only calculate x1 and y1 and use those.
: : Best Regards,
: : Richard
: Looks clearer now.
: I'm gonna try this and let you know.
: Once it's finish i'll post the app in case others need it.
: Thanks again
Yes it's me again
I tried your formulas and I must be doing something wrong because it doesn't yield the right results.
I tried with the following values:
This should put the center at approx. x=56 and y=243 (measured on a paper). The results I get are x=100 and y=1500050.
Here's my code. Do you see anything wrong?
FormuA = 1 + (Start_x - End_x) ^ 2 / (End_y - Start_y) ^ 2
FormuB = 0.5 * (Start_x - End_x) - 0.5 * (Start_x + End_x) * (Start_x - End_x) ^ 2 / (End_y - Start_y) ^ 2
FormuC = 0.25 - Radius ^ 2 + Start_x ^ 2 + Start_y ^ 2 + 0.25 * (Start_y + End_y) ^ 2 + 0.25 * (Start_x + End_x) ^ 2 * (Start_x - End_x) ^ 2 / (End_y - Start_y) ^ 2 - 0.5 * Start_y * (Start_y - End_y)
FormuD = FormuB ^ 2 - 4 * FormA * FormuC
Center_x1 = (Sqr(FormuD) - FormuB) / (2 * FormuA)
Center_y1 = ((Start_x - End_x) / (End_y - Start_y)) * Center_x1 + (Start_y + End_y) / 2 - (Start_x - End_x) * (Start_x + End_x) / 2 * (End_y - Start_y)
Thanks for the great help