# Draw an arc from two points and radius

2»

• : : Hi,
: :
: : 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
: : Jean
: :
: :
: :
: Hi,
: 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:
: start_x=100
: start_y=100
: end_x=200
: end_y=200
:
: 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)
:

Well one thing I saw is that the last part of the FormuC is Start_y + End_y, instead of minus. No idea if this is the only thing The equation if fuzzy enough to make a lot of mistakes.

: 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
: JohnBug
:
:

Hmm let me work it out on paper again and see if I made any mistakes...

*here we go* ... *starts to sing*

*half an hour later*

I noticed that they don't look entirely the same as last time, but that could welly be due to choices I made when simplifying.

[code]
A = 1 + (x2 - x1) / (y1 - y2)[green]
// Ok so A atleast is the same (they look a bit different, but they aren't)[/green]

B = 0.5*(x2 - x1)(y1 + x1 - y2 - x2) / (y1 - y2) +
(x1 - x2)y1 / (y1 - y2) - 2x1[green]
// Ok so this one does really look different :-S I have no idea if they
// are the same...[/green]

C = x1 + y1 + 0.25(y1 + x1 - y2 - x2) / (y1 - y2) -
0.5y1(y1 + x1 - y2 - x2) / (y1 - y2)[green]
// Well ... B and C have become different looking, but it's really hard
// to tell if they are actually different or not. Probably, which
// means I did something wrong the last time or now (or both...)[/green]
[/code]

Well I'd say give them a go Be careful to mind all the 's in there.

Best Regards,
Richard

• [b][red]This message was edited by DrMarten at 2006-8-15 8:31:27[/red][/b][hr]
Hi,

I have working code :-) that proves Richards formulas.

See these screenshots>>
http://i13.photobucket.com/albums/a272/u-might-want-this/Proof1a.jpg

http://i13.photobucket.com/albums/a272/u-might-want-this/Proof2a.jpg

My first point was at 100,100
my second point at 200,200

while the maths and the loop that proved it worked in RADIANS
and not degrees, i could soon change my program to work in degrees.

The code is for VB.Net too but i could change it for standard VB
too if you wish?

of VISUAL BASIC EXPRESS EDITION available from>>
http://msdn.microsoft.com/vstudio/express/vb/

[b]
Remember to put this line at the top of your code window
and add one textbox and one button.>>
[code]
Imports Microsoft.VisualBasic.ControlChars
[/code]
John, i have sent you a message which is the entire code.
PASTE it into a completely EMPTY code window
for a fully working program. :-)

[/b]
[b][blue]
Installing the EXPRESS EDITION will not spoil your current
VB setup as it installs to a different folder.
[/blue]
[/b]

[code]
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a, b, f, g, r As Double
Dim formulaA, formulaB As Double
a = 100 : b = 100 '1st points coordinates.
f = 200 : g = 200 '2nd points coordinates.
r = 75 'is the radius value.

Dim circle1_x, circle1_y As Integer

formulaA = 1 + (((a - f) ^ 2) / ((g - b) ^ 2))
'This line uses the line continuation technique type a space and an underscore>> " _"
formulaB = 0.5 * (a - f) - _
((0.5 * (a + f) * ((a - f) ^ 2)) / ((g - b) ^ 2))
'This line uses the line continuation technique type a space and an underscore>> " _"
formulaC = 0.25 - _
(r ^ 2) + _
(a ^ 2) + _
(b ^ 2) + _
(0.25 * ((b + g) ^ 2)) + ( _
(0.25 * ((a + f) ^ 2) * ((a - f) ^ 2)) / _
(((g - b) ^ 2) - (0.5 * b * (b + g))))

formulaD = (formulaB ^ 2) - (4 * formulaA * formulaC)

circle1_x = CInt(((Math.Sqrt(formulaD)) - formulaB) / (2 * formulaA))
'This line uses the line continuation technique type a space and an underscore>> " _"
circle1_y = CInt((((a - f) / (g - b)) * circle1_x) + _
((b + g) / 2) - _
(((a - f) * (a + f)) / (2 * (g - b))))

'Loop to prove result.>>

Dim index As Double 'is the loop variable.

Dim x1, y1 As Double 'are valid plot points that are calculated.

For index = 0 To (2 * Math.PI) Step 0.01
x1 = r * Math.Sin(index) + circle1_x 'Uses the calculated cantre X coordinate.
y1 = r * Math.Cos(index) + circle1_y 'Uses the calculated cantre Y coordinate.
x1 = CInt(x1) 'Converted to INTEGER.
y1 = CInt(y1) 'Converted to INTEGER.

'This line uses the line continuation technique type a space and an underscore>> " _"
TextBox1.AppendText("x1= " & CStr(x1) & " when y1= " & CStr(y1) & NewLine & _
"angle= " & CStr(index * (180 / Math.PI)) & " degrees." & NewLine & NewLine)
Next
End Sub
[/code]

Regards,

Dr M.

• [code]
Dim a, b, f, g, r As Double
Dim formulaA, formulaB As Double
a = 100 : b = 100 '1st points coordinates.
f = 200 : g = 200 '2nd points coordinates.
r = 75 'is the radius value.

Dim circle1_x, circle1_y As Integer

formulaA = 1 + (((a - f) ^ 2) / ((g - b) ^ 2))

formulaB = 0.5 * (a - f) - ((0.5 * (a + f) * ((a - f) ^ 2)) / ((g - b) ^ 2))

formulaC = 0.25 - (r ^ 2) + (a ^ 2) + (b ^ 2) + (0.25 * ((b + g) ^ 2)) + ((0.25 * ((a + f) ^ 2) * ((a - f) ^ 2)) / (((g - b) ^ 2) - (0.5 * b * (b + g))))

formulaD = (formulaB ^ 2) - (4 * formulaA * formulaC)

circle1_x = CInt(((Math.Sqrt(formulaD)) - formulaB) / (2 * formulaA))

circle1_y = CInt((((a - f) / (g - b)) * circle1_x) + ((b + g) / 2) - (((a - f) * (a + f)) / (2 * (g - b))))

[/code]

• Just out of curiousity, did you use my first formula's, or the ones I wrote down after working it out on paper again? :P

Best Regards,
Richard

• Hi Richard,

Richard i used the ones in this thread>>

Regards,

Dr M.

• Hi all,

This version finds the exact angle for 100,100 and
200,200 being 204 ang 66 degrees respectively.
It is just a coincidence, the program [b]does not by brute
force calculation try to find the angles.[/b]

[b][red]
Anyone know why the ouput only reaches 176.75 degrees in the
FOR NEXT loop when step value is changed to 0.25 please?
[/red][/b]

[code]
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim a, b, f, g, r As Double
Dim formulaA, formulaB As Double
a = 100 : b = 100 '1st points coordinates.
f = 200 : g = 200 '2nd points coordinates.
r = 75 'is the radius value.

Dim circle1_x, circle1_y As Integer

formulaA = 1 + (((a - f) ^ 2) / ((g - b) ^ 2))
'This line uses the line continuation technique type a space and an underscore>> " _"
formulaB = 0.5 * (a - f) - _
((0.5 * (a + f) * ((a - f) ^ 2)) / ((g - b) ^ 2))
'This line uses the line continuation technique type a space and an underscore>> " _"
formulaC = 0.25 - _
(r ^ 2) + _
(a ^ 2) + _
(b ^ 2) + _
(0.25 * ((b + g) ^ 2)) + ( _
(0.25 * ((a + f) ^ 2) * ((a - f) ^ 2)) / _
(((g - b) ^ 2) - (0.5 * b * (b + g))))

formulaD = (formulaB ^ 2) - (4 * formulaA * formulaC)

circle1_x = CInt(((Math.Sqrt(formulaD)) - formulaB) / (2 * formulaA))
'This line uses the line continuation technique type a space and an underscore>> " _"
circle1_y = CInt((((a - f) / (g - b)) * circle1_x) + _
((b + g) / 2) - _
(((a - f) * (a + f)) / (2 * (g - b))))

'Loop to prove result.>>

Dim index As Double 'is the loop variable.

Dim x1, y1 As Double 'are valid plot points that are calculated.

For index = 0 To 360 Step 0.5
x1 = r * Math.Sin(index / (180 / Math.PI)) + circle1_x 'Uses the calculated cantre X coordinate.
y1 = r * Math.Cos(index / (180 / Math.PI)) + circle1_y 'Uses the calculated cantre Y coordinate.
x1 = CInt(x1) 'Converted to INTEGER.
y1 = CInt(y1) 'Converted to INTEGER.

'This line uses the line continuation technique type a space and an underscore>> " _"
TextBox1.AppendText("x1= " & CStr(x1) & " when y1= " & CStr(y1) & NewLine & _
"angle= " & CStr(index) & " degrees." & NewLine & NewLine)
Next
End Sub
[/code]

Regards,

Dr M.

• Hi Guys

I'm trying to get this working in C# but not getting correct results.. Does anybody have a working code for C#?

Jan
• Could you post your code (in [leftbr]code[rightbr] tags!)?

Best Regards,
Richard

The way I see it... Well, it's all pretty blurry
• This post has been deleted.
• This post has been deleted.