Draw an arc from two points and radius

Hi Everyone,
I need to draw an arc on a form only from the coordinates of the start and end points, the radius and the direction(clockwise or anticlockwise). All functions i find require the coordinates for the center of the circle.
Does anyone know how to do that?

Thanks
JohnBug
«1

• [b][red]This message was edited by BitByBit_Thor at 2006-8-8 15:32:55[/red][/b][hr]
[b][red]This message was edited by BitByBit_Thor at 2006-8-8 15:22:30[/red][/b][hr]
: Hi Everyone,
: I need to draw an arc on a form only from the coordinates of the start and end points, the radius and the direction(clockwise or anticlockwise). All functions i find require the coordinates for the center of the circle.
: Does anyone know how to do that?
:
: Thanks
: JohnBug
:

If you have the begin and endpoints of the arc, you can draw a line between them. Put a point P on the middle of this line and then draw a second line through P, with a 90 degree angle on the first line. Call this new line l.
All the possible points for the center of the circle will be on this line l.
Now you need to draw a circle from either the begin point or end point with the given radius and the intersections between this circle and the new line are the possible circle centers (in most cases there will be 2 points).

Translating this story in the calculations:
Begin point B(a, b)
End point E(f, g)

Middle of the line P( (f+a)/2, (b+g)/2 )
Angle of the line in y/x: r1 = (g-b) / (f-a)

Then the line l (90 degrees on this line) has:
Angle of l in y/x: r2 = -1 / r1 = (a-f) / (g-b)
Given that l goes through P we can find a function y for l:
y = r*x + c --> y = (a-f)/(g-b) * x + c

Inserting P( (f+a)/2, (b+g)/2 ) into the equation makes:
(b+g)/2 = (a-f)/(g-b) * (f+a)/2 + c
c = (b+g)/2 - (a-f)(f+a)/2(g-b)

Making l:
y = (f-a)/(g-b) * x + (b+g)/2 - (a-f)(a+f)/2(g-b)
(stay with me here ... it looks worse than it is)

We are searching a point M(p, q) on l where has a distance radius to B or E (begin or end point).

M(p, q) can be written as:
M(x, (a-f)/(g-b) * x + (b+g)/2 - (a-f)(a+f)/2(g-b))

With B(a, b):

(x - a) + ((a-f)/(g-b) * x + (b+g)/2 - (a-f)(a+f)/2(g-b) - b) = radius

[grey]
Well ... to solve this is going to take a while!
Unfortunately, I don't have enough time to finish the calculation right now (already started working it out on paper). I'll come back later today and edit the result into this post.
[/grey]
Well uhm You don't even wanna see what it's going to become. I gave up working it out fully :P

Anyway, as far as I got (and it's a miracle if I did it without mistakes!) is:

I don't know if you're familair with what we here call the 'abc'-formula? It's the formula to solve the equation: Ax + Bx + C = 0

Basically, I found such an equation with:

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)

So following the 'abc-formula' further yields:
D = B - 4AC
You can do a check here. For any valid solution (eg for any arc that can be drawn) D will have to be equal to or larger than 0. If it's not for any situation, then either there is no possible arc, or I screwed up somewhere :P

De x coordinates of the centers of the circle are as following:
x1 = (-B + Sqr(D)) / 2A
x2 = (-B - Sqr(D)) / 2A

The y coordinates are when you insert these x values into the equation for the line l:

l: y = (a-f)/(g-b) * x + (b+g)/2 - (a-f)(a+f)/2(g-b)

y1 = (a-f)/(g-b) * x1 + (b+g)/2 - (a-f)(a+f)/2(g-b)
y2 = (a-f)/(g-b) * x2 + (b+g)/2 - (a-f)(a+f)/2(g-b)

So M1(x1, y1) and M2(x2, y2)

Since A, B and C are too 'sick', the best thing to do in VB6 is to make double variables and calculate A, B and C. Then with these double values calculate D and then x1 and x2 and after that y1 and y2.

Ok ... it's a tough story I suggest you test it for errors by programming it and seeing if the found circle center coordinates are correct. If not, please contact me If there's anything you don't understand don't hesitate to ask... I did my best at explaining and undoubtedly failed misserable at it

Best Regards,
Richard
• [b][red]This message was edited by DrMarten at 2006-8-9 1:14:16[/red][/b][hr]

Hi,

I was starting to think along the same lines as you.
By the way do you have an A level or degree in maths or something?

I came up with the following.

If point1 coordinates are x1,y1
If point2 coordinates are x2,y2
If circle/arc centre coordinates are cx,cy then>>
[b]
cx=(x1+x2)/2
cy=(y1+y2)/2
[/b]
Now for distances and angles>>

Angle1 is the angle to point1
Angle2 is the angle to point2

Angle1 is given by>>
[b]
Angle1=ArcSin( (y1-cy) / ( x1-cx) ) 'Opposite/ajacent
[/b]
and Angle2 by>>
[b]
Angle2=ArcSin( (y2-cy) / ( x2-cx) ) 'Opposite/ajacent
[/b]

I've been looking up code to do ArcSin ( or Inverse Sine ) function

Anyway once i get the angle values and convert to RADIANS by dividing
the angles by the following number.>>
57.2957795 which is also equal to 360/(2*PI)

and the RADIUS=SQR( ((x1-cx)^2)) + ((y1-cy)^2) )

you can then say>>
[b][red]
SORRY THIS CODE IS FOR VB.NET
( WHICH THIS CODE SHOULD WORK WITHIN ) HERE>>
[/red][blue]
http://msdn.microsoft.com/vstudio/express/vb/
[/blue]
[/b]
[code]
'cx and cy are the centre coordinates of the circle.
Dim cx As Integer
Dim cy As Integer
'x2 and y2 are the plotted positions that are calculated.
Dim x2 As Integer
Dim y2 As Integer
Dim PI As Double
'Just a loop Count variable to go plot each point
'on the arc or circle.
Dim Count As Double
'Set up a white PEN of width=1
Dim aPen As New Pen(Color.White, 1)
Radius = SQR( ((x1-cx)^2)) + ((y1-cy)^2) )
PI = Math.PI

For Count = Angle1 To Angle2 Step 0.05 'Can be any step value.
x2 = Math.Round(Radius * Math.Sin(Count) + cx, 3)
y2 = Math.Round(Radius * Math.Cos(Count) + cy, 3)

pictureBox1.CreateGraphics.DrawLine(aPen, x2, y2, x2 + 1, y2)

Next Count
[/code]

I know this method is not "ideal" for some people as i'm not using
SetPixel, but to do that I believe you need to load a bitmap first.:-(
With the above METHOD you can plot on the FORM itself.
To do this i think the last line needs to be changed within
the FOR NEXT loop to>>
[b]
Me.CreateGraphics.DrawLine(aPen, x2, y2, x2 + 1, y2)
[/b]

To go backwards (anti-clockwise), put a minus sign in either equation in the code above so it reads as>>
[b]
x2 = Math.Round(-Radius * Math.Sin(Count) + cx, 3)
'or but not in both
y2 = Math.Round(-Radius * Math.Cos(Count) + cy, 3)
[/b]
You could multiply the radius by minus 1.

I'm off to give it a try....

Regards,

Dr M.

P.S. Richard, i followed the bit about a right angled line for
all of the points to plot from but the arc from any other point, other than the centre, would be a partial ellipse, sometimes
a diagonal ellipse.

• : Hi,
:
: I was starting to think along the same lines as you.
: By the way do you have an A level or degree in maths or something?
:

Nope ... just secondary school for now Going to college next year! ^^

: I came up with the following.
:
: If point1 coordinates are x1,y1
: If point2 coordinates are x2,y2
: If circle/arc centre coordinates are cx,cy then>>
: [b]
: cx=(x1+x2)/2
: cy=(y1+y2)/2
: [/b]

Yeah I was thinking about this solution too - had the message already posted when I quickly clicked the delete button. Why? If I understand you right then this method works fine for when you are trying to draw half a circle. Perhaps he meant to create half a circle all along (I'm not really sure what the definition of arc is ) and if so my post was WAY too complicated :P Then this will work fine.
However, if you just want, say a quarter of a circle, then you can try but this won't work: draw it out on a piece of paper and see where your center is placed: the center is placed as such that the two points become half a circle, but not a quarter.

: P.S. Richard, i followed the bit about a right angled line for
: all of the points to plot from but the arc from any other point, other than the centre, would be a partial ellipse, sometimes
: a diagonal ellipse.
:

Yeah I know. So that's why I continue the calculation to get the exact point on the line where the arc would be a partial circle. I do it this way, because there is no easy way (as far as I know) to equate two circles:
(x - a) + (y - b) = r
With center M(a, b) and radius r
y = b + Sqr(r - (x-a))
-and
y = b - Sqr(r - (x-a))
(each of these formula's is half a circle)

If you try and equate one of these y's with another circle's y (with the same radius) you'll get:
M1(a, b) and M2(c, d)
y1 = b + Sqr(r1 - (x-a))
y2 = d + Sqr(r2 - (x-c))

y1 = y2 -->

b + Sqr(r1 - (x-a)) = d + Sqr(r2 - (x-c))
I don't know how to solve this equation, even when r1 = r2.

So that's why I took the detour saying that all the centers had to be on that line l. Making the equation (unfortunately not easier) but atleast solvable

Best Regards,
Richard

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

b + Sqr(r1 - (x-a)) = d + Sqr(r2 - (x-c))

If you "square" both sides of the equation you get>>

(b^2) + (r1^2 - (x-a)^2) = (d^2) + (r2^2 - (x-c)^2) >>

becomes>>

(b^2) + (r1^2)- (x^2) -2xa - (a^2) = (d^2) + (r2^2) - (x^2) -2xc - (c^2)

If r1 and r2 are equal then>>

(b^2) - (x^2) -2xa - (a^2) = (d^2) - (x^2) -2xc - (c^2)

the ( x^2 ) also cancel each other giving>>
[b][blue]
(b^2) -2xa - (a^2) = (d^2) -2xc - (c^2)
[/blue]
[/b]

Any help?

I.E. the a, b, c and d. What are they?
How do you get " " on a keyboard too please?
The above one was PASTED.

Regards,

Dr M.

• : [b][red]This message was edited by DrMarten at 2006-8-9 10:29:31[/red][/b][hr]
: Hi,
:
: b + Sqr(r1 - (x-a)) = d + Sqr(r2 - (x-c))
:
: If you "square" both sides of the equation you get>>
:
Yeah I so wish it did:

( b + Sqr(r1 - (x-a)) ) = b + r1 - (x-a) + 2b*Sqr(r1 - (x-a))
And there we have the root, still alive.
(5 + 1) = 6 = 36
This is 5 + 1 + 2*5*1 = 25 + 1 + 10 = 36
NOT 5 + 1 = 26
So you can't square away the root... thus no solution.

:
: Any help?
:
:
: I.E. the a, b, c and d. What are they?
Well the center of circle one is M1(a, b) and of circle two M2(c, d)
r is the radius, and x and y are the normal grid axes.
Thus a, b, c and d are the x and y coordinates of circle one and two respectively.

: How do you get " " on a keyboard too please?
: The above one was PASTED.

^^ Alt+2 =

----------------------------------

So we need input from the person that asked the question:
What is an arc? Is it half a circle or only part of a circle?

If it's half a circle, see Dr Marten's first post.
If it's part of a circle, unfortunately see my first post :P

Best Regards,
Richard

• : : [b][red]This message was edited by DrMarten at 2006-8-9 10:29:31[/red][/b][hr]
: : Hi,
: :
: : b + Sqr(r1 - (x-a)) = d + Sqr(r2 - (x-c))
: :
: : If you "square" both sides of the equation you get>>
: :
: Yeah I so wish it did:
:
: ( b + Sqr(r1 - (x-a)) ) = b + r1 - (x-a) + 2b*Sqr(r1 - (x-a))
: And there we have the root, still alive.
: (5 + 1) = 6 = 36
: This is 5 + 1 + 2*5*1 = 25 + 1 + 10 = 36
: NOT 5 + 1 = 26
: So you can't square away the root... thus no solution.
:
: :
: : Any help?
: :
: : Can you explain each term in your equations please BitByBit_Thor?
: :
: : I.E. the a, b, c and d. What are they?
: Well the center of circle one is M1(a, b) and of circle two M2(c, d)
: r is the radius, and x and y are the normal grid axes.
: Thus a, b, c and d are the x and y coordinates of circle one and two respectively.
:
: : How do you get " " on a keyboard too please?
: : The above one was PASTED.
:
: ^^ Alt+2 =
:
: ----------------------------------
:
: So we need input from the person that asked the question:
: What is an arc? Is it half a circle or only part of a circle?
:
: If it's half a circle, see Dr Marten's first post.
: If it's part of a circle, unfortunately see my first post :P
:
: Best Regards,
: Richard
:
:
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

• Hi,

What i was getting at Richard is creating a formula from another
by trying to eliminate terms such as square roots or indices such as
x^2

If you take as an example>>

2+sqr(9) = 3+sqr(4)

both sides equate to 5.

Now square each of the terms separately above and you get>>

(2^2) + 9 = (3^2) + 4 equating to>>
[b]
4+9 = 9+4
and both sides equal 13[/b]

I'm not sure if this works for ALL equations but if one of the
terms equates or is equal to 1 i know it doesn't as in this
example>>

2+SQR(9)=1+SQR(16)

Both sides equal 5 however

(2^2)+9[b][red]DOES NOT EQUAL[/red][/b] (1^2)+16
I.E.
4+9 [b][red]DOES NOT EQUAL[/red][/b] 1+16
13 [b][red]DOES NOT EQUAL[/red][/b] 17

Regards,

Dr M.

• [b][red]This message was edited by DrMarten at 2006-8-11 1:7:30[/red][/b][hr]

: Hi,
:
: I was starting to think along the same lines as you.
: By the way do you have an A level or degree in maths or something?
:
: I came up with the following.
:
: If point1 coordinates are x1,y1
: If point2 coordinates are x2,y2
: If circle/arc centre coordinates are cx,cy then>>
: [b]
: cx=(x1+x2)/2
: cy=(y1+y2)/2
: [/b]
: Now for distances and angles>>
:
: Angle1 is the angle to point1
: Angle2 is the angle to point2
:
: Angle1 is given by>>
: [b]
: Angle1=Math.Atan( (y1-cy) / ( x1-cx) ) 'Opposite/ajacent
: [/b]
: and Angle2 by>>
: [b]
: Angle2=Math.Atan( (y2-cy) / ( x2-cx) ) 'Opposite/ajacent
: [/b]

: and the RADIUS=SQR( ((x1-cx)^2)) + ((y1-cy)^2) )
:
: you can then say>>
: [b][red]
: SORRY THIS CODE IS FOR VB.NET
: ( WHICH THIS CODE SHOULD WORK WITHIN ) HERE>>
: [/red][blue]
: http://msdn.microsoft.com/vstudio/express/vb/
: [/blue]
: [/b]
: [code]
'Sorry this only works for half a circle.
'cx and cy are the centre coordinates of the circle.
Dim cx As Integer
Dim cy As Integer
'x2 and y2 are the plotted positions that are calculated.
Dim x2 As Integer
Dim y2 As Integer
Dim PI As Double
'Just a loop Count variable to go plot each point
'on the arc or circle.
Dim Count As Double
Dim Angle1 As Double
Dim Angle2 As Double
Angle1=Math.Atan( ((y1-cy) / ( x1-cx)) /(180/Pi) )'Converted to radians
Angle2=Math.Atan( ((y2-cy) / ( x2-cx))/(180/Pi) )'Converted to radians
'Set up a white PEN of width=1
Dim aPen As New Pen(Color.White, 1)
Radius = SQR( ((x1-cx)^2)) + ((y1-cy)^2) )
PI = Math.PI

For Count = Angle1 To Angle2 Step 0.05 'Can be any step value.
x2 = Math.Round(Radius * Math.Sin(Count) + cx, 3)
y2 = Math.Round(Radius * Math.Cos(Count) + cy, 3)

pictureBox1.CreateGraphics.DrawLine(aPen, x2, y2, x2 + 1, y2)

Next Count
[/code]

: I know this method is not "ideal" for some people as i'm not using
: SetPixel, but to do that I believe you need to load a bitmap first.:-(
: With the above METHOD you can plot on the FORM itself.
: To do this i think the last line needs to be changed within
: the FOR NEXT loop to>>
: [b]
: Me.CreateGraphics.DrawLine(aPen, x2, y2, x2 + 1, y2)
: [/b]
:
: To go backwards (anti-clockwise), put a minus sign in either equation in the code above so it reads as>>
: [b]
: x2 = Math.Round(-Radius * Math.Sin(Count) + cx, 3)
: 'or but not in both
: y2 = Math.Round(-Radius * Math.Cos(Count) + cy, 3)
: [/b]
: You could multiply the radius by minus 1.
:
: I'm off to give it a try....
:
:
: Regards,
:
: Dr M.
:
: P.S. Richard, i followed the bit about a right angled line for
: all of the points to plot from but the arc from any other point, other than the centre, would be a partial ellipse, sometimes
: a diagonal ellipse.
______________________________________________________________________

Hi,

My original post above is now amended as Opposite/Adjacent is Tan not
Sine as i originally put. Ooops.... :-(

Regards,

Dr M.

• [b][red]This message was edited by DrMarten at 2006-8-12 0:26:44[/red][/b][hr]

If a circle call it c1 is plotted with

x1=R*sin(a)+x
y1=R*cos(a)+y

where x,y are the centre and r the radius and (a) is the same angle
for any point then if you imagine a 2nd circle with radius r2
at the same centre the formulae become>>

x1=R*sin(a)+x
newR=R*(r2/R)
y1=newR*cos(a)+y

or >>
x1=R*sin(a)+x
y1=R*(r2/R)*cos(a)+y

is the same.
This results in a horizontal ellipse if r2R.

For the same centre a diagonal ellipse if plotted as>>

x1=R*sin(a)+x
y1=R*(r2/R)*cos(a+b)+y

where b is any angle.

______________________________________________________________________

Another thing about an ellipse is it can be plotted from
2 centres or locci, i believe they are called.

Call the loccii centres w,x and y,z

Any point on the ellipse equates to C=a+b where
C is always constant and>>>

a is the distance from w,x ( locci1 )
b is the distance from y,z ( locci2 )

You can do this with a piece of string which is loose between
2 points, C being the length of the string.
Fasten with drawing pins on a suitable surface and if you pull
the string tight away from the 2 points with a pencil and move around
the result of the plot is an ellipse.

See the sketch at>>
http://i13.photobucket.com/albums/a272/u-might-want-this/EllipseSketch.jpg which shows what i'm talking about.
r2 is the distance from the centre to the ellipse cicumference
not the full yellow line length,
R is the distance from the centre to the ellipse cicumference
and not the full white horizontal line length.

I'd love to know how to calculate the w,x and y,z
coordinates of the 2 locci though....

Regards,

Dr M.

• : [b][red]This message was edited by DrMarten at 2006-8-12 0:26:44[/red][/b][hr]
:
: If a circle call it c1 is plotted with
:
: x1=R*sin(a)+x
: y1=R*cos(a)+y
:
: where x,y are the centre and r the radius and (a) is the same angle
: for any point then if you imagine a 2nd circle with radius r2
: at the same centre the formulae become>>
:
: x1=R*sin(a)+x
: newR=R*(r2/R)
: y1=newR*cos(a)+y
:
: or >>
: x1=R*sin(a)+x
: y1=R*(r2/R)*cos(a)+y
:
: is the same.
: This results in a horizontal ellipse if r2R.
:
: For the same centre a diagonal ellipse if plotted as>>
:
: x1=R*sin(a)+x
: y1=R*(r2/R)*cos(a+b)+y
:
: where b is any angle.
:
: ______________________________________________________________________
:
: Another thing about an ellipse is it can be plotted from
: 2 centres or locci, i believe they are called.
:
: Call the loccii centres w,x and y,z
:
: Any point on the ellipse equates to C=a+b where
: C is always constant and>>>
:
: a is the distance from w,x ( locci1 )
: b is the distance from y,z ( locci2 )
:
: You can do this with a piece of string which is loose between
: 2 points, C being the length of the string.
: Fasten with drawing pins on a suitable surface and if you pull
: the string tight away from the 2 points with a pencil and move around
: the result of the plot is an ellipse.
:
: See the sketch at>>
: http://i13.photobucket.com/albums/a272/u-might-want-this/EllipseSketch.jpg which shows what i'm talking about.
: r2 is the distance from the centre to the ellipse cicumference
: not the full yellow line length,
: R is the distance from the centre to the ellipse cicumference
: and not the full white horizontal line length.
:
: I'd love to know how to calculate the w,x and y,z
: coordinates of the 2 locci though....
:
:
: Regards,
:
: Dr M.
:
:

I must be missing something here, but uhmm what's your point?

I once knew the formula for the ellips, but kinda forgot it now (too bad).

Best Regards,
Richard

• : 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)

(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):
[code]
formuA = 1 + ((beginX - endX) / (endY - beginY))^2
[/code]

Continue with calculating
D = B - 4AC

[code]
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 " & _
'Stop the process here, for instance by exiting the function
Exit Sub
End If
[/code]

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 )
[code]
circle1_x = (Sqr(formuD) - formuB)) / (2*formuA)
circle1_y = ((beginX - endX) / (endY - beginY)) * circle1_x + ...
[/code]
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

• : : 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)
:
: (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):
: [code]
: formuA = 1 + ((beginX - endX) / (endY - beginY))^2
: [/code]
:
: Continue with calculating
: D = B - 4AC
:
: [code]
: 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 " & _
: 'Stop the process here, for instance by exiting the function
: Exit Sub
: End If
: [/code]
:
: 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 )
: [code]
: circle1_x = (Sqr(formuD) - formuB)) / (2*formuA)
: circle1_y = ((beginX - endX) / (endY - beginY)) * circle1_x + ...
: [/code]
: 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
:
:
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

• [b][red]This message was edited by DrMarten at 2006-8-14 8:9:9[/red][/b][hr]
: :
: : If a circle call it c1 is plotted with
: :
: : x1=R*sin(a)+x
: : y1=R*cos(a)+y
: :
: : where x,y are the centre and r the radius and (a) is the same angle
: : for any point then if you imagine a 2nd circle with radius r2
: : at the same centre the formulae become>>
: :
: : x1=R*sin(a)+x
: : newR=R*(r2/R)
: : y1=newR*cos(a)+y
: :
: : or >>
: : x1=R*sin(a)+x
: : y1=R*(r2/R)*cos(a)+y
: :
: : is the same.
: : This results in a horizontal ellipse if r2R.
: :
: : For the same centre a diagonal ellipse if plotted as>>
: :
: : x1=R*sin(a)+x
: : y1=R*(r2/R)*cos(a+b)+y
: :
: : where b is any angle.
: :
: : ______________________________________________________________________
: :
: : Another thing about an ellipse is it can be plotted from
: : 2 centres or locci, i believe they are called.
: :
: : Call the loccii centres w,x and y,z
: :
: : Any point on the ellipse equates to C=a+b where
: : C is always constant and>>>
: :
: : a is the distance from w,x ( locci1 )
: : b is the distance from y,z ( locci2 )
: :
: : You can do this with a piece of string which is loose between
: : 2 points, C being the length of the string.
: : Fasten with drawing pins on a suitable surface and if you pull
: : the string tight away from the 2 points with a pencil and move around
: : the result of the plot is an ellipse.
: :
: : See the sketch at>>
: : http://i13.photobucket.com/albums/a272/u-might-want-this/EllipseSketch.jpg which shows what i'm talking about.
: : r2 is the distance from the centre to the ellipse cicumference
: : not the full yellow line length,
: : R is the distance from the centre to the ellipse cicumference
: : and not the full white horizontal line length.
: :
: : I'd love to know how to calculate the w,x and y,z
: : coordinates of the 2 locci though....
: :
: :
: : Regards,
: :
: : Dr M.
: :
: :
:
: I must be missing something here, but uhmm what's your point?
:
: I once knew the formula for the ellips, but kinda forgot it now (too bad).
:
: Best Regards,
: Richard

=====================================================================

Hi Richard,

I was wondering if knowing the methods to plot a circle or an ellipse
that i have posted here can in some way be applied with your posted
formulas to plot an arc from a circle [b]or an ellipse[/b] between
any two points....as per the original question at all please?
Of course this would put the mid line between the two points at any
angle depending on the ratio of the ellipse and whether it is a
horizontal, vertical or a diagonal ellipse.

[b][blue]That may be getting very complicated though. :-(
[/blue][/b]
The post was a hope about trying to make things simpler here too.

Regards,

Dr M.

• : : : 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)
: :
: : (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):
: : [code]
: : formuA = 1 + ((beginX - endX) / (endY - beginY))^2
: : [/code]
: :
: : Continue with calculating
: : D = B - 4AC
: :
: : [code]
: : 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 " & _
: : 'Stop the process here, for instance by exiting the function
: : Exit Sub
: : End If
: : [/code]
: :
: : 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 )
: : [code]
: : circle1_x = (Sqr(formuD) - formuB)) / (2*formuA)
: : circle1_y = ((beginX - endX) / (endY - beginY)) * circle1_x + ...
: : [/code]
: : 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
: :
: :
: 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)

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

• Ahh right

Still wondering why you are talking about an ellips here? Must've missed something I guess, cause I don't see where an ellips comes in when drawing a part of a circle.

Anyway, like I said my first thought was to use the circle function and then continue from there. That, however, was not really successful.

You'll end up with just as difficult calculations as mine - and they're even harder to solve.

The problem is the Sqr that always occurs, or the fact that it is a parabolic equation which means you need to use the abc-formula.

I just don't think that there is an easier way than the one I have already presented.

Best Regards,
Richard